Hot answers tagged

6

Aside from the notes already given, here are two big ideas to think about: Don't repeat yourself (DRY) This is something you'll hear repeated a lot in discussions of code. Any time you see the same "magic values" repeated more than one place (e.g. 0 and 20), or you see two lines of code that do exactly the same thing for exactly the same reason (e.g. your ...


6

Statics You have a one-file program, so more of your methods and globals, including these: int playerLossesCount[NUM_PLAYERS]; Wall walls[NUM_PLAYERS][NUM_WALLS]; GXTexObj texObj; should be made static. Declarations for variables int main( int argc, char **argv ){ u32 fb; // initial framebuffer index u32 first_frame; f32 yscale; u32 ...


4

First off, some minor nitpicks on style. In Python, variables are usually given names like_this rather than likeThis - most of your names are fine, but userInput should probably be user_input instead. You usually want a space on each side of operators, guess = int(input()) is more pleasant to look at than guess=int(input()) Second, your program's behaviour ...


3

To add to @Sara J's answer, in Python, it's generally a good practice to wrap your main code (so the last two lines) in a if __name__ == '__main__': statement so your script can be either: Directly run Imported and its functions used as the dev that imported it pleases. https://stackoverflow.com/a/419185/1524913 Also, contrary to a lot of other ...


2

Requirements You need Python 3.6+ So at the least, you should add a shebang: #!/usr/bin/env python3 with numpy should go in a requirements.txt. Definition order You define main at the top. Call me old-fashioned, but I'm used to stricter languages where the referred symbols in a function need to be defined before that function. I still consider ...


2

There are no classes in C. However, there are functions. Regarding: CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) When compiling, always enable the warnings, then fix those warnings. ( for gcc, at a minimum use: -Wall -Wextra -Wconversion -pedantic -std=gnu11 ) the = will cause this macro to be re-evaluated every time it is referenced. Suggest: ...


2

Player identification #define Player1 1 #define Player2 2 int whoseTurn; Do you ever plan to support more than two players? If not, consider representing this as enum or a bool. The same is true of your moves and board. Those should not be strings; they should be enums. Making them strings is not strongly-typed, and gives you fewer guarantees about the ...


1

That's a lot of code to review. I've given it a cursory review and have a few comments, but by no means is it an exhaustive review. Overall, I like your style. Nice indentation, uses of braces, class access modifiers, IEnumerable(s), and variable names not being abbreviated. Most of the times, but not all, your names are clear. Other things stand out. ...


Only top voted, non community-wiki answers of a minimum length are eligible