Saturday 5th April, 2008
Seven Deadly Sins of Debugging

Roger is a member of the ISO C++ Standards Committee, and a specialist in the field of debugging. Having attended one of his sessions last year, we had a pretty good idea that this keynote would be both entertaining and informative.
Roger started by stating the obvious - that the best bugs are those which do not occur, and that by learning to apply techniques to reduce problems up front (e.g. good design, unit testing, code analysis, defensive programming etc.) we can reduce the risk of bugs occurring. None of this should be news to anyone attending the conference.
After using such techniques to remove the obvious bugs, we are of course left with everything else. Debugging is quite obviously here to stay.
It has been stated that better programmers can be 20 (?) times better at finding bugs, spend less time fixing them and put fewer new bugs in by doing so. The obvious question this then raises is "Why is there such a differential, and what prevents so many of us from learning?"
Enter the Seven Deadly Sins of Debugging:
-
Inattention
-
Pride
-
Naivety
-
Anger
-
Sloth
-
Blame
-
Vagueness
Inattention can lead us to not look closely enough at what we are doing, miss the obvious patterns ("what are the real symptoms of the bug?"), and repeat the same mistakes again and again.
Details are very important in debugging - logfiles, configuration information etc. can all yield crucial information, so the more information which can be automatically generated the better. Collecting this information up-front can also save you from having to generate the information you need while actually investigating the bug.
Debugging also of course requires very focused concentration, so taking adequate breaks is essential. There is nothing less productive than staring at a debugger with a deadlocked or clueless mind -and yet all too often developers attempt to debug in exactly that way.
Keeping checklists (e.g. our own lint configuration triage procedure) can also help greatly, since it is all to easy to miss something obvious when you are under pressure to fix a critical bug. Similarly, the insight afforded by a second pair of eyes can also help, so we should never be afraid to ask for help.
The corresponding virtue is of course observation, which leads us to ask interesting questions such as:
-
What is our strategy for observing program behaviour?
-
What tools are available to give us the information we need?
-
How can we make this easier at the design stage?
Pride can lead to higher quality code in the first place, but when mis-applied it can also unfortunately:
-
Prevent us from asking for help when we are trying to fix a bug
-
Lead to a refusal to admit that a bug is our problem (and because it isn't our problem we won't look for better ways to prevent bugs).
-
Keep us following a wrong debugging hunch rather than stepping back and re-examining the evidence.
-
Lead to inappropriately clever code, and lead us to writing things from scratch when we should reuse existing solutions.
The opposite of pride is humility. Questions such as "I could be wrong", "What have I missed?" and "Who can I ask, and how?" can lead to the insights you need to fix that troublesome bug.
Naivety tends to prevent us from learning from our mistakes, and lead us to make mistaken assumptions about where the problem lies. On the plus side, the simplest fix for a bug is likely to be the right one.
The corresponding virtue is wisdom. - e.g. standing back to reflect on how the bug happened, why, and how we can prevent it happening again.
Anger needs no introduction. It can of course cloud our judgement, cause us to miss obvious clues and deny the implications of the evidence we have.
Sloth can lead us to try to avoid "unnecessary" work while we are writing code in the first place. When the resultant bug surfaces, we poke around in the debugger in vain. It also results in ignorance - a failure to read around the subject or fully understand the technology. Sadly, this is all too common.
The corresponding virtue is diligence - by learning enough about the system to understand how it behaves, we dramatically increase our chances of identifying the cause of bugs in a timely manner.
Diligence also leads to other positive effects - for example spending time upfront to save even more time later. By writing scripts, adding logging etc. we can often make a real difference when investigating a bug. Another often overlooked technique is to make error codes unique enough to look up in a search engine ("error 3" really doesn't help anyone).
Blame - As the saying goes, a bad workman blames his:
-
Tools
-
Users
-
Testers
-
Any 3rd party component
-
...in fact, anyone but themselves!
Blame of course, doesn't fix the problem, but may lose you some allies. At the end of the day, even if you can blame another system, you still have a bug to fix.
The corresponding virtue is quite obviously responsibility.
Vagueness is fatal to effective fault finding. "What exactly is the bug?" and fixing a bug, but not "the" bug can both intervene to mess things up.
However, precision greatly improves bug hunting. If something seems to be baking repeatedly, focusing on what you are doing, making error messages umore seful etc. can all help.
The bad news is that debugging is hard, and is not likely to get any easier:
-
There are more distributed systems
-
The trend is towards an increasing mix of technologies and languages
-
Higher security requirements
-
More dependencies and faster time to market
The more effective we can be at preventing, identifying and fixing bugs the less time we will spend unnecessarily in front of the debugger.
Researching a Problem and getting meaningful results

If you're on an obviously failing project, how do you get management to listen?
That was the question posed by this session. One obvious answer is of course to quantify it in a form they undestand and will therefore listen to. This actually dovetails rather closely with Tom Gilb's EVO session earlier this week, albeit from a different perspective.
Fortunately, with a bit of work you can quantify just about anything (technical debt anyone?). There is however a danger that by quantifying things doing so becomes an end in itself, rather than a tool to solve a problem. Once you quantify a problem, the presentation method of choice for managers is of course the spreadsheet (which also provide a simple way to present the results graphically if appropriate).
A financial cost estimate is of course key for this target audience. Once you have an idea of how long an issue would reasonably take to fix, it is straightforward to calculate this based on time to fix and hourly cost including (or excluding, for maximum impact when you add them in later!) overheads.
If you are planning to make a financial case it is also worth remembering that capital costs and labour costs do not always compare directly, since the former can (certainly in the UK) have an impact of profit margins but the latter will not (you find this sort of stuff out when you set up your own company, believe me!).
A key question is of course how to quantify a failing project, rather than just one part which can be fixed? The obvious metric is "how much is the company spending per month on this project?".
C++ 2009 in 90 minutes
(Alistair Meredith - Codegear)
Alistair Meredith is a member of the C++ Standards Committee, and this session was a lightning tour of the changes in C++ 2009 (otherwise known as C++ 0x; Alistair stated that they are aiming for a 2009 release) - the first full C++ standard release since C++ 1998. As such, it is a major update.
Alistair first of all described the features which will (unfortunately) be missing from this release: e.g. library features beyond TR1, C++ modules, math binding and garbage collection have been deferred until TR2 (due in 2012?) or will be incorporated into separate standards.
The final release candidate of the standard should be out in September 2008 - which would mean that all comments will be received by January.
So what's new? In short:
-
50 new language features
-
New libraries
-
A wider set of standards
-
Revisions to existing libraries
-
The incorporation of features from C99 + TC1 + TC2 + Unicode TR
-
ECMAscript regular expressons
-
Threading
Some of the most fundamental changes are (as is to be expected) in the area of concurrency. Notably, C++ 2009 will finally define a modern memory model, which should lead to less uncertainty in defining what is and is not acceptable in multi-threaded code. The biggest impact of this change is of course in defining which fundamental assumptions can and cannot be made by optimisers, so it should be largely transparent for most.
Other changes in this area include the addition of defined atomic operations (there is a new atomic keyword), intrinsic threads and locks and (possibly) futures. Thread pool support has been deferred to TR2, which is a shame but understandable given the volume of change already proposed.
Alistair talked at length and in detail about the new and changed language features, but did not have time to discuss the corresponding library changes. I can't even begin to do everything justice, so here's a long bulletted list of the changes he described:
- The meaning of the
autokeyword has been changed to a type deduction specifier (a.k.a. dynamic languages). - Template aliases (non specialised template typedefs)
- Raw string literals
- UTF8 string literals
- Delegating constructors (allows constructors to delegate object initialisation to another constructor)
- Inheriting constructors
- Member initialisers (maybe)
- New for- loop syntax for simple containers (maybe)
- Lambda expressions
- Reconstituted pointers (needed for future garbage collection support). This could potentially become a breaking change in future.
- Simplified syntax for things such as template, typename, right angle brackets in templates.
- Reference collapsing (reference to reference is no longer an error)
- Nested classes are now members of the enclosing class
- Spurious semicolons are no longer an error
- Default template parameters for function templates
- sizeof(non-static) data members
- Linkage for local types (maybe)
- Extern C function pointers (maybe)
- Concepts (compile time checking of template implementations, leading to improved error detection and diagnostics)
static_assert- Explicit conversion functions (e.g. explicit
operator bool()) - Deleted functions (a neat way to stop default assignment operators/constructors from being implemented etc.)
- Reference qualifiers
nullptr- Scoped enumerations
- Detection of array new overflows (maybe)
- Conditionally supported behaviour (optional)
- Inheriting constructors (strong typedefs)
- Extended friends in templates
- Variadic templates
- Perfect forwarding in templates (deals with the explosion of overloads where const is involved)
- Move semantics (through rvalue references)
- Enhanced unions (no comment!)
- Extensible literals (maybe)
- Variadic macros
- New data types (
long long,char16_t,char32_tand extended integral types) decltype- auto function declarations
- defaulted functions
- New initialiser list syntax (maybe)
- Compiler attributes (maybe)
_Pragma(from C99)- Trivial types
- New types
- Alignment specifiers (e.g.
alignof) - C99 preprocessor
- constexpr
- Trivial types
- Memory model
- Thread local storage
- Atomic operations
- Parallel initialisation
- inline namespacing
- Exception cloning and nesting APIs
- extern template
- Native support for type traits.
__func__and Updated assert macro.- Unicode identifiers
And that's just in the compiler...!
The State of the Practice
(Tom Gilb, Hubert Matthews, Russell Winder, Peter Sommerlad and James Copelien)

The subject of this panel was in effect: "Are we barking up the right tree? So many developers have no idea of basic good practice. Discuss.."
While I can't even begin to do the ensuing discussion justice, the responses of the panel members to the opening question give an interesting insight into the discussion :
Tom Gilb: "There is not enough focus on delivering value to our stakeholders"
Hubert Matthews: "We have forgotten the human element and reward structures reflect that"
Russell Winder: "Polarisation. There is (unfortunately) a lot of dross out there."
Peter Sommerlad: "The state of practice is partly a reflection of past failure in academia. It is now too easy for lay people to produce badly written software."
James Copelien: "This is a wicked problem without clear cause and effect."
I gave up taking notes when the discussion wandered into the "bottomless pit" issue of professional certification...
