Writing good code

From Training Material
Jump to navigation Jump to search


Coding guidelines:

  • Divide the program into functions
  • Write short docstrings for all functions.
  • Use reasonable variable names.
  • Use reasonable function names starting with a verb.
  • Don't re-invent the wheel, using libraries makes your code shorter and easier to maintain.
  • Writing test functions saves lots of time on a long term.

The Dogma of Programming

  • First, make it work.
  • Second, make it nice.
  • Third, and only if it is really neccessary, make it fast.

Code formatting conventions:

  • Use spaces instead of tabs (or use an editor that converts them automatically.
  • Keep lines less than 80 characters long.
  • Separate functions with two blank lines.
  • Separate logical chunks of long functions with a single blank line.
  • Variables and function names in lowercase.