New answers tagged

4

Type hints The parameters to your MazeSolver.__init__ should get type hints, particularly for things that don't have defaults. For instance, maze_path: str. Separate input You shouldn't be calling input from __init__. Just accept it as another parameter, and do the input and validation at a higher level. In-band logic Baking 'a' as a special condition ...


4

I would make the following recommendations to clean it up for future maintainability and readability: Clean up and remove the anonymous functions. They aren't really needed here and just create extra clutter, decreasing readability. Remove the additional setTimeout call and just call to show when you're done loading. Use more meaningful names. It was ...


1

Define your variables at the top of your script outside of the setTimeout. That way, you only need to define every variable once. Also, you can make them const, since they won't change. The same goes for the run() function. Declare it outside of the setTimeout. You just want to call it inside the setTimeout. I hope this is helpful for you. const wrp = ...


13

This is a tip I make a lot, but if you have a collection that's simply tracking "membership", and you don't care about order, you should consider using a Set over a List. I think this is the case for cell.linked_cells. The only thing you ever do with cell.linked_cells is do in membership tests, and add and remove from it. Make the following changes: ...


7

Type hints row_index, column_index, rows, columns I can guess that these are all int based on the docs. But adding :int (etc) will help, here. Variable reuse north = self.row - 1, self.column if north[0] < 0: north = 0 neighbors.append(0) if north: neighbors.append(grid[north[0]][north[1]]) This is confusing. north ...


2

Animation base class typedef std::chrono::high_resolution_clock hrc; In modern C++, use an alias-declaration: using hrc = std::chrono::high_resolution_clock; It is arguably more readable. std::chrono::time_point<hrc> m_now; unsigned int m_us; // us for microseconds unsigned int m_endUs; The types and names of the last two members are not ...


2

Code and style Many variables you have declared can be constants const rather than let. Element properties defined in the DOM do not need to be set via setAttribute eg canvas.setAttribute("width", canvasWidth); can be canvas.width = canvasWidth window is the global this. You do not need to specify it. eg window.requestAnimationFrame can be ...


Top 50 recent answers are included