[Python-Dev] C.E.R. Thoughts
Nick Coghlan
ncoghlan at gmail.com
Tue Oct 11 12:14:46 CEST 2005
jamesr wrote:
> Congragulations heartily given. I missed the ternary op in c... Way to
> go! clean and easy and now i can do:
>
> if ((sys.argv[1] =='debug') if len(sys.argv) > 1 else False):
> pass
>
> and check variables IF AND ONLY if they exist, in a single line!
>
> but y'all knew that..
Yep, it was a conscious decision to add a construct with the *potential* to be
abused for use in places where the existing "and" and "or" expressions *are*
being abused and resulting in buggy code.
The code in your example is lousy because it's unreadable (and there are far
more readable alternatives like a simple short-circuiting usage of "and"), but
at least it's semantically correct (whereas the same can't be said for the
current abuse of "and" and "or").
If code using a conditional expression is unclear, blame the programmer for
choosing to write the code, don't blame the existence of the conditional
expression :)
We're-all-adults-here-ly yours,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.blogspot.com
More information about the Python-Dev
mailing list