From: Josh Cheek Date: 2010-02-14T12:48:26+09:00 Subject: Re: Why no ++ and --? --000e0cd2928031b4af047f875ff0 Content-Type: text/plain; charset=ISO-8859-1 They just plain don't mean the same thing: In C++, outputs "ref1 = 6 , ref2 = 6" Because ++ changes the underlying object, and they both referencing that object. #include "iostream" int main( ) { int actual=5 , &ref1=actual , &ref2=ref1; ++ref1; std::cout << "ref1 = " << ref1 << ", ref2 = " << ref2 << std::endl; return 0; } In C, outputs "*ptr1 = 6 , *ptr2 = 6" For the same reason as above, We increment the value that ptr1 is pointing at, since ptr2 is pointing to the same place, it gets updated also #include "stdio.h" int main(){ int actual=5 , *ptr1=&actual , *ptr2=ptr1; ++*ptr1; printf( "*ptr1 = %d , *ptr2 = %d\n" , *ptr1 , *ptr2 ); return 0; } In Ruby, outputs "ref1 = 6 , ref2 = 5" Because += creates a new object, and updates one of the references to point to the new place in memory, but the second reference is still pointing to the old number. actual=5 ; ref1=actual ; ref2=ref1 ref1 += 1 puts "ref1 = #{ref1} , ref2 = #{ref2}" Numbers are immutable in Ruby, so you cannot increment a number that the object represents, you can only get a new object containing the next number. And anything referring to the original number will not be updated, that original number still exists. So where do you compromise? Does ref1++ translate directly to ref1+=1 which would give it very different meaning than in the languages the people making the requests are coming from, or do you make numbers mutable, which would present other issues that these people would dislike (ie making numbers immutable allows them to mimic the behaviour of pass by value, but now they would either have to explicitly duplicate the number before passing it, or they would have to deal with the possibility of the function they are calling having the ability to change it, or some sort of magic such as checking params and duping them before letting them in) I think that people who ask for ++ really don't understand what they are asking for, and think it is just a simple syntactic difference. I also think you can trash a beautiful language by giving in to every half-understood request for exceptional changes, so I'm very much against adding this, my brain can only remember so many exceptions to the rules. --000e0cd2928031b4af047f875ff0--