seand
  • Member for 10 years, 1 month
  • Last seen more than a month ago
Ternary operation in Java - isn't this abuse?
57 votes

I think it's important to note that nested ternary operators can be formatted to look good: String name = isConditionA ? "first" : isConditionB ? "second" : isConditionC ? "...

View answer
How is my BlackJack game design?
Accepted answer
8 votes

A few notes: I don't think you're utilizing OOP to its full potential in your BlackJack class; all its methods are static and you're passing around too many variables. A cleaner alternative would be ...

View answer
Sets, Check and add
8 votes

You could also use a variable to make the compact version more readable: public boolean isTerminal(Node node) { boolean stateWasAdded = _seen.add(node.getState()); return !stateWasAdded; }

View answer
Android SQLite Database management
6 votes

The code looks fine to me but it is a bit odd because the official docs recommend creating a SQLiteOpenHelper subclass to handle database interaction. And if you use one SQLiteOpenHelper instance ...

View answer
Will this test to check if an element has an attribute work?
Accepted answer
6 votes

To check if an HTML element has an attribute, you should use hasAttribute. If you have to support IE6 and IE7, check its existence using [name]. Given that, the implementation of hasAttr would be ...

View answer
jQuery parallax site (on scroll)
6 votes

The jQuery documentation offers the best advice: Event performance In most cases, an event such as click occurs infrequently and performance is not a significant concern. However, high ...

View answer
Fastest way to remove/hide a lot of elements from a list
5 votes

A couple notes: display: none does everything you're trying to do with your existing CSS class; it hides and completely removes the element from the layout. So instead of adding the zero class you ...

View answer
Is this C++ naive primality test done right?
5 votes

2 things: isPrime(9) returns true because you're using < in the loop's termination clause instead of <=. You don't need to add a special case for eliminating even numbers, you can just change ...

View answer
Java binary search (and get index if not there) review
Accepted answer
5 votes

2 minor things: Remove the unnecessary comparison. If sortedArray[mid].equals(target) fails, it will again compare the two strings in the next if condition. Instead, you can just do: int c = ...

View answer
Safely using console.* in browser
Accepted answer
4 votes

I don't see any problems with that. It's similar to this answer on SO. Just a couple minor things: You don't need args in the empty log function You should make the entire function anonymous and ...

View answer
Step-by-step form
3 votes

jQuery was designed so you can chain function calls together like that. If you're worried about readability, then break them up into logical parts. You can either use variables, or keep the chaining ...

View answer
Publishing a description about a selected band
Accepted answer
3 votes

I have several comments on both your HTML and your JS. We'll start with the HTML: You can keep it much cleaner by separating Javascript from it completely. For example, instead of doing this: <...

View answer
AJAX call in JavaScript
Accepted answer
3 votes

There are a couple issues with this code: You don't define a function in Javascript with ajaxRequest(function() { ... }); What you're doing there is calling function ajaxRequest and passing an ...

View answer
SQLite class to manage recipes for an Android application
2 votes

If you're using one instance of SQLiteOpenHelper across your application (which you should be doing), you should never need to call close on it or the SQLiteDatabase object. Why do you need the ...

View answer
Mapping the differences between JavaScript objects
2 votes

I was going to post this as a comment to palacsint's answer but it helps to have code blocks. Because you're using this pattern in several places: for (var prop in obj) { if(obj.hasOwnProperty(...

View answer
DIV mask implemented in JavaScript/CSS
Accepted answer
2 votes

The code looks fine to me. Just a couple minor points: Why do you change the div's position to relative? If the function is called on a div with absolute positioning, it would mess up the layout. And ...

View answer
Will this kind of codes leak memory?
2 votes

No, there is nothing you're doing in that code that would result in memory leaks. I found an article written by Jack Slocum (creator of the ExtJS framework) that details some basic steps to follow to ...

View answer
jQuery horizontal slide out navigation
2 votes

2 comments: Why are you passing the same function twice to $.toggle()? From the documentation it looks like it only takes 1 function, the callback. You can abstract out the common functionality in ...

View answer
JSON formatting and processing hierarchies
Accepted answer
2 votes

Assuming you're using JavaScript to manipulate the object, you could also split it up into 2 different structures, one for maintaining the hierarchy and another for easy access: var hierarchy = { ...

View answer
Prevent Double Form Submit within X seconds
2 votes

You could wrap the entire thing in an anonymous function that you immediately execute: (function() { var aLockedForms = []; ... )(); Edit: I want to clarify that this is something you can do to ...

View answer
Web files browser
Accepted answer
2 votes

A couple notes on design: Split the code up into different objects that handle specific tasks. You don't need to split your code up into different files, because it's not that long (yet), but you can ...

View answer
Checking a HTML element's class
Accepted answer
2 votes

It looks like whatever library you're using is generating properties and sticking them inside the class attribute, which I've never seen before and seems questionable (why can't they be attributes on ...

View answer
Finding the most frequent character in a string
2 votes

I think your solution is optimal in terms of efficiency. One alternative would be to eliminate the last loop which iterates through the holder array to find the maximum by keeping a running max, like ...

View answer
Converting an integer into the written form
2 votes

I can't comment (not enough rep I guess), but one minor thing I noticed is that if the input number is evenly divisible by 100 or 1000, it will have a space at the end of the printed string. Example: ...

View answer
Android SQLite architecture for a task list
1 votes

I don't have any comments on the architecture, but here are 2 suggestions: To keep database access thread-safe, I would suggest you make your DatabaseHelper class a singleton and only access the ...

View answer
Object construction differences
Accepted answer
1 votes

Correct, the lifetime of objectSettings is only for the MyObject function, so you don't need the assignment to null at the end. Passing in an object to the constructor is a common pattern to set its ...

View answer
isType(obj) / getType(obj) - v0
1 votes

I think you can run into issues when checking arrays across frames in IE 7 and older, so if you want to make it accurate for that case, check out this answer on StackOverflow.

View answer
Expanding branches of a family tree
Accepted answer
1 votes

A couple notes: I would use classes instead of ids for the nested links. I don't know if it's faster to search the DOM for all elements with a specific class, but it looks cleaner and doesn't require ...

View answer
Improving script performance for looping unparalleled arrays
Accepted answer
1 votes

Instead of iterating through the inner array multiple times, it might be faster to create a map for the inner array beforehand and then test for a match within the map. (I think this will only work if ...

View answer
Optimize coloring book built with Raphaël and jQuery
1 votes

First of all, the best way to optimize any code is to run it through a profiler to find the bottlenecks. Assuming you've already done that, here are a couple very minor things: This code: for(var i ...

View answer