Ethan Bierlein
  • Member for 7 years, 4 months
  • Last seen more than a month ago
My first calculator
24 votes

Input validation You do absolutely no input validation when the user enters an integer. If the user enters a non-integer value, like foo, or bar, your code will crash with a ValueError. The correct ...

View answer
Turn-based battle simulator
20 votes

Style You've styled your code very well overall, I just have a few small nitpicky tips and such. First off, when running main, you need run it under an if __name__ == "__main__": block. See this ...

View answer
Imposing a sort order on a query
Accepted answer
18 votes

You could use goto, but you can also just define a function, as the label returns a value anyways. For example, your label FAILED:, would become the following function. public IQueryable<T> ...

View answer
Simple worker class program
Accepted answer
17 votes

Properties Currently, you're defining a public field, and then creating a property which can get and set that public field, like this: public int SomeNumber; public int SomeNumberProperty { get ...

View answer
Quadratic equation solver in Python
Accepted answer
15 votes

Repeating code infinitely Right now, in order to have QuadSolver repeat forever, you're calling it recursively, by calling QuadSolver again inside of itself. Unlike functional languages, which are ...

View answer
Full C++ Snake game
14 votes

Using constants Rather than using #define and creating a bunch of macros like this: #define PLANEHEIGHT 20 #define PLANEWIDTH 50 #define INITIALSNAKELENGTH 3 #define FPS 5 You should use const ...

View answer
Text based fight game
Accepted answer
14 votes

Design As it stands, your current design is very rigid, and not extensible in any way. The best approach for a situation like this could be to use Object Oriented Programming, but in accordance with ...

View answer
Simple chat bot
Accepted answer
14 votes

Whitespace. It looks nice, and is important. Use it. There are many areas here where you could insert some whitespace, and then the code will magically become much easier to read. Here are a few areas ...

View answer
Console window to debug Windows Applications
13 votes

I'm not very familiar with WinForms, or how apps like this are designed, so this will be a short review. Rather than typing out 80 repeated characters in a string, as you did here: private static ...

View answer
Populating a bag of Scrabble tiles
13 votes

Forewarning: I'm not the most experienced C# programmer, so if anything is wrong, just mention it. There is way too much useless repetition here. This begs for an implementation using System....

View answer
Grading scores from 0.0 to 1.0
12 votes

Yes, your code is correct, although I would recommend adding comments, and following the style guidelines of PEP8. Here are a few tips I have. You should specify what type of error you want to ...

View answer
Calculating Parking Fees
Accepted answer
11 votes

You're inconsistent with how you place your curly braces, {}. The general style for Java is to place opening curly braces, {, on the same line, like this: public void myMethod() { } This goes for ...

View answer
Script for a Civil War game
Accepted answer
11 votes

As mentioned by @abarnert, you're using infinite recursion to "repeat forever". By default, after you've recursed more than 1000 times, your program will throw an error. The better way to do this ...

View answer
Election vote-counting, result-posting chatbot
11 votes

To address your first concern, the way you're doing colors is fine... If you're not running Windows. If you try to use raw ANSI codes like this on windows, you're going to run into some issues. ...

View answer
SimCity clone performance
11 votes

As you asked in your question, I'm going to try and address your performance issues here. Some of this will be a style review though, so bear with me. Style First off, no offense, but this code ...

View answer
Metaballs and Gravity game;
Accepted answer
10 votes

Refactoring code structure As of right now, you have: A struct named Object. A global std::vector<Object> of Objects. A function named attraction, which (I assume) calculates the attraction ...

View answer
ASCII generator
10 votes

Generator expressions for loops like this that are simply appending items to lists are a little ugly: for i in xrange(h-1): output.append('') This is not ideal. Rather, you can directly set the ...

View answer
Filtering log files from a server
Accepted answer
10 votes

Raising useful errors If you have something like this: raise You're doing something wrong. Just calling raise with no additional useful info is not helpful. Preferably, you should do one of the ...

View answer
WaTor Code in Java
10 votes

I'm not a Java expert, and I've only looked over this code a little bit, so I only have a few tips. Why are your moveDirection methods in the specific animal classes inherited from Animal? I'd ...

View answer
Simple text RPG in Python
10 votes

There's a lot of code here, (258 lines), so I'm not going to give a full review, but rather, a few suggestions on what you can improve in general. My first suggestion is to be consistent, and clear ...

View answer
Ant Colony Simulator
Accepted answer
8 votes

Generating better random numbers Don't use rand(). It's a horrible, deprecated function that doesn't actually generate numbers that seem to be truly random. At a quick glance it seems like it, but ...

View answer
The Mysts of Altair - text-based adventure game
8 votes

There many things here that can be improved. First off, let's tackle some best practices. Generally, doing stuff like this with system isn't very good: system("pause"); system("cls"); To start off, ...

View answer
E-mail testing code
8 votes

As mentioned by @JeroenVannevel, there really isn't a good way to do this. The best you can do is something like the below. Essentially, I have one function, isEmailAddress, which returns true if an @ ...

View answer
Getting a scrabble score from a word
8 votes

Remove this line: using namespace std; This is a horrible, awful habit to get into. So much can go wrong with this line involving name conflicts. After removing this, you should prefix members of ...

View answer
"Nothing" interpreter/compiler
8 votes

This line here: return EXIT_SUCCESS Is equivalent to this: return 0; Which is automatically inserted by the compiler if it isn't found. In short, return EXIT_SUCCESS can be removed. In addition, ...

View answer
Procedural World in Unity3D
Accepted answer
8 votes

Unlike Java Lists, C# lists can be pre-initialized with values, like this: List<string> names = new List<string>() { "arco01_2_prefab", ... }; This eliminates the need to call ....

View answer
Performing and timing loops with SQL queries
8 votes

for loops Rather than using a while loop, and having an iterator variable i, You can use a for loop. A simple for loop is structured something like this: for(/* Declare `i` */; /* Check the value of ...

View answer
Three-function calculator
8 votes

First off, indent your class/namespaces. It makes things look a whole lot clearer. Even it's not necessary, you should still do it. Secondly, do you need all those usings? I don't see you using ...

View answer
Using the CMA-ES algorithm to optimize the position of wind turbines
8 votes

First off, style. Your code is... not very well styled. You have many PEP8 violations. Here's a list of those violations. You have no space between operators/variable declarations. You should have ...

View answer
Block_breaker clone in pygame with simple edge detection
8 votes

First off, according to this online tool, you have ~119 PEP8 violations. So, for my first tip, I'm going to reccomend reading Python's official style guide, PEP8. The style guide essentially tells you ...

View answer
1
2 3 4 5
7