I collected a whole bunch of links recently and have just started going through them in depth. One of them was a blog post called A Double Handful of Programming Quotes. The first quote in the list was this one:
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
- Brian Kernighan
This is one of what I like to call a thinker. What does it really mean? At first it sort of makes one think that he is saying that people are not smart enough to debug their own code. Clearly that’s not right though. Is it? I think not. What I think he is really saying is that it doesn’t pay to be too “clever” or tricky in your code. It the code you right is some sort of tour de force that takes every ounce of your skill and knowledge then you’ll be in trouble if (when) something goes wrong. This may work when you are a new programmer working hard to stretch yourself and have a mentor or instructor with far greater skill than you posses but if you know it all like some of us do … Well maybe you shouldn’t be showing off too much.
I’ve seen a lot of beginners write code that was too complex for them to debug themselves over the years. Often this happens because they try to write too much code at once before testing any of it. Or they get clever by using something they barely know and are bitten by unexpected side effects. As a teacher (or mentor) more experienced programmers see that a lot. most often it becomes a good learning experience. But for those learning on their own it can be a nightmare. That’s one of the reasons I believe most people are better off learning with others – a teacher, a senior developer or some other mentor who has gone before.
This is also an argument for keeping things as simple as possible. Sure you have to do some tuning at times. And sometimes you have to use some advanced “tricks” or tools that push you to your limit. But if/when you do you should be pretty careful how you use them. (And maybe read the documentation as well.)