Re: Assertions and Such

Dave Scott wrote:

> On Mon, Aug 21, 2000 at 04:53:23PM -0400, Sean Middleditch wrote:
> >
> > ... Why wouldn't you kill warnings?  The messages from compilers and GTK
> > don't say: "Notice: you are using a deprecated API or your code needs
> > restructuring", they say: "Warning: there's a bug in your code else this
> > wouldn't be printed to the screen!!"
> >
> Warnings from compilers can sometimes just be warnings, not bug reports.
> $ cat t.c
> int main(int argc, char* argv[]){
>   int x = 1; // or get input from somewhere
>   if (x)  { return 1; }
>   if (!x) { return 0; }
>   // control reaches here?
> }
> $ gcc -o t t.c
> $ gcc -Wall -o t t.c
> t.c: In function `main':
> t.c:8: warning: control reaches end of non-void function
> You could argue that the code was correct, as it always had a well defined
> result. Should it be refactored so it's more obvious to the compiler what's
> going on? Should that actually be classed as a bug?

Actually, yes.  There's a reason that happens.  What if a programmer was
testing the code to see what happens if x is never true, so comments out the
first if?

It's more a habit of coding style, perhaps, but if you're going to enable
those kinds of warnings, you should perhaps take head.

> > ...
> > I mean, simple things like an app always causes GTK to generate a warning
> > about passing a NULL pointer to some function....
> >
> I guess it's a bit trickier with runtime warnings generated by GTK. As an
> app gets more complicated it's going to be harder to test all the various
> bits of GUI code. Sitting at a computer randomly clicking on things trying
> to get them to break doesn't sound like much fun ;)

I don't mean be 100% sure your code is perfect.  Just don't release stuff that
you know has bugs.  After all, half the people that download it will find the
bug, get annoyed about it, send a bug report and then use another program.
You could have saved them, and yourself, the trouble by fixing anything you
knew about.

An unknown bug is different.  Simply, you didn't know about it.  As long as
you fix it when someone points it out, you're doing the best you can, right?

> Dave
> --
> They'll fight... and they'll win!
>   -- Do you want to know more?

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]