(no) fast boolean evaluation ?

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Fri Aug 3 11:57:30 EDT 2007


Steven D'Aprano a écrit :
> On Fri, 03 Aug 2007 10:20:59 +0200, Bruno Desthuilliers wrote:
> 
>> Joshua J. Kugler a écrit :
>>> On Thursday 02 August 2007 15:19, Evan Klitzke wrote:
>>>>> I discovered that boolean evaluation in Python is done "fast"
>>>>> (as soon as the condition is ok, the rest of the expression is ignored).
>>>> This is standard behavior in every language I've ever encountered.
>>> Then you've never programmed in VB (at least 6, don't know if .net still
>>> does this).  Nested IF statements. AAAAAAAAAAAAAAAAAAAACK! 
>> I do remember an even brain-deadiest language that not only didn't 
>> short-circuit boolean operators but also didn't have an "elif" statement...
> 
> 
> Is it a secret?
> 
> I'm a little perplexed at why you say a language without "elif" is a good
> sign of brain-death in a programming language. I understand that, given
> the parsing rules of Python, it is better to use elif than the equivalent:
> 
> if condition:
>     pass
> else:
>     if another_condition:
>         pass
> 
> 
> But that's specific to the syntax of the language. You could, if you
> choose, design a language where elif was unnecessary:
> 
> if condition:
>     pass
> else if another_condition:
>     pass
> 
> What advantage is there to "elif", apart from it needing three fewer
> characters to type?
> 

Sorry, I forgot to mention the language did not allow to have else & if 
in the same statement. IOW :

if some_condition then
   do_sometehing
else
   if some_other_condition then
     do_something_else
   else
     if yet_another_condition then
       do_yet_another_thing
     else
       if your_still_here then
          give_up('this language is definitively brain dead')
       end if
     end if
   end if
end if




More information about the Python-list mailing list