NaNs Just Don't Get No Respect

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Sat Aug 18 19:36:44 PDT 2012


On Sat, 18 Aug 2012 06:44:12 +0200
"Jesse Phillips" <jessekphillips+D at gmail.com> wrote:

> On Saturday, 18 August 2012 at 01:07:43 UTC, F i L wrote:
> > Your example:
> >
> >     float f;
> >     if (condition1)
> >         f = 7;
> >     ... code ...
> >     if (condition2)
> >         ++f;
> >
> > is flawed in that condition1 is _required_ to pass in sync with 
> > condition2, or you'll get a NaN in the result.
> 
> It is not flawed as that is exactly what he said condition1 did 
> until the maintenance programmer made a change which caused this 
> to no longer be in sync with condition2 (most likely fixing a bug 
> as condition1 really should have been false).

If that's the case, then the code is far too damn fragile in the first
place.

This:

    float f;
    if (condition1)
        f = 7;

Is bad fucking code, period. I'd expect *ANY* usage of f after that
(except, of course, a plain assignment to it) to be flagged as an
error. That's because *even if* f isn't technically used without
assignment, it still indicates that somebody didn't think their shit
through and may already be hiding a bug (in which case they're damnned
lucky it's a float instead of an int) - and even if not, then it's
still too damn fragile anyway and *will* likely wind up creating a bug
once someone goes and touches that code.

FWIW, Last time we debated this on the NG, this was the point where
Walter got stuck on the irrelevant "But it's not garbage-inited like C!"
strawman. I hope we can do better this time.



More information about the Digitalmars-d-announce mailing list