inline assignments in conditionals

John Roth johnroth at ameritech.net
Sat Apr 27 20:15:25 EDT 2002


"Michael Gilfix" <mgilfix at eecs.tufts.edu> wrote in message
news:mailman.1019937169.5421.python-list at python.org...
> On Sat, Apr 27 @ 12:33, jaf wrote:
> > Writing things that way is really unnatural, at least for English
> > speakers.  It makes the intent of the code harder to understand (at
> > least for me).  For example, if you were talking to a friend, you
> > woudn't say:
> >
> >    "If today is Sunday, I'm going to go shopping"
> >
> > but rather:
> >
> >    "If Sunday is today, I'm going to go shopping"
> >
> > and in any case, writing the constant first only protects in the
case
> > where one of the compared values is a constant.  If you are doing
> >
> >    if (a == b):
> >
> > then there is no way to protect yourself against actually writing
'='.

Unnatural and partial as it is, it is a recommended best
practice to protect yourself from accidentally writing '='
when you meant '==' in C or C++.

I don't have any objection to implementing assignment
in expressions. I have a real objection to doing it in such
a way that it makes silly mistakes easier, however.

John Roth





More information about the Python-list mailing list