assignment expression peeve

Donn Cave donn at drizzle.com
Thu Oct 16 02:12:13 EDT 2003


Quoth Paul Rubin <http://phr.cx@NOSPAM.invalid>:
| Carl Banks <imbosol at aerojockey.invalid> writes:
|> Again, apples and oranges.  You are comparing meanings, when the
|> problem is syntax.  "A guy named Bob walks into a bar" and
|> "bar.enter(bob := Guy())" might have the same meaning, but they use a
|> diffenent syntax to convey it.  And the latter uses a syntax with no
|> analogue in any natural language I know of.
|
| Whatever.  You're the only programmer I've ever encountered who claims
| to have actual trouble understanding assignment expressions.  With
| other people, the objection is that they can be confused with
| comparison expressions, or that they're simply another
| not-so-important feature that Python doesn't need.

They are an impediment to understanding, says the second programmer.

If there were some way to support the functionality you wanted
there, and ONLY as represented in your example, then the impediment
would not be a severe one, and the only question would be whether
such a trivial gain is worth the bother.  I think the class wrapper
work-arounds, as proposed in your initial post and one or two
follow-ups, are better, so it's no gain at all in my eye.

But when you can say

  if g := match(a, b):

then I suspect you will also be able to say things like -

  if not (dv := start() and f := nfile(dv)
          and ((t := f.find("--") > 0 and fx = f[:t]) or (fx = f))):
     print "Well, bless me!"

Of course no one would do such a thing.  I translated this from C code
written by someone who is a far more accomplished programmer than I,
whose name I know you would recognize.  (Identifiers etc. changed to
protect the not-entirely-innocent.)

	Donn Cave, donn at drizzle.com




More information about the Python-list mailing list