Programming mantras

What is programming mantra? This is small advice or rule of thumb that should help write better code. Lets see some examples

  1. Less code is better
  2. Prefer composition over inheritance
  3. Don’t repeat yourself (DRY)

Sometime developers forget what is the purpose of mantras and start follow them blindly without giving a thought on what they actually doing.

Your aim as a developer write good code, not follow mantras. Mantras suppose to help you, not to make decisions instead of you.

Good code:

  • does what it is suppose to do
  • is readable and maintainable (in one row, because they are the sides of the same coin)

Here is the story from Sandi Metz which explains how DRY mantra can get you into bad position.

Duplication is far cheaper than the wrong abstraction.

See also: Too DRY - The Grep Test.