POV-Ray : Newsgroups : povray.off-topic : Smart little programming tricks, where to find ? : Re: Smart little programming tricks, where to find ? Server Time
10 Oct 2024 23:21:05 EDT (-0400)
  Re: Smart little programming tricks, where to find ?  
From: Mike Raiford
Date: 19 Mar 2008 06:42:51
Message: <47e0fc3b$1@news.povray.org>
Warp wrote:

> 
>     0 < money
> 

Where that really comes into play is range statements:

if(10 < money && money < 100)
{
  ...
}

which can be read as "if money is between 10 and 100"

Someone I used to work with insisted that you use the same direction in 
comparisons if you had more than 1 comparison. It seemed to make sense 
when he used this example. The equivalent (and probably the way most 
people are familiar with handling ranges) "money > 10 && money < 100" 
isn't as quick to parse what you're looking for. Using that sort of 
statement with a single comparison seems a bit ridiculous to me, though.

I have seen and used the [Constant|Literal] == [Variable] syntax before, 
it's good for preventing assignment where you meant equality bugs. Of 
course, the problem becomes obvious when you begin debugging seemingly 
bizarre behavior. But, the objective is to prevent such behavior in the 
first place.

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.


Post a reply to this message

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