Check Your Code First before Looking to Blame Others

From WikiContent

(Difference between revisions)
Jump to: navigation, search
(New page: Developers — all of us! — often have trouble believing our own code is broken. It is just so improbable that, for once, it must be the compiler that's broken. Yet in truth it is very ...)
Line 18: Line 18:
So before you rush to blame the compiler remember Sherlock Holmes' advice, "Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth," rather than Dirk Gently's, "Once you eliminate the improbable, whatever remains, no matter how impossible, must be the truth."
So before you rush to blame the compiler remember Sherlock Holmes' advice, "Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth," rather than Dirk Gently's, "Once you eliminate the improbable, whatever remains, no matter how impossible, must be the truth."
 +
 +
By [[Allan Kelly]]
 +
 +
This work is licensed under a [http://creativecommons.org/licenses/by/3.0/us/ Creative Commons Attribution 3]
 +
 +
 +
Back to [[97 Things Every Programmer Should Know]] home page

Revision as of 14:14, 1 February 2009

Developers — all of us! — often have trouble believing our own code is broken. It is just so improbable that, for once, it must be the compiler that's broken.

Yet in truth it is very (very) unusual that code is broken by a bug in the compiler, interpreter, OS, app server, database, memory manager, or any other piece of system software. Yes, they exist, but they are far less common that we might like to believe.

I once had a genuine problem with a compiler bug optimizing away a loop variable, but I have imagined my compiler or OS had a bug many times. I have wasted a lot of my time, support time, and management time in the process only to feel a little foolish each time it turned out to be my mistake after all.

Assuming the tools are widely used, mature, and employed in various technology stacks, there is little reason to doubt the quality. Of course, if the tool is an early release, or used by only a few people worldwide, or a piece of seldom downloaded, version 0.1, Open Source Software, there may be good reason to suspect the software. (Equally, an alpha version of commercial software might be suspect.)

Given how rare compiler bugs are you are far better putting your time and energy into finding the error in your code than proving the compiler is wrong. All the usual debugging advice applies so isolate the problem, stub out calls, surround it with tests; check calling conventions, shared libraries and version numbers; look out for stack corruption and variable type mismatches; try the code on different machines and different build types such as debug and release if you use these.

Question your own assumptions and the assumptions of others. Tools from different vendors might have different assumptions built into them – then so too might tools from the same vendor.

When someone else is reporting a problem that you cannot duplicate go and see what they are doing. They maybe doing something you never thought of or doing something in a different order.

As a personal rule if I have a bug I can’t pin down, and I’m starting to think its the compiler then its time to look for stack corruption. This is especially true if adding tracing code makes it move around.

Multi-threaded problems are the other type of bug that turn hair grey and have one screaming at the machine. All the recommendations about simple code are 10 times greater when a system is multi-threaded. Debugging and even unit tests cannot be relied on find bugs so simplicity of design is paramount.

So before you rush to blame the compiler remember Sherlock Holmes' advice, "Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth," rather than Dirk Gently's, "Once you eliminate the improbable, whatever remains, no matter how impossible, must be the truth."

By Allan Kelly

This work is licensed under a Creative Commons Attribution 3


Back to 97 Things Every Programmer Should Know home page

Personal tools