10 Commandments of Programming
- 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.
- 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)
- Don’t repeat yourself (a.k.a DRY). Reuse everything you can and keep things coherent.
- 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)
- Keep it simple, stupid! (a.k.a KISS). Everything should be made as simple as possible, but not simpler (Einstein said that, so…)
- Always leave the code you changed cleaner than you found it. (a.k.a Boys scout rule of programming)
- 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.
- 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)
- 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!
- 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