[dmd-internals] Asserts
Walter Bright
walter at digitalmars.com
Fri Nov 9 23:38:34 PST 2012
On 11/9/2012 10:10 PM, David Held wrote:
> Relying on the debugger to tell you where something went wrong is pretty
> ghetto, IMO. For instance, the debugger makes all of the commented-out
> printfs() in the code also redundant, and yet I see thousands of these. So
> which is it...should the compiler give you diagnostic information, or should
> you rely on the debugger? Since we're on this topic, let's then switch it to
> the nature of diagnostics in dmd.
I'll often use printf because although the debugger knows types, it rarely shows
the values in a form I particularly need to track down a problem, which tends to
be different every time. And besides, throwing in a few printfs is fast and
easy, whereas setting break points and stepping through a program is an awfully
tedious process. Or maybe I never learned to use debugger properly, which is
possible since I've been forced to debug systems where no debugger whatsoever
was available - I've even debugged programs using an oscilloscope, making clicks
on a speaker, blinking an LED, whatever is available.
Note that getting a call stack for a seg fault does not suffer from these
problems. I just:
gdb --args dmd foo.d
and whammo, I got my stack trace, complete with files and line numbers.
>
> Since I work on apps professionally that need to be running 24/7, I am
> naturally inclined to rely on logging rather than debugging.
> Especially when there may be hundreds of instances running, while only a few
> actually experience a problem, logging usually turns out to be the better
> choice. Then consider that logging is also more useful for bug reporting, as
> well as visualizing the code flow even in non-error cases.
Sure, but that doesn't apply to dmd. What's best practice for one kind of
program isn't for another.
>
> One of my TODO items was to take the commented-out printfs and turn them into
> a first-class logging solution with configurable log levels/modules/etc. (so
> you can turn on logging in just one subsystem if you want). If the reigning
> philosophy is instead to lean on the debugger, then that would be a waste of
> time. What do y'all think?
I've tried that (see the LOG macros in template.c). It doesn't work very well,
because the logging data tends to be far too voluminous. I like to tailor it to
each specific problem. It's faster for me, and works.
More information about the dmd-internals
mailing list