Post History
Find a style guide and stick with it. Style guides are more than just comments - they cover all parts of your code from how you name your variables to how you structure your code. Good style guid...
Answer
#3: Attribution notice added
Source: https://writers.stackexchange.com/a/36233 License name: CC BY-SA 3.0 License URL: https://creativecommons.org/licenses/by-sa/3.0/
#2: Initial revision
# Find a style guide and stick with it. Style guides are more than just comments - they cover all parts of your code from how you name your variables to how you structure your code. Good style guides are designed to keep your code as maintainable as possible, with an emphasis on readability. There are a number of style guides you can follow. Here is [Google's C++ Style Guide](https://google.github.io/styleguide/cppguide.html). For the moment, you are mostly interested in the naming, commenting, and formatting sections, but you'll learn a lot from reading the other sections as well. Good style guides provide rules, explanations for why those rules exist, and examples. The most important rule is to pick a style and stick with it. If you are consistent then both writing and reading your code becomes easier. # Quick and dirty rules of thumb If you don't want to read through the style guide, my rule of thumb is that it should be possible to use a function without having to read the code. That means it should be completely comprehensible from the name and docstring. That usually means fully explaining what each of the arguments do, and that the return value means. If your code expects particular units (meters, seconds, etc), **always** describe what units you are using. If, after returning to a piece of code after a little while doing something else, it takes you more than 10 seconds to figure out what a piece of code is doing or why it is doing that, add a comment.