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:
Post a Comment