Writing Bug-Free C/D Code

Knud Soerensen 4tuu4k002 at sneakemail.com
Wed Mar 21 06:57:51 PDT 2007


On Wed, 21 Mar 2007 13:16:08 +0100, Jascha Wetzel wrote:

>> "Use a debugger only as a last resort. Having to resort to a debugger
>> means your programming methodologies have failed."
> 
> i strongly disagree with this statement.
> you can do a lot more with a debugger than printing exception
> stacktraces and finding uninitialized variables. it enables you to
> conveniently watch your program work step by step, watch intermediate
> values, etc. to check whether it does the right thing, not just on a
> low, technical level.
> no syntax or programming methodologies will prevent you from
> implementing faulty algorithms, they'll just help you to not fall into
> pits that are part of the details of a programming language.
> 
Yes, the debugger can be very useful. 
What he meant where that if your use a debugger for debugging 
you obviously got a bug in your program.
Then when your find the bug your should go check your methods to see 
why the bug slipped through.

I am working on a set of rules for bug free programing
and one of them is "Question every line of code" 
and here the debugger is very useful, it allow you to 
single step through you code and question everything.
But you should always do this not only when you get a bug.
 
Right now the rules looks like.


   1. Bug free programing is possible
   2. Every bug is due to a problem in the programming process
   3. Question every line of code
   4. Everything must scale
   5. Test all code
   6. Hide your data
   7. Count your mistakes
   8. Build it right the first time
   9. Interfaces are good, but inheritance is bad
  10. Always leave objects in a valid state



More information about the Digitalmars-d mailing list