POV-Ray : Newsgroups : povray.off-topic : Smart little programming tricks, where to find ? : Re: Smart little programming tricks, where to find ? Server Time
11 Oct 2024 01:23:26 EDT (-0400)
  Re: Smart little programming tricks, where to find ?  
From: Mike Raiford
Date: 20 Mar 2008 06:42:29
Message: <47e24da5@news.povray.org>
Warp wrote:

> 
>   The form you suggest becomes a bit counter-productive when the expression
> is not a pure "between x and y", like for example:
> 
> if(10 < money*money && money*12 < 100)
> 
>   Now it becomes much harder to understand quickly what's going on.
> 

Right, and I don't think I'd dare use that form for a set of comparisons 
like that. But for simple ranges, it makes sense.

> 
>   In most cases the compiler will issue a warning anyways if you make
> the mistake. Never been a problem to me.
> 

Until you're working on some project where someone has set the Warning 
level so low that there are no warnings. (I have run into that, and 
setting the warning level any higher scared me ... so many warnings...)

>> My favorite syntactical bug was the following:
> 
>> for(int i = 0; i < cItems; i++);
>> {
>>     ... Block of code ...
>> }
> 
>> It's subtle, and if your for loops are any more complex than the above 
>> trivial example, results in headaches. I spent an hour tracking 
>> something similar down in my early days.
> 
>   If the loop of the body uses 'i' (as is rather usual) you'll get a
> compiler error.
> 

Without opening the argument on MS compiler vs a truly ANSI compliant 
compiler, that is not the case with Visual C++. It happily compiles the 
code because i is still declared after the for loop.

(I dislike this sort of behavior, and IIRC, they fixed it in more recent 
versions, but have an option to keep it compatible with code written in 
older versions)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.