Disclaimer

The content of this blog is my personal opinion only. Although I am an employee - currently of Imagination Technologies's MIPS group, in the past of other companies such as Intellectual Ventures, Intel, AMD, Motorola, and Gould - I reveal this only so that the reader may account for any possible bias I may have towards my employer's products. The statements I make here in no way represent my employer's position, nor am I authorized to speak on behalf of my employer. In fact, this posting may not even represent my personal opinion, since occasionally I play devil's advocate.

See http://docs.google.com/View?id=dcxddbtr_23cg5thdfj for photo credits.

Wednesday, May 11, 2016

1 PEP 308: Conditional Expressions

1 PEP 308: Conditional Expressions:  x = true_value if condition else false_value"



I am vindicated!!!!



Or at least I am following in Guido's footsteps without noticing it.



More and more, I have been using  R := A if Cond else C

in pseudocode, etc., because it reads better than

R:= if Cond then A else B



Python does the same.





I must admit, however, that I wish that both versions were available - it depends on whether you want to emphasize the condition of the value.



For multiway if expressions



R := if C1 then V1 elsif C2 then V2 elsif ... else Ve



looks better than



R := V1 if C1 elsif C2 then V2 elsif ... else Ve



although I think that both have value, again, depending on whether you want to emphasize the condition or the value.



Also, often the conditions are error conditions, and the primary condition is the negation of all the rare error conditions:



R := if rareC1 then rareC2 
        elsif rareC2 then rareV2 
        elsif ... 
        else Most_Common_V_Else

This is the equivalent of putting the default case at the top of a switch statement.

Can we come up with a syntax that allows this?

R := Most_Common_V_Else
        if rareC1 then rareC2 
        elsif rareC2 then rareV2 
        elsif ... 
        else /*no value?*/

R := Most_Common_V_Else
        if none of the following (
           if rareC1 then rareC2 
           elsif rareC2 then rareV2 
           elsif ... 
           /* bit no else */
        )


 








'via Blog this'

No comments: