From: Jakub Travnik Date: 2001-11-25T23:44:30+09:00 Subject: [ruby-talk:26450] Re: ++operator and sorted hashes Willi Kappler wrote: > Hi list, > > I'm new to ruby ( using 1.6.5 ) and comming from c++. The language is really great > and easy to learn. But there are some things that would be fine > if they were implemented: > > Is there a certain reason why the ++operator is not implemented ? > In c/c++: a=5; a++; > In ruby: a=5; a+=1 In Ruby everthing is object, a++ means add one in C. What this should mean for String? for Regexp? for Your own class? It does not have usefull object semantic. However a+=something is ok: a=10;a+=1 a='Hello'; a+=' world' a=MyClass.new; a+=MyClass.new (if MyClass have instance method + defined) > An other really usefull object is hash ( map in c++ stl ) > In c++ maps are sorted, in ruby there is a sort function, but it > returns an array. I thought that c++ uses sorted maps for speedup > reasons, so there must be an other reason why ruby doesn't sort them ? It is a implementation reason. there are some links that might explain more about hash tables: http://www.nist.gov/dads/HTML/hashtab.html http://www.wikipedia.com/wiki/Hash_table Jakub Travnik jabber://jtra@jabber.com ICQ: 66770334 (deprecated)