PEP 308: Obfuscated Nested Ternaries (Not)
David Eppstein
eppstein at ics.uci.edu
Thu Feb 20 11:36:10 EST 2003
In article <MvudncQKAr1OasmjXTWcrg at comcast.com>,
"Terry Reedy" <tjreedy at udel.edu> wrote:
> Instead, I will rewrite so more clear than original.
>
> seq = (
> x > 0 ?
> y > 0 ? (tl, br, b, br, r, br) :
> y==0 ? (l, r, t, r, b, r) :
> (bl, tr, t, tr, r, tr) :
> x==0 ?
> y > 0 ? (t, b, l, b, r, b) :
> y==0 ? (tl, tr, br, bl, tl) :
> (b, t, l, t, r, t) :
> # x < 0
> y > 0 ? (tr, bl, b, bl, l, bl) :
> y==0 ? (r, l, t, l, b, l) :
> (br, tl, t, tl, l, tl)
> )
This goes completely against the Python philosophy that whitespace
should be used to define the structure. It would be very easy to
reindent this to make it look like it did something other than what it
really did. For this reason I prefer using if-elif-else statements to
ternary expressions for anything this big.
--
David Eppstein UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
More information about the Python-list
mailing list