Related: Programming MOC, Concepts MOC
Info
Clean code are good coding practices. I’m writing them down with examples as I come across them myself.
Read Clean Code by Robert J Martin !
Naming Variables
- Meaningful names: avoid comments to explain what the variable is.
- instead of
var d; // elapsed time in days
, usevar elapsedTimeInDays
- instead of
- Disinformation/Misnomers: some common spoken words mean something specific in coding, like “list”
- instead of
var accountList = [ ]
, you can just useaccounts = [ ]
- instead of
Functions
- Keep them small and doing one thing: “They should really be 20 lines long. The longer a function gets, it is more likely…to do multiple things and have side effects.”
Other
- Know the language style guides: Just like each newspaper has a style guide, so does each coding language.
- quick example: snake_case in python, and camelCase in Java
- Style guides