Postfix/Prefix Operators (++,--)

sismex01 at hebmex.com sismex01 at hebmex.com
Fri Jun 6 11:41:56 EDT 2003


> From: Peter Hansen [mailto:peter at engcorp.com]
> Sent: Friday, June 06, 2003 10:36 AM
> 
> Joshua Marshall wrote:
> > 
> > Peter Hansen <peter at engcorp.com> wrote:
> > ...
> > 
> > > Secondly, in Python assignment actually *rebinds* a name to a new
> > > object, so i = i + 1 creates a new object that is one greater than
> > > the old, and rebinds the name "i" to it (like a pointer).  The old
> > > value, if there are no more references to it, is destroyed.
> > 
> > > This, combined with the fact that these integer objects 
> > > are actually *immutable* (they cannot be changed!) pretty
> > > much prevents any possibility of those operators working the
> > > way you'd expected.
> > 
> > ++/-- can be added to Python, and could act in a way that wouldn't
> > surprise C or Java programmers.  There really isn't any conceptual
> > difference between references to immutabe ints and C/Java primitive
> > ints.
> 
> How would the error generated when the C or Java programmer wrote 
> the following code not surprise him or her?
> 
>   c = 1
>   a = c++
>

There's plenty reasons why these operators will never be added
to Python, the most important is that most programmers think they're
equivalent in any case (decrement and increment, only), that is,
they think that "x++" is the same thing as "++x", which is
totally wrong.

As such, they are a veritable fountain of subtle bugs, which
are tough to diagnose.  These operations are supposed to map to
low-level register gimnastics on different CPUs, so that they
should be used accordingly to the machine's architecture.  So,
depending on the CPU, using these operators on expressions
such as "ch = *(c++)" can be more than twice as slow as "ch = *(++c)",
because of register gimnastics.

So...

They won't be added.  Python is not C, nor is it assembler.
Python commands a totally different style of development than
those other languages, so it's appropriate to use the tools
available.

This isn't a rant, or maybe, it's a tiny, mild, "it's friday
and I'm programming in VB and wish it was Python" kind of rant.
Python's very, very nice, smooth, predictable, consistent,
etc.  Adding these kind of operations to it will break all
that.  Better add intercal's "ON 50% GOTO label" operation,
or "PLEASE GOTO label".

:-/

-gca

--
Advertencia:La informacion contenida en este mensaje es confidencial y
restringida, por lo tanto esta destinada unicamente para el uso de la
persona arriba indicada, se le notifica que esta prohibida la difusion de
este mensaje. Si ha recibido este mensaje por error, o si hay problemas en
la transmision, favor de comunicarse con el remitente. Gracias.





More information about the Python-list mailing list