10 Commandments of Programming

Pt-br version here.

  1. If it’s hard, it’s wrong. If a problem seems too hard to tackle, either you don’t know exactly what you are doing or you are doing it wrong.
  2. Don’t suppose. Discover the problem and validate the idea/solution instead. Only then you start coding, measure the results and learn in the process. (a.k.a build-measure-learn)
  3. Don’t repeat yourself (a.k.a DRY). Reuse everything you can and keep things coherent.
  4. Don’t reinvent the wheel. But disassemble it and try to make a better one, periodically, just for fun. (a.k.a never stop learning)
  5. Keep it simple, stupid! (a.k.a KISS). Everything should be made as simple as possible, but not simpler (Einstein said that, so…)
  6. Always leave the code you changed cleaner than you found it. (a.k.a Boys scout rule of programming)
  7. Always be clear about what you are doing. Don’t start coding until you know exactly what needs to be done. Start writing some diagrams or mock-ups of what you need to do, to organize your ideas. Then make it happen.
  8. Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live. (a.k.a think about your team too)
  9. Don’t comment, unless you really need it. Instead, try hard to write code that’s easy to read and shows in a glance what it does. Comments are a last resort. In other words, write a clean code!
  10. The best code is no code at all. Code is hard to maintain, so whenever possible, don’t write it. Think how you can make it both more elegant and less verbose, and over time, it will shrink and work better.

These are basically the rules I try to follow when coding.

Update: I found this article with another list of good rules too follow. Check it out!

Update 2: a great checklist for good code