On Mon, Feb 19, 2001 at 05:31:07PM +0100, Jesper Skov wrote:
> >>>>> "Sam" == Sam TH <[EMAIL PROTECTED]> writes:
> 
> Sam> Instead of assigning, we were comparing.  Bad.  Changed a
> Sam> potentially bad comparison to an assignment.  That could have
> Sam> been a hard-to-find bug. :)
> 
> Surely the compiler should have been bitching about expression without
> side effect. We use -Wall on GCC. It's usually quite good at catching
> something like that.

The compiler was complaining, which was how I found it.  But if you
were looking for that bug, it would have been harder to find.  

> 
> As for assignments which should have been comparisons, I'd like to
> advocate a defensive programming style:
> 
> Instead of:
> 
>   (foo == CONST_OF_ONE_FORM_OR_ANOTHER)
> 
> use:
> 
>   (CONST_OF_ONE_FORM_OR_ANOTHER == foo)
>  
> Then you'll get a compiler error if you accidently forget one of the
> equal characters.

We already do this in lots of places, and where we don't, we should.  
           
        sam th               
        [EMAIL PROTECTED]
        http://www.abisource.com/~sam/
        GnuPG Key:  
        http://www.abisource.com/~sam/key

PGP signature

Reply via email to