POV-Ray : Newsgroups : povray.beta-test : Radiosity Status: Giving Up... : Re: Radiosity Status: Giving Up... Server Time
29 Jul 2024 02:23:29 EDT (-0400)
  Re: Radiosity Status: Giving Up...  
From: Warp
Date: 30 Dec 2008 11:04:33
Message: <495a4691@news.povray.org>
Daniel Nilsson <pov### [at] daniel-nilssoncom> wrote:
> The thing to learn from this, and it's my experience from work too, is 
> that you should write code that is easy to read and maintain rather than 
> try to be clever with optimizations.

  IMO this:

    variable = someLengthyCalculation;
    useVariable(variable);
    useVariableForSomethingElse(variable);

is more readable than:

    useVariable(someLengthCalculation);
    useVariableForSomethingElse(someLengthCalculation);

especially if "someLengtyCalculation" is even a bit complicated. (Basically
the variable makes it very clear that the two expressions are, in fact, the
one and same, something which might not be visually obvious if the expression
is repeated.)

  As a bonus, you'll make absolutely sure the compiler won't calculate
it twice. (In some cases it might be that the compiler is forced to
calculate it twice because it can't know if some called function has
side-effects.)

-- 
                                                          - Warp


Post a reply to this message

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