David Harkness
  • Member for 10 years, 10 months
  • Last seen more than a month ago
2 answers
votes
10k views
Spliterator implementation
2 votes

From my reading of the Spliterator documentation, your code looks like it should handle parallel usage. Each list of URLs is owned by exactly one spliterator while they all share the thread-safe set ...

View answer
3 answers
votes
239 views
Geographic search
6 votes

If after adding the index on latitude and longitude you still see poor performance, trim the query down to the bare minimum to isolate the source. Remove all of the joins and the where clause ...

View answer
4 answers
votes
976 views
FileWriter supporting writing to multiple files
5 votes

Given that FileWriter works solely with files, you can drop File from the public method names leaving Open and Close, assuming these aren't reserved in vba. It looks like the built-in Print ...

View answer
2 answers
vote
178 views
Series of repetitive content-loading functions
2 votes

Joseph cleaned up the code a lot so let me point out a few things that you'll be able to use in your future code. Consistent formatting greatly improves code readability and maintenance. There are ...

View answer
1 answers
votes
136 views
Stripping out all /* */ comments from a paragraph
1 votes

You didn't specify whether or not nested comments are allowed, but your code trims only the shorter comment. For example, case 4 would yield Text Text with nesting but Text */ Text without. It would ...

View answer
5 answers
votes
21k views
Circular queue implementation
Accepted answer
5 votes

As pointed out by others, you have some bugs. add increments rear twice. poll should wrap front. poll and peek use different emptiness tests. Here's where isEmpty and isFull would come in handy. ...

View answer
2 answers
votes
4k views
Chain of responsibility pattern
4 votes

I would not use Chain of Responsibility to solve this problem. For every request, a single handler is chosen based on the same property: it's output format. For that you can use a simple dispatch ...

View answer
3 answers
votes
5k views
Executing a URL using RestTemplate
Accepted answer
4 votes

As I've stated in my previous answer, the first thing you must decide is "What level of atomicity does this application require?" I don't mean simple thread-safety, which the above code provides by ...

View answer
3 answers
votes
477 views
Scrubbing user input
Accepted answer
10 votes

I only have a few minor suggestions, but none are hard-line. You have a space between the else if and open parenthesis. I don't like this style of removing spaces around keywords and from between ) ...

View answer
2 answers
votes
468 views
Merge Sort Java Implementation
2 votes

Be consistent with your formatting. Sometimes you have a space between keywords like if and else and the opening parenthesis and the closing parenthesis and the opening brace, sometimes not. Pick one (...

View answer
1 answers
votes
237 views
Social sharing counter plugin
Accepted answer
2 votes

One improvement you can make for DRYness is to replace the switch with a simple if. This is possible because the AJAX call passes the field name in the type parameter (they all seem to match). static ...

View answer
1 answers
votes
618 views
Constructing a URL for execution using RestTemplate
Accepted answer
4 votes

For adding and removing single host names, I would use a simple ConcurrentHashMap without the AtomicReference. Initialize it with an empty map and drop the additional latch. Update: I really doubt ...

View answer
6 answers
votes
2k views
BaseRepository for EF6
5 votes

It seems strange to me for Get to be a specific way of getting all items, and GetAll should always return all items. Introduce a GetSome helper for clarity. public T Get(Func<T, bool> predicate)...

View answer
1 answers
votes
150 views
Does my controller code look good?
Accepted answer
3 votes

On the surface the code in your question seems fine, but I can tell you from experience that once this door is cracked just a bit, it will continue to creak open wider over time. "I'm just checking ...

View answer
3 answers
votes
1k views
Speeding up Project Euler 43 - sub-string divisibility
Accepted answer
5 votes

You can make a few quick improvements without altering the algorithm significantly: Remove one of the redundant calls to timer(). Store the list of primes instead of calculating it for every call to ...

View answer
3 answers
votes
9k views
Usage of AtomicBoolean
Accepted answer
6 votes

You are attempting to use the AtomicBoolean to satisfy two requirements: The first thread to access the data loads it while all others wait until it's been loaded the first time. Another thread can ...

View answer
2 answers
votes
1k views
Generic implementation of the Quick-Union algorithm with Path Compression
1 votes

While I applaud your effort to keep methods short by refactoring, I question the benefit of replacing treeSizes.get(component) with a private method call that saves two characters without ...

View answer
4 answers
votes
7k views
Basic Postfix Calculator in Java
Accepted answer
7 votes

General Use full JavaDoc for method comments. Instead of "Throw X in case Y" go for "@throws X if Y" You never need to call the default (zero-argument) superclass constructor. If the first statement ...

View answer
3 answers
votes
69k views
Java implementation of spell-checking algorithm
Accepted answer
13 votes

General Many of the variable names lack meaning and are inconsistent. I cover some of them specifically below, but for example print is not a good choice for a list of suggestions--even though you ...

View answer
1 answers
vote
443 views
Tag Cloud using 2 queries (one nested), and a foreach loop: Is there a better way?
Accepted answer
3 votes

Note: Your table and especially column names are quite verbose. I would remove the table name from each column as a first start and be more consistent with the names. I'll use better names below. You'...

View answer
5 answers
votes
4k views
Implementing a set using a linked list
7 votes

There are a few inconsistencies in your JavaDoc comments (bravo! for using them): Parameter and exception descriptions don't need to be complete sentences and should not end with a period. This helps ...

View answer
2 answers
votes
1k views
Lock for preventing concurrent access in client data
Accepted answer
6 votes

The fact that you must be able to swap in a new set of maps at any time--even if only once every three months--requires a design change. Here are the requirements as I understand them: Reads block ...

View answer
3 answers
votes
202 views
SEDE Top Sponsors
7 votes

You don't need the op join on Users since you can compare the user IDs in the question directly. Remove that join and in the where clause replace and op.Id != u.Id with and q.OwnerUserId != bo....

View answer
1 answers
votes
102 views
Does the class have unnecessary and violating Single responsibility principle method?
2 votes

You're right, but you should take this to its logical conclusion. Creating item belongs to a factory class. Tracking a list of items (coordinating?) is another responsibility. Handling the new item (...

View answer
2 answers
votes
10k views
Java implementation of the Factory Method pattern
4 votes

This pattern can be difficult to understand outside of an application with many modes of operation. There are two advantages to using the factory patterns: you can swap in different implementations, ...

View answer
6 answers
votes
20k views
Find Minimum Number of coins
5 votes

Style Surround all binary operators with spaces. Put a space before every open brace. Favor for (x : xs) over manual index management. Break up your methods so each does one thing. It sounds crazy at ...

View answer
7 answers
votes
8k views
Why does caching of string objects perform faster?
3 votes

Another aspect to consider is cache locality as the pool grows. The cost of allocating a small temporary string may be far less than an L1/L2 cache miss. You could randomly generate strings such that ...

View answer
5 answers
votes
25k views
Longest palindrome in a string
8 votes

You have the same formatting inconsistencies I pointed out in a previous question. Take two more minutes to fix these before committing (submitting code). Feel free to use your editor's autoformat ...

View answer
2 answers
votes
62 views
HTML/Attrs Tester Environment
Accepted answer
3 votes

One problem I see is that moveVal is shared across every click, but I suspect you want to bind it to each addition so that removing it removes the approach damage. To do this you'll need to store each ...

View answer
1 answers
votes
1k views
Assembly line scheduling
1 votes

The code implementing the core algorithm is very cumbersome. This is partly due to shoehorning the line entry/exit times into the first/last stations as evidenced by some internal stations in your ...

View answer