[Python-ideas] except expression

spir denis.spir at gmail.com
Thu Feb 13 13:07:51 CET 2014


On 02/13/2014 12:48 PM, Chris Angelico wrote:
On Thu, Feb 13, 2014 at 10:25 PM, spir <denis.spir at gmail.com> wrote:
> > [By the way, this shows that:
> >         x = b if cond else a
> > should really be:
> >         x = a else b if cond
> > The difference being that the standard case is expressed first, the
> > exceptional one being then introduced as an special variant.]
>
> My example tends to agree with you... but my example is using "if" to
> introduce the abnormal case, whereas it's common to spell a block if
> the other way:
>
> if normal-case:
>      code code code
> else:
>      abnormal code

I rather write code the the other way round, with the condition determinig the 
special case. This also matches the common idom:
    if special-case:
        deal-with-it
        return [result]
    deal-with-normal-case	# no else needed

Generally, I think logical vars should be 'false' by default, expressing the 
standard/rest/off state, with 'true' meaning something new or activated ('on'), 
or otherwise special.

> C's ternary operator puts the expressions in the order "condition,
> if_true, if_false". Python's puts them "if_true, condition, if_false".
> You're proposing "if_false, if_true, condition".

That's because I think (1) the standard value should come first (2) the 
condition should express the special case instead.

>  We're half way to
> covering all the permutations!

;-)

Actually, the ideal order for me would be:
     if_false, condition, if_true
in the sense of
     normal_value, special_condition, special_value
but this does not match the meaning of natural language preposition (here, 'if').

d


More information about the Python-ideas mailing list