No "side effect" assignment!

Martin Maney maney at pobox.com
Thu Sep 18 01:23:45 EDT 2003


Sean Ross <sross at connectmail.carleton.ca> wrote:
> If you must use assignments in expressions, you might find the following
> recipes useful:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/202234

Did I forget about this one or is it in fact new?  It is, as the author
says, an ugly hack at the implementation level, but that seems to be
its only drawback.  It doesn't use any hidden state that could be
altered unexpectedly, and is only a minor eyesore; those who worry
about accidentally writing an assignment in place of an equality test
will consider that last to be a feature, of course.  Perhaps it could
be improved, slightly, by being renamed to "let"?  <evil grin>

> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66061

The hope of obliterating this recipie is IMO the strongest argument in
favor of adding operator= to Python.  I can think of no reason to
prefer this to 202234 aside from the chance that the language
implementation detail used in the latter's implementation could
conceivably go away someday.

Short form: 66061 Considered Harmful.  What, you thought it was just a
coincidence it had all those sixes in its number?

-- 
People make secure systems insecure because
insecure systems do what people want and
secure systems don't.  -- James Grimmelmann




More information about the Python-list mailing list