assignment expression peeve

Paul Rubin http
Wed Oct 15 16:42:52 EDT 2003


Carl Banks <imbosol at aerojockey.invalid> writes:
> The real reason is that assignment expressions lead to all kinds of
> ugly and unreadable code.  This is because there is no linguistic
> analogue for assignment as an expression.

Swell, tell me the linguistic analog for metaclasses.  Or should those
be removed too?

> > Well, that's your opinion.
> 
> I've given some linguistic evidence why it's ugly and
> counterintuitive.  Take it as you will.

Well, that's also your opinion.  Programmers have been using
assignment expressions in Lisp (and more recently C) for over 40 years
now and it's been working ok for them.  Anything programming construct
can be ugly and counterintuitive if used untastefully.  The idea is to
apply good judgement when using assignment expressions or anything
else.  That way you can get code that's both beautiful and intuitive,
even if you use assignment expressions.

> > There's no way to know that, without first waiting til the end of "never".
> 
> Well, an evil alien can possess Guido's body, and declare that Python
> will add assignment expressions--and then do it tactfully enough that
> the masses won't rise against the BDFL.  You're right, I'd have to
> wait until never ends to know that won't happen.  Barring that though,
> I can pretty much assure you that this will NEVER change.

Well, to be more specific, I don't get any sense from Guido's or Tim's
posts that it will never change.  I do get the sense that a strong
enough case for changing it has not yet been made, and so it hasn't
changed thus far.  I also get the sense that "if x=y: ..." will never
be allowed because of the possible confusion between = and ==.  That
leaves the possibility open for some adding different assignment
operator or function someday, if there's a strong argument for adding
it.  The regexp example I gave was a case that comes up over and over,
and it turns out Alex even has a workaround in the Python Cookbook for
dealing with it.  But it seems to me like the tried and true solution
(in other languages) is assignment expressions, so my post aimed to
point out a common Python situation where they'd be useful.




More information about the Python-list mailing list