From: Guillaume Cottenceau Date: 2001-08-24T04:46:32+09:00 Subject: [ruby-talk:20203] Re: ++ Operator Hi ! matz@ruby-lang.org (Yukihiro Matsumoto) writes: > Hi, > > In message "[ruby-talk:20191] Re: ++ Operator" > on 01/08/24, Guillaume Cottenceau writes: > > |Yet, from the "parsing" point of view (excuse the potential improper use > |of this term), if `counter += 1' is effectively shorthand for `counter = > |counter + 1', why `counter ++' could not be shortand for `counter += 1'? > | > |If this is done early enough in the code, I think this should be possible? > > It's possible. But do you think this is what you really want? > Think about "a++", where a = "foo" for example. I think it's > confusing, rather than useful. Maybe I just don't see the future problems, but I think it would not be very confusing. It would try to "increment" the object behind the variable. It would fail just as it currently fails, on a String: irb(main):001:0> a = "foo" "foo" irb(main):002:0> a += 1 TypeError: failed to convert Fixnum into String from (irb):2:in `+' from (irb):2 irb(main):003:0> The ++ would also fail.... unless you would imagine it should succeed for some reason ? If the "++" is just converted to "+= 1" ok it would fail for the same reason, but I imagine you would like that the "++" behaves differently among objects because some of them could be "incremented" while not "added the Fixnum `1'". In my opinion, I would not be shocked if it would simply convert to +=1 and then fail for relevant reason for most objects. The only moment where I miss the "++" is actually when I need to increment a Number... Writing "a += 1" is just.. depressing.. ;p. -- Guillaume Cottenceau - http://people.mandrakesoft.com/~gc/