cHao
  • Member for 10 years, 11 months
  • Last seen more than a week ago
  • Richmond, VA
Simple calculator in Java
17 votes

power should probably be using Math.pow(). I'm picturing how slow your code would be at calculating 1.00000015000000. Or how inaccurate it'll be when someone wants to raise to a non-integer power. ...

View answer
Div in unordered list - good practice?
Accepted answer
13 votes

Divs of any kind are a bit of a "lesser evil" -- they carry no semantic info, and should be used only when (1) you need an element there and (2) there's no semantic equivalent. In this case, you do ...

View answer
Expanding a string to a certain length
12 votes

OK, first, for the most straightforward optimization. Use a StringBuilder. The way your code currently works, it creates length - str.Length intermediate strings. Besides creating lots of ...

View answer
Why is my page semantically incorrect HTML and incorrect use of CSS?
Accepted answer
11 votes

Several things that would cause me to reject this: Nearly every element on the page is a <div>. <div> is semantically void. It says nothing about the structure of the document, other ...

View answer
Implementing a Stack in Java for a technical interview
10 votes

I would look at this code and think you hadn't messed with Java since before 1.5. You should really be using generics, particularly for a collection-type class like a stack. Any value you allow to be ...

View answer
Relying on short-circuit evaluation instead of using the IF control structure
Accepted answer
8 votes

This is an abuse of short-circuit evaluation. It's not immediately obvious what the intent is. Sure, i can eventually see that you're getting an ID, calling Req.abort(), whatever. But i shouldn't ...

View answer
Javascript assert function
Accepted answer
8 votes

I (and many other people) expect certain behavior from a function called "assert"...namely that it throws an exception or otherwise halts execution if the asserted condition isn't true. If your ...

View answer
Text-based RPG game using classes
7 votes

First off, decide whether, and to what degree, you want object orientedness. If you want to keep the current design, you may want to use structs rather than classes. At the moment this isn't very ...

View answer
Battle system in C++
7 votes

system("PAUSE") is entirely unnecessary here. You could do the same thing by simply clearing out cin and then reading a char. You should generally call srand once, at the beginning of the program. ...

View answer
Userform that calculates gas mileage
6 votes

You have a form -- by definition, a window in which text boxes and such can appear. Why are you using MsgBox and InputBox to communicate with the user? If you instead put elements on the form and ...

View answer
Template engine
Accepted answer
6 votes

There are at least two places in your code where it looks like you wanted to use an object's attributes, but you say $attribute rather than $this->attribute. PHP requires $this-> before ...

View answer
mvc improvment - 0 - to_do
Accepted answer
6 votes

This code seems to require changes based on whether magic quotes are enabled. Moreover, it's currently assuming that magic quotes are enabled. One should be encouraging the elimination of magic ...

View answer
Truly private JavaScript variables
6 votes

As for the code: The property getter and setter should probably throw an exception if the check against the caller failed. If you attempt to set it from any function besides one defined on the ...

View answer
Finding the next palindrome of a number string
Accepted answer
6 votes

Among other things: Knowing the right-side chars has exactly one purpose: it tells you whether the number you're making (when palindromized) can be returned as is, or whether you have to find the "...

View answer
HTTP redirects after login, registration, and logout
5 votes

Your RedirectInterface type doesn't redirect. It's just a URL builder. Either the name should be changed to reflect that, or RedirectInterface needs a redirect method. You're supplying a customer ID ...

View answer
Coupon code manager
Accepted answer
5 votes

I'm not seeing blatant non-OOPness, but there is a little funkiness here: The setters ideally should be usable -- and should be used -- everywhere you import potential user input into the object. ...

View answer
Stack Implementation
5 votes

As it stands, if the stack is empty, pop doesn't alter element, and doesn't let the code know that it failed. So the code using the stack thinks it popped whatever element was before the operation. ...

View answer
Simple spin game
Accepted answer
5 votes

Having the entire program contained in one function is rather frowned upon by pretty much all camps. A function hundreds of lines long can be a real pain to fix, if ever you have to. Add to that, ...

View answer
SpellParser for a text-based RPG
5 votes

Your comments don't help much. They should explain why you're doing what you're doing, not just paraphrase the code. If you can't tell the reader anything more than the code already does, then a ...

View answer
Better way to write this branch with an exceptional retry in an embedded C environment?
Accepted answer
5 votes

If you can do without the received variable...just make the radioReceive(...) the condition of a while loop. You get rid of received, and your loop condition now has a purpose. :) while (...

View answer
Calculating golf score against course par
Accepted answer
5 votes

The big thing worth mentioning here is: Use an array for your scores. The instant you do that, the code size shrinks dramatically. $course = array(0, 4, 5, 4, 3, 5, 3, 4, 4, 4, 4, 4, 4, 4, 3, 5, 3, ...

View answer
Using a singleton class to get and set program wide settings
Accepted answer
5 votes

There should be something about a Singleton class that requires that it allow and present a single, globally available, instance. Otherwise, the pattern is being misused. The way your class is built,...

View answer
Coding and printing a graph
5 votes

You're using pointers to local variables. If this were being done in a subroutine as opposed to in main, you'd probably end up pointing at objects that were no longer alive. Even if you let Graph ...

View answer
DOM-manipulation search-ordering algorithm
Accepted answer
5 votes

First off...all this cats = and return cats confuses things, since you never actually replace cats -- the items inside are what you mess with. cats = doSomethingWith(cats) implies to me that ...

View answer
Multi client chat application
4 votes

Java's common naming conventions are that names of types are in PascalCase, and names of variables are in camelCase. If chatServer is your entry point, the class should be declared as public. Now, ...

View answer
A platform-independent implementation of "which" in Ruby
Accepted answer
4 votes

I see at least two issues, aside from the atrocious code style: String#casecmp returns an integer, much like strcasecmp does in C. But in Ruby, everything other than false and nil is truthy. So if a ...

View answer
Shopping Cart Handler Class
Accepted answer
4 votes

There are a few things: Comments like this one: parent::__construct(); // to run the constructor of parent provide no real value; they just repeat what the code does. Prefer reserving comments ...

View answer
group - ajax - 0 - to_do - consistent access, styling
Accepted answer
4 votes

If you're just passing the IDs of elements, rather than the elements themselves, your variable names should reflect that. (Yes, it's possible to pass DOM elements around -- they're just objects, as ...

View answer
Simple four-function calculator
4 votes

All those globals give me the willies. Same with the evals. You're doing math in two places -- in calculate and in setOperation. Consider that display.value = x; storedNum = display.value; display....

View answer
Comparing each element of a list to all other elements of the same list
3 votes

getData is no better than doStuff() as the name of a function. getDataNotVar and getDataAndVar are only slightly better, and are useless to me, as i don't know what Data or Var you're getting. :P ...

View answer