cHao
  • Member for 10 years, 11 months
  • Last seen more than a week ago
  • Richmond, VA
Breakout-style game
Accepted answer
2 votes

First, the small stuff. getBallDiamiter has a misspelling. movement kinda sucks as a method name. move would be better, but makes ball.move(30, 100) a bit ambiguous. It's better if classes that don'...

View answer
Check if the given string has duplicates
1 votes

There are considerably more than 25 ASCII characters. Did you mean ASCII letters? Cause if the test was for characters, this code will break. But even if it's just letters, (case aside,) there are 26 ...

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
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
Monitoring real-time air waves
1 votes

This loop looks odd... static void *demod_thread_fn(void *arg) { while (!do_exit) { if (do_exit) { return 0; } ... } return 0; } Looks ...

View answer
Matching parentheses
Accepted answer
2 votes

One thing you can do is insert beforehand the characters you want to track. var _inputDictionary = new Dictionary<char, int>(); foreach (char c in "{}[]()") { ...

View answer
Fetching a post from the database based on a query parameter
Accepted answer
2 votes

There are two things that jump out at me: You assume $_GET['post'] exists. If someone just goes to post.php without specifying a parameter, $_GET['post'] is not set -- and any attempt to read it ...

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
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
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
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
Nested try/catch with PDO in PHP
3 votes

Exception handlers that don't either handle exceptions or rethrow them, generally shouldn't exist. An exception signals that a breakage has occurred -- one serious enough that the thrower thinks that ...

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
Very Basic Java Piano
3 votes

If this class is intended to represent the whole UI, window and all, you might consider extending JFrame and using this rather than frame. Right now, when you initially create a VirtualKeyboard, it's ...

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
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
Allocating memory and releasing the same
Accepted answer
2 votes

I could see passing the pointer to another thread, and the other thread deleting the object. (Gives me the willies, but it at least makes sense.) But if PostThreadMessage itself is doing the ...

View answer
Swapping adjacent nodes of a linked list
Accepted answer
3 votes

Consider having swapAdjacent(NULL) return NULL. Once it does, you can get rid of the whole if (nextNode == NULL) statement, and just unconditionally say temp->next = swapAdjacent(nextNode);. You ...

View answer
Is coding to an interface with regards to PDO the right thing to do?
Accepted answer
3 votes

This feels quite over-engineered to me, when i can do the work of all three classes in one line of code. echo new PDO('mysql:host=localhost;dbname=test', 'root', 'root'); The big question to ask ...

View answer
Is this how an MVC controller supposed to be?
0 votes

The biggest thing that bugs me about this is that Controller::__construct is basically handling the whole request. A constructor should be doing as little work as possible -- ideally only getting the ...

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
First PHP login system
2 votes

$userName = $_POST['name'] or ""; doesn't do what it looks like it does. or has a lower precedence than just about any other operator in PHP, including =. So that line is equivalent to ($userName = $...

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
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
Increasing opacity based on an element's location
0 votes

You could easily loop over the element names... for (var i = 2; i <= 36; ++i) { if (scrolled > ($wheresThisAt + (i-1)*20)) { $('#salamander-' + i).css('opacity', 1); } else ...

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
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
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
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