assignment expression peeve

Carl Banks imbosol at aerojockey.invalid
Wed Oct 15 17:49:32 EDT 2003


Paul Rubin wrote:
> 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?

Paragraph that defines some of its own words?

Seriously, you're comparing apples to oranges here.  I'm comparing
syntax here, and there's nothing syntactical about metaclasses.  If
you want to compare a class statement to natural language, that works.
Metaclasses don't have syntax, regular classes don't have syntax.
Class statements do.

And class statement certainly does have an analogue in natural
language.  If you have ever uttered an itemized list, then you've used
the natural language analogue of a class statement.


>> > 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.

I say C would be better off without them.  Lisp probably would too,
although I can believe that, because Lisp is into that "design your
own language" thing, assignment expressions might be an evil worth
having in the language.  But maybe not even then.


> 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.

Yeah, yeah, yeah.  Some things are easier to abuse than others, and I
find assignment expressions to be one of the most often and most
easily abused contructs in the C language.  It would certainly happen
in Python, too.

And frankly, I say nothing involving an assignment expression is every
beautiful or intuitive.  My opinion on the beauty part.  The intuitive
part is supported by the linguistic evidence I gave you.


>> > 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.

Because one doesn't exist.  The little idiom you're complaining about
is the strongest case for it, and that's a VERY WEAK case.  And there
are other solutions that don't fuck up the rest of the language.


[snip]
> 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.

It's not the tried and true solution.  It's the hackish solution that
takes advantage of a mistake in the language.  There are other ways to
solve this relatively minor problem.

Consider Perl.  This problem never happens in Perl, but guess
what--it's not because Perl has assignment experssions!!!  Perl
manages to handle this idiom perfectly well without assignment
expressions.

The real problem is that this idiom is awkward in Python.  It's not
necessary to add assignment expressions to the language to fix this.


-- 
CARL BANKS                   http://www.aerojockey.com/software

As the newest Lady Turnpot descended into the kitchen wrapped only in
her celery-green dressing gown, her creamy bosom rising and falling
like a temperamental souffle, her tart mouth pursed in distaste, the
sous-chef whispered to the scullery boy, "I don't know what to make of
her." 
          --Laurel Fortuner, Montendre, France 
            1992 Bulwer-Lytton Fiction Contest Winner




More information about the Python-list mailing list