Michael Dudzik wrote:
Sure, but what about when you don't know the boolean value ahead of
time, like:

   C and f(x) or g(x)

   On the other hand, (g(x), f(x))[C] works every time

To be fair, both g(x) and f(x) are evaluated while

   f(x) if C else g(x)  # python 2.5, only evaluates the appropriate
   function.

Still, I mostly spoke up because if one starts to use an idiom like:

    python:C and 'somestring' or 'anotherstring'

you have to realize that

    python:C and '' or 'anotherstring'

will fail.  An idiom that breaks so easily doesn't seem so useful.

In 90% of cases you'll have a fixed value for the true case or the false case, and you'll know that one cannot evaluate to false, in which case you can choose to use:
  C and foo or bar
or
  not C and bar or foo
depending on whether foo or bar is potentially false.

In the remaining cases, you can use
  (C and [foo] or [bar])[0]
if it's important to have short-circuit semantics.

Florent

--
Florent Guillaume, Nuxeo (Paris, France)   Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   [EMAIL PROTECTED]
_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to