Note that, if we ignore the afore-mentioned undefined types, then the naming accounts for a vast majority of the remaining issues my editor reports. For example, allocateMines should be allocate_mines, and so on. ![]() You are using camelCase for functions, methods, attributes, variables, and parameters. snake_case naming: The standard naming convention in Python is PascalCase for classes, snake_case for modules, functions, methods, attributes, variables, and parameters, and SCREAMING_SNAKE_CASE for constants.Docstring: All your public modules, classes, methods, and functions should have a docstring explaining their usage.There should be 2 blank lines after a function or class. Sometimes, you have 1 blank line after the function.Line length: PEP8 is rather strict about line length.No space before colon: In some places, you have space before the colon that starts a new block.Here's just a couple that my editor flagged: ![]() There are plenty of tools available that can flag and even auto-correct violations of PEP8. You should always follow the guidelines of PEP8. The standard community coding style for the Python community is defined in Python Enhancement Proposal 8 – Style Guide for Python Code. Note that PEP8 mandates two lines after classes, one line after methods and functions. So, you should only use two different ways of writing the same thing IFF you actually want to convey some extra information. In general, if you use two different ways to write the exact same thing, the reader will think that you want to convey a message with that. If you are part of a team, you should adapt your style to match the rest of the team. If you are editing some existing code, you should adapt your style to be the same as the existing code. You should choose one style and stick with it. Sometimes, you use two blank lines between methods, sometimes only one. And I get the code formatted according to my preferences (e.g. If, instead, I copy
0 Comments
Leave a Reply. |