Curious assignment behaviour

John Roth johnroth at ameritech.net
Wed Oct 10 17:25:01 CEST 2001


"Paul Rubin" <phr-n2001d at nightsong.com> wrote in message
news:7x669o7r4k.fsf at ruckus.brouhaha.com...
> "John Roth" <johnroth at ameritech.net> writes:
> > However, I think := makes a good choice for an expression assignment
> > operator. It needs to be different from both the statement assignment
> > operator and the equality operator. It also can't be in use for an
> > extended assignment.
>
> Why on earth does it have to be different from the statement assignment
> operator?  What's wrong with
>
>   while x=get_next(): whatever(x)
>
> I just don't buy the rationale that using = instead of == is a big source
> of bugs.  In 25 years of hacking C code, I think I've seen that error
> maybe once or twice.

You're obviously a much more meticulous programmer than I am,
or than most of the programmers I work with are. That's to your
credit.

However, I've seen that bug many times in lots less code. That may
say something about the lack of quality assurance in the areas I work
in, and you'd be right.

For the rest of the commentary, see Tim Peters' note on another branch
of this thread. I agree completely with the error causing potential of
having the same symbol for assignment and comparison; that's been
noted as early as the Algol 60 compiler, which used := for assignment,
and = for comparison.

A large part of the target audience for languages like Python are not
professional programmers, in the sense that they do programming on a
daily basis. They are professional system administrators, or professionals
in other fields, and do programming as only part of their job or
avocation. A language that makes it difficult to make the more obvious
mistakes, and that doesn't get in the way if you really want to do something
that may turn out to be a real mistake, is ideal for them.

John Roth





More information about the Python-list mailing list