Time and Location
Avoiding Code Smells
I’ve been writing code for over 40 years. One thing that comes with experience is one develops a nose for code smells. When you’re asked to help someone find a bug in their code, you can often just glance at it and get a pretty good idea where to hone in on where the error is likely lurking.
How is this possible in a large code base? It turns out that the human brain is a very good pattern matcher, and by experience one learns to recognize what code looks like that has bugs in it, i.e. it smells. Sometimes, though, it is hard for the person to say just what it is that triggers the smell, just that it stinks. I’ve tried to distill out what those characteristics are.
Inevitably, since this is based on my own personal experience, it is a highly personal list. Many you’ve surely heard before, I hope there will be some you haven’t recognized yet. Will eliminating smells actually result in bug-free code? Maybe that’s too much to hope for, but I bet we get a lot closer to it.
Walter Bright is the creator and first implementer of the D programming language and has implemented compilers for several other languages. He’s an expert in all areas of compiler technology, including front ends, optimizers, code generation, interpreter engines and runtime libraries. Walter regularly writes articles about compilers and programming, is known for engaging and informative presentations, and provides training in compiler development techniques. Many are surprised to discover that Walter is also the creator of the wargame Empire, which is still popular today over 30 years after its debut.
A Word From Our Sponsor
Gordon Churchill is an embedded Linux specialist in medical devices and other safety critical systems.