assignment expression peeve

Carl Banks imbosol at aerojockey.invalid
Wed Oct 15 16:26:02 EDT 2003


Paul Rubin wrote:
> Carl Banks <imbosol at aerojockey.invalid> writes:
>> The designers of Python believe that assignment expressions are bad
>> news 
> 
> I'm not sure you're correct about that.  The impression I've gotten
> when this subject has come up before is designers are terrified of
> someone saying
> 
>   if x = y:
> 
> when they meant ==, and causing a nuclear meltdown or something.
> Using a different operator like "x := y", avoids that problem which is
> why I did it that way in the example I gave.  However, with that
> problem removed, it's still not considered a done deal.

With my apologies for sounding a little edgy in the first post, I
think this is only only a minor reason why Python has no assignment
expressions.

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.  Things that work as
expressions in computer code are uttered as nouns, or noun phrases, in
natural languages.  Assignments, however, are not uttered as nouns,
but as imperatives, and therefore are inappropraite as expressions.

Assignment expressions are bad news, I think, and I think the designers
think, because it goes against the grain of natural language, and is
thus counterintuitive, and leads to code that takes a lot of effort to
read and understand.


>> (which I agree with),
> 
> Well, that's your opinion.

I've given some linguistic evidence why it's ugly and
counterintuitive.  Take it as you will.


>> and they will NEVER make assigments into expressions just to avoid
>> this little problem.
> 
> 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.


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