Programming Good Practices
There are many practices in programming that are thought to be good for code readability and maintenance. A good thing to keep in mind is that you may not be the one who updates your code in the future, therefore it should be objective and easy to understand.
These principles include:
- Code should be split into functions so that 1 function does 1 thing.
- All functions should be labelled with their general purpose with comments (“//” in c).
- Code should be separated using white space (blank lines) between functions.
- All variables should be declared at the top of a function.
- Functions and variables should be named by purpose (the worst possible variable name is var1).
- Recursion should be avoided wherever possible.
- Constants should be used rather than values.
- Code should never use “GOTO” statements.
- If more than 3 “else if” are used, then a switch statement should be used instead.
- The end condition of a “for” loop should not be edited within the loop.
- Variables should always be local and passed between functions rather than global.
- Factorial and exponential algorithms should be avoided at all costs.
- The size of an array should not be altered after declaration.
- Python should be avoided where possible (This is a joke, I just hate python).