SHORT Re: Suggestion: "fix" assert(obj)

Georg Wrede georg at nospam.org
Sun Jun 17 05:45:16 PDT 2007


Deewiant wrote:
> Walter Bright wrote:
>>sambeau wrote:
>>
>>>While I get your point completely I believe this style of debugging is
>>>only really useful to the hard-core professional.

Right.

>>>For the novice, where the debugger is a scary place of last resort, it
>>>would be more useful to have an assert too. All most of us want is a
>>>line number: and segfaults don't give us that.
>>
>>They do when combined with symbolic debug info - that is how the
>>debugger is able to display your source code with the highlighted line
>>where it seg faulted.
> 
> Yes, but you still need the debugger to see it. The fact remains that many
> novices and stubborn professionals don't use debuggers, no matter how useful
> they are and how many times they are praised by others. They're happy with their
> printf debugging, even though they would probably be happier using a debugger,
> at least in some cases.

Actually, the debugger and asserts (or even printf statements) all serve 
different purposes. The debugger is what I'd use when the situation is 
complex, that is, when there is much to inspect in the program state at 
one time. For example a tree structure, or other complex problem that 
I'm clueless about. (And a debugger is of course essential for the 
trial-and-error type of coder. :-) Sadly, that is the kind of coding 
that too easy access to [gui]debuggers tends to foster! :-( )

Printfs are real handy for much of the rest, since I usually have a 
pretty good guess of the one or two variables that might contain wrong 
values at some point. (Actually, even loop debuggin gets easier since I 
can put a few printfs inside the loop and then redirect the output to a 
file, so I have a hard copy of the entire situation, that I can refer to 
repeatedly, instead of only the momentaneous situation in the debugger. 
Lessing, grepping, heading or tailing the file are much faster than 
"creating the situation with single stepping" in the debugger.)

Asserts I mainly use in code that's ok at the time, but which might end 
up with wrong values when I'm debugging or developing another part of 
the routine or program. (Oh, and obviously and embarrassingly, I often 
use asserts instead of proper precondition tests.)

And, finally, asserts are, IMHO, the easiest way of ensuring I get 
reasonable info when the program is run by others and it misbehaves.

> In this case, either remove all asserts and force everyone to use a debugger in
> all cases, or add some asserts to make people generally happier and more
> productive when coding.

Exactly.

> Personally, I find it annoying that most crashing bugs I can catch easily with a
> normal run of the program, but when it's "Access Violation" or "Win32 Exception"
> or "Segmentation fault", I have to recompile with -g and fire up the debugger to
> find out exactly what happened and where.

Ditto.



More information about the Digitalmars-d mailing list