From: Robert Dober Date: 2008-08-29T22:40:57+09:00 Subject: Re: Please don't flame me...why is there no "++" in Ruby again ? On Fri, Aug 29, 2008 at 10:10 AM, Lars Christensen wrote: > I think the OP deserves the fuller explanation; You are right, but I did after realising my error ;). AAMOF it has *nothing* to do with the immutability of integers. OP asked for syntactic sugar. > Why are integers > immutable? Consider this: > > a = 2 > b = a > a++ > > Since everything is an object, 'a' references the object '2' and b > should reference it too after the assignment. Then 'a++' should > increment the object referenced by both a and b? This would of course > be possible, but it would be a rather huge performance penalty to keep > something as simple as integers as references to objects everywhere. > > Ruby keeps 'small-enough' integers in the object reference (pointer) > to improve performance. Hence 'b = a' results in an actual copy being > taken of the value '2'. If you increment 'b', 'a' would retain its old > value, breaking the concept that a variable is always just a > reference. Ruby opts for immutable Integers instead. > Nevertheless all you said makes perfect sense of course. R.