ternary operator

Andrew Koenig ark at research.att.com
Fri Feb 7 17:28:44 EST 2003


David> I think you missed the point twice: it's not about indexing,
David> it's about calling a function whose side effects you depend on
David> (always) in a component of an expression that might not get
David> evaluated.

I didn't miss that point.

I think there are two cases that are often confused with each other:

  1) Calling a function with side effects that you depend on;

  2) Using one expression to guard another--that is, evaluating
     one expression to determine whether another is meaningful
     before evaluating it.

In general, I think that the first case makes programs harder to
follow, and the second case makes them easier.  Of course, there
will always be exceptions, but I think this is true in general.

The difference is that in case (1), the side effects happen somewhere
else (otherwise they wouldn't be side effects), whereas in case 2,
the parts of the computation contribute to the results of the expression
and nothing else.






More information about the Python-list mailing list