Monday, April 09, 2012

Avoiding bugs in code

Its really very simple. It goes like this:

1 - the more code you write, the more likely there are to be bugs in it.

2 - Inverting (1) we have : the less code you have, the less bugs you have.

3 - When programming, it is good to avoid bugs. Therefore, following (2), write less code.

How to get the job done but write less code? Spend more time in *design*. What is the minimum amount of new (and therefore buggy in unpredictable ways) code you can write to get the job done.

Programming is Haiku, not Victorian Novel.

Yes, its art. But there is a science to the art.

Good programmers write less code. They take the time to ensure they are brief in their code expression.

There is no more important skill in software engineering in my opinion. Its all about the code you *dont* have to write.


Anonymous said...

Thanks! This applies no matter the language, library or platform used. To what extent do you believe languages are a factor? I've been using Scala in a simple, somewhat functional way and I find that the "less code" benefits are huge. I assume you find the same in your use of Jython.

Sean McGrath said...


Yes, I find the same with Python/Jython. However, literal code size can be misleading if taken too far. For example, APL is very brief but is it "less code" when you factor in the limits of human cognition we all have to live under?

Similarly, with Perl. Amazing functionality/lines-of-code density but ready comprehension can suffer. At least, it sure did in my case. I remember staring at a short Perl program once wondering what it did and what idiot wrote it so densely....only to find out that I was that idiot, about 6 months prior.

Anonymous said...

Agreed. Scala's flexible syntax can lead to some Perlish code. It can also lead to the expressiveness of well written Python or Ruby. Saving keystrokes is not the goal ;-)