<< January 10, 2008 | Home | January 12, 2008 >>

Tips for Honest Programming

Keep your code moral

Chalain blogged about Dishonest Programming and provides a few tips on how to write moral code by being honest with yourself, with the compiler, and with your coworkers.

I think the first ones are most important:

  • Name functions for what they really do.
    Make sure your functions do what the name implies. Review your code to identify large parts that are doing different things like checking for preconditions or handling errors and extract them.
  • Let your yea mean yea and your nil mean nil.
    If you write a function called createLink() it should create a link or clearly indicate failure (e.g. by throwing an exception). Side effects that are not reflected by the name should be well documented.

Few code is ever written to be dishonest but as new features are added and bugs get fixed in a hurry it is easy to become immoral.

References

Tags :