Suggesting for overloading the assign operator
LogiplexSoftware at earthlink.net
Tue Jul 1 23:50:05 CEST 2003
On Mon, 2003-06-30 at 20:31, Rim wrote:
> The idea is to separate the value assignment from the type assignment,
> by introducing a new operator, let's say the ':=' operator.
> '=' remains what it is, assigns type and value at the same time
> ':=' assigns only the value
On the surface, this idea seems appealing. However, besides the
arguments that others have forwarded, you might consider the fact that
given two similar "assignment operators", subtle bugs are bound to
> >>> class myint(int): pass
> >>> a = myint()
> >>> a := 6
> <class '__main__.myint'>
> >>> a
What if the programmer accidentally uses '=' rather than ':=' (and I
think this would be a natural mistake)? It would be legal Python but
would probably not have the intended effect. It is not unlike the
"allow assignment in expressions" arguments that come up here every 3.2
Anyway, your arguments cancel themselves out. You asked initially for a
way to overload '=' because your users didn't want to have to type
something different. But ':=' *is* different, so what are you really
looking for?. Worse, because ':=' isn't *very* different, it makes
mistakes more likely.
In short, I think using a = myint(6) or even a.value = 6 is preferable.
Besides, when I used Pascal (many years ago), I found ':=' to be one of
the most annoying (and most common) things I had to type. Please don't
ask to bring it back.
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 (800) 735-0555
More information about the Python-list