Styleguide for programming
2 min readNov 30, 2022
This is how you can make your program readable:
READABILITY
- Write your code clearly — don’t be too clever nor too efficient over clarity.
- Say what you mean, simply and directly for easy understanding.
- Write first in easy-to-understand pseudo language; then translate into whatever language you have to use.
- Modularize. Use procedures and functions to avoid repetitive expressions
- Use in-built functions first.
- Use parenthesis and indentation to avoid ambiguity.
- Format a program to help the reader understand it.
- Don’t patch bad code — rewrite it.
VARIABLES
- Use variable names that are relatable and meaningful.
- Avoid too many temporary variables.
- Initialise all variables before use.
- Choose a data representation that makes the program simple.
INPUT
- Make sure input doesn’t violate the limits of the program.
- Identify bad input; recover if possible.
- Make input easy to prepare and output self-explanatory.
- Use uniform input formats.