Program logic bugs vs input/environmental errors

luka8088 via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 28 02:20:25 PDT 2014


On 28.9.2014. 1:15, Walter Bright wrote:
> This issue comes up over and over, in various guises. I feel like
> Yosemite Sam here:
>
>      https://www.youtube.com/watch?v=hBhlQgvHmQ0
>
> In that vein, Exceptions are for either being able to recover from
> input/environmental errors, or report them to the user of the application.
>
> When I say "They are NOT for debugging programs", I mean they are NOT
> for debugging programs.
>
> assert()s and contracts are for debugging programs.
>
> After all, what would you think of a compiler that spewed out messages
> like this:
>
>     > dmd test.d
>     test.d(15) Error: missing } thrown from dmd/src/parse.c(283)
>
> ?
>
> See:
>
>      https://issues.dlang.org/show_bug.cgi?id=13543
>
> As for the programmer wanting to know where the message "missing }" came
> from,
> li
>      grep -r dmd/src/*.c "missing }"
>
> works nicely. I do that sort of thing all the time. It really isn't a
> problem.

We has this issue at work (we are working with php). We outputted a 
stack trace for both exceptions and asserts but the lines that should be 
addressed are not always so obvious.

I found a solution and it works great for us. All library code is marked 
appropriately so when stack is outputted it is shadows out (with gray 
color) all the lines in library code and point out first non-library 
line from the top of the stack. In 95% of the time it is the line that 
the programmer should look into. Other 5% is the time when it shows the 
line where programmer is forwarding a call to the library but turns out 
to be ok as it turns out to be much more comprehensible than the entire 
stack. One note worth mentioning is that juniors have much easier time 
understanding which lines concern them, and from that I can only 
conclude that such approach is more intuitive.

Marking is done on namespace level so it can be easily disabled for 
entire namespace.

I think outputting a stack trace for asserts is a must because of that 
5%. And for exceptions I agree completely with your arguments and I 
think that there is no need for stack.

 From my experience this has been a good approach and I think is worth 
considering.



More information about the Digitalmars-d mailing list