Defending the ternary operator

Paul Paterson hamonlypaulpaterson at houston.rr.com
Mon Feb 10 05:48:28 CET 2003


"Dennis Lee Bieber" <wlfraed at ix.netcom.com> wrote in message
news:bqbjh-nj3.ln1 at beastie.ix.netcom.com...
> Paul Paterson fed this fish to the penguins on Saturday 08 February
> 2003 05:14 pm:
>
>
> > structure finds 769 matches of the following pattern,
> >
> >     if <something>
> >         variable = <some value>
> >     else:
> >         variable = <some other value>
> >
> > in 381209 lines of code. I leave the statistical interpretation to the
> > reader.
>
>         Ah, but perhaps the better statistic would be to also know how
many
>
>         if <something>:
>                 <do something>
>         else:
>                 <do something else>
>
> appear in the code referenced. If your 769 were 50% of the total
> if/else code, then a conditional might be a desirable feature. If 5%
> then it probably doesn't gain enough to justify adding it.
>
>         Oh, what about?
>
>         if <s1>:
>                 v = <some1>
>         elif <s2>:
>                 v = <some2>
>         elif...
>                 v = <some...>
>         else:
>                 v = <else>
>
>         A conditional expression won't replace that (though unless each
> <somen> is a dynamic equation, a list/dictionary look-up is likely
> better).
>

A minor modification could find both these statistics. The code is here,

http://groups.google.com/groups?selm=xXh1a.5331%24yn1.486089%40twister.austi
n.rr.com&oe=UTF-8&output=gplain








More information about the Python-list mailing list