Debugging

“Everyone knows that debugging is twice as hard as writing a program in the first place.  So if you’re as clever as you can be when you write it, how will you ever debug it?”

Kernighan and Plauger

There’s supposedly a very similar quote attributed just to Kernighan, but I chose this one mentioned in this blog which also gave me a date of 1974.

There are two assertions in this statement, and I am pretty sure that the first is not true any more given that we have modern visual debuggers provided by tools such as Visual Studio.  Debugging can be even be fun!  But I think it is certainly fair to say that  advanced debugging on a platform like Windows can easily extend complexity greatly.

However, the moral of the quote is still totally true.  If you write some code at your very best… how will you understand it the next day? And if you are not at your very best today, what sort of quality of code are you writing? Or what happens if the next person who debugs it isn’t even as smart / senior as you?

Frankly, it matters less if you follow some basic elements of programming style, and indeed, this quote is from a book titled “The Elements of Programming Style”.

Don’t be smart, keep it simple, and if you do have to write complex code, protect it in a separate place away from causing unnecessary confusion, behind a simple interface or method call.