POV-Ray : Newsgroups : povray.off-topic : Programming style question - specifically Python : Re: Programming style question - specifically Python Server Time
29 Jul 2024 20:24:10 EDT (-0400)
  Re: Programming style question - specifically Python  
From: Darren New
Date: 27 Aug 2011 16:34:42
Message: <4e5954e2@news.povray.org>
On 8/27/2011 7:14, Warp wrote:
>    bool_a is not being assigned to bool_b. The result of the expression
> "something&&  something_else" is being assigned to bool_b.
>
>    I don't even understand what is it that you don't like about this.

If bool_a is false, then bool_a is being assigned to bool_b. This implies in 
a vague sense that bool_b is false when bool_a is false. In reality, bool_b 
is *undefined* when bool_a is false. One assigns it "false" not because 
bool_a is false, but because one must assign something in that statement, 
and it doesn't matter what gets assigned.

In other words, in a language that supported tri-value logic (like PHP, 
perhaps), I'd say
   bool_b = bool_a ? min(...) : undefined
to make it clear.

>    It may be *common* for the result to be discarded, but it's perfectly
> possible to take the result into account for subsequent decisions. The
> advantage of using a sequence of commands separated by&&  is that you
> don't need to put an 'if' after each of the commands, if you want to
> react to one of them failing. You only need to use one 'if' to catch any
> of them failing.

Sure. And if the person wrote
   bool_a = big_long_expression_one(alpha,beta,gamma)
   bool_b = big_long_expression_one(alpha,beta,gamma) && min(...)
then I would agree that would be the right expression.

Again, it's a matter of taste. Written with the boolean, I'd have to stop 
and look at the rest of the code to see if, for example, there's a
    bool_b == bool_a
kind of expression somewhere later to try to understand what the bools meant.

Of course, picking better names for the bools would obviate the entire 
debate. :-)

-- 
Darren New, San Diego CA, USA (PST)
   How come I never get only one kudo?


Post a reply to this message

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