Hi --

On Sat, 12 Oct 2002, Kontra, Gergely wrote:

> >3) 'x+=b', 'x*=b' and other assignment operators is internally translated
> >into 'x=x+b' and so on, so these operators assign to x reference to
> >newly created object
>
> If this is true, a+=1 creates a new object. Can't it be avoided?

In the case of numbers, it doesn't create a new object, because
numbers are only instantiated once (if that's the right way to put
it), as well as immutable.  (You can't do 3 << 1 etc.)

So when you do:

  a = 3
  a += 1

the only thing it can mean is:  a = a+1

With other things, e.g. Strings, += does create a new object.  I think
the reasoning is: since += has to behave like an assignment for
numbers, it should do so consistently.  This means that the "creates a
new object" part is not consistent, but it really can't be anyway.


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav