Meaningful Names
- Do not encodes the type information in the name.
- Avoid disinformation.
- Name should be self-delaractive.
- Use Pronouceable and Searchable Names.Makes searching for symbol easier. Makes code reusability easier.
Function
- Be small. Block structures should not be nested and should be 3-4 lines long. Indent level of a functions should not be greater than one or two.
- KISS. Keep It Simple, Stupid. One function should just do one thing, and do it well. The code in the function should be one level of abstraction below the name of the function.
- The Stepdown Rule: Making the code read like a top-down set of TO paragraphs is aneffective technique for keeping the abstraction level consistent.
- Bury switch statement under the lowest level.
- Give descriptive name to function. A self-explanative name is better than a long comment describing it.
- The less arguments, the better. Function with less arguments is easier to remember. Avoid using flag argument, it's ugly. Function should just do one thing as mentioned above.
- No side effects. Side effects are lies. The function promises to do one thing, but it also does other hidden things. This is evil.
- Use this as an output argument. Anything that forces you to check the function signature is euivalent to a double-take. So put output argument is an bad idea.
- Error handling is one thing. It should be put into one function.
Comments
- Explain yourself in code.
- Explanation of intent which is not clear in code.
- If the variable or function name is self-explanative, don't repeat it in comments.
- Noisy comments should be avoided because it lower the readability.
- Delete your commented-out code. We have SCM tools, and we can revert our code through it.