10 Commandments of Programming

Darlan Alves
3 min readDec 8, 2014

--

10 rules that will help you with being a good, professional and efficient developer.

  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.
    Break down your problem into smaller pieces and try to decouple everything. Writing pseudocode, creating aPoC and talking about your solution to a colleague are great ways to check if you’re going in the right direction.
  2. Don’t reinvent the wheel.
    We love coding. Yes, we do. But writing our own solution to everything just because we want it to be exactly like “this” or “that” is a waste of time and money.
    But you should reinvent things from time to time, just for fun. You will understand how things work to the tiniest detail. And you can only innovate or improve on things that you know very well.
  3. Never stop learning.
    Programming is hard. Thinking about all possible ways that something can go wrong is exhausting. Dealing with edge cases and crazy users is an insanity. But you will have to spend some time out of that madness to keep learning new things.
    Try a new framework, write pet projects, fill your Github account will endless crap that no one will ever see. That’s gonna be great for your one day, when you face a problem and “Aha, hold on!”, you know how to fix it because you tried that before.
  4. Always be clear about what you are doing.
    Don’t start coding until you know exactly what needs to be done.
    There’s nothing worse than someone writing code at random and just hoping it will work at some point.
    That only adds up to a pile of unmaintainable mess.
  5. Don’t repeat yourself.
    Reuse everything you can and keep things coherent. But don’t go too crazy either.
    The whole point here is… if you need to change something, you should have to change it only in one place. Otherwise, you will make mistakes.
  6. Write tests for everything.
    Not a single line of code should go to production without some form of testing. And don’t trust your coverage either!
    Code Coverage is a lie you tell yourself. Is just code porn.
    Make sure you write a test, then write a line of code to pass that test.
    Only this way you will know for sure that every single thing in your system is tested.
  7. Don’t comment, unless you really, really need it.
    Unless something incredibly hard to understand is part of your job, no comments should be tolerated.
    Long if condition? Write the condition to a local constant that explains what’s that.
    Weird algorithm. Write a function name that explains what it does.
    Comments rot, and very fast
  8. 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.
  9. Always leave the code you changed cleaner than you found it. (a.k.a Boys scout rule of programming)
  10. Stick to the rules!
    Discipline will pay off in quality and clarity over time. Things should be black and white: if you establish a rule, follow it to the letter.
    Why? Because you don’t have to think about it. Your precious brain juice is better spent on things that you DO have to think about.

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


Also recommended: Watch this series of Clean Code talks from Uncle Bob:

https://www.youtube.com/watch?v=7EmboKQH8lM
https://www.youtube.com/watch?v=2a_ytyt9sf8
https://www.youtube.com/watch?v=Qjywrq2gM8o
https://www.youtube.com/watch?v=58jGpV2Cg50
https://www.youtube.com/watch?v=sn0aFEMVTpA

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

Update 2: a great checklist for good code

--

--

Darlan Alves

Front end codemonkey. Javascript aficionado & Indoor enthusiast. In promise we trust. http://darlanalv.es