# Tag Info

5

Welcome to Code Review! PEP-8 In python, it is common (and recommended) to follow the PEP-8 style guide for writing clean, maintainable and consistent code. Functions and variables should be named in a lower_snake_case, classes as UpperCamelCase, and constants as UPPER_SNAKE_CASE. f-strings Newly introduced in python 3 is the f-string; so instead of having ...

4

There's a lot in your code that can be refactored but let's start from the beginning with some Python styleguides (also called PEP8) Imports It's recommended to write all the imports at the top of your file. Naming In Python, the name of functions and variables should be snake_cased. That is, instead of def Roll() you should have def roll(), instead of ...

4

I'm not an expert in SFML, so I can't really give any advice about that. Though, let me look at the code as is. Let's start with Game.h: Your Game is taking a const char * as argument, I would recommend std::string_view if you would be compiling with C++17. It has a lot of features of std::string and it behaves as const char * I like how you encapsulate ...

4

Prefer member variables to be private if possible There are a lot of member variables that are public that are not used outside the class itself. For example, Game::score, Bird::texture_wing_up, and many more. These should all be private, as this prevents other classes from accidentily accessing these member variabels. Avoid premature inlining of functions ...

4

Indentation Much of the indentation in the HTML, CSS, and JS is inconsistent, which makes the code moderately harder to read than would be ideal. Consider using an IDE which automatically formats code properly so things can be made readable without having to mess with it manually. Duplicate IDs are invalid HTML You have two elements with div id="egg&...

3

First pass: Move most of the list creation stuff into a function PEP8 fixes: standardize spaces, get rid of continuation escapes, spaces between functions Some immutable tuples instead of lists def make_num_lists(): x = [xx for xx in range(1, 64)] num_i = [i for i in range(1, 64, 2)] num_ii = (x[ 1::16] + x[ 2::16] + x[ 5::16] + x[ 6::16] + ...

10

Magic numbers As already mentioned in comments, the numbers $1, 2, \cdots$ appear to be completely random to anyone not sure about how the summation is going to (or supposed to) work. The generation of the lists is also very cumbersome. The same trick could be expanded to a selection upto $127, 255, 511, \cdots, 2^{n} - 1$. Recursive main You have a ...

3

The code looks mostly well structured, formatted and using good names for functions, so those "obvious" things don't need fixing. Logic 1 / Don't repeat yourself if WINDOW_SIZE[0] % SNAKE_SIZE != 0 or WINDOW_SIZE[1] % SNAKE_SIZE != 0 or MARGIN % SNAKE_SIZE != 0: raise Exception('Size of grid should be divisible by SNAKE_SIZE') Since you're ...

4

const float updatesRate = 1 / 60.0f; const float framesRate = 1 / 308.0f; The other time values are all doubles, it's a bit strange to use floats here. if ( newTime - timer >= 1 ) { ... if ( frameTime > 0.25 ) frameTime = 0.25; These magic numbers should be named constants. C++ now provides a variety of time-related utilities through ...

2

Stray console You have window.console.log( this.getAttribute( 'data-pos' ) );. They're useful for debugging, but remember to remove logs for production. Consider no-console. n A variable named n is not all that informative. How about calling it totalNumberOfTiles instead? Also, rather than for ( let i = 0; i < n; i++ ) { initialTileArray.push( String( i + ...

4

Use more functions Currently, the entirety of your hangman game lies inside the run() call. You can split certain parts of it to their own functions, such as checking for win condition, asking for character input, displaying the current state etc. Empty prints Use \n to get a new line in console, instead of putting in empty print statements. Checking guessed ...

4

My understanding is that by using a unique_ptr my state gets stored on the heap, and this avoids the problem of object slicing Well... technically, no. When you have a pointer to a base class pointing to a derived class, non virtual methods still get sliced. However, since we allocate on the heap and pass around a pointer to the base class, that information ...

7

Answers to your questions Inheritance: I have not really used this before in C++. My understanding is that by using a unique_ptr my state gets stored on the heap, and this avoids the problem of object slicing. My State methods are all pure virtual, and overridden by the subclass. Am I missing anything? Object slicing happens when you copy a derived class ...

2

Program design Handling of grapheme clusters The program operates on Unicode grapheme clusters, presumably to handle different languages. However, Hangman only really works on languages with an alphabet small enough. Japanese, as a counterexample, is written with a wide range of individual characters — around 50 hiragana, 50 katakana, 2,136 commonly used ...

1

Welcome to Code Review. Nice implementation and good structure of the code, find my suggestions in line. There is a better way to generate the random numbers of snakes and ladders. The methods setSnakes and setLadders differ by just a couple of lines of code, which is an indicator of code duplication. This is the method setLadders: public void setLadders(...

Top 50 recent answers are included