From: Gavin Sinclair Date: 2002-11-26T09:32:44+09:00 Subject: Re: Things That Newcomers to Ruby Should Know (11/24/02) From: "Daniel Carrera" > > > And given that the concept of 'x++' is very rarely needed in a Ruby program, > > having iterators instead of for-loops, those extra three characters are > > actually a very small percentage, amortised over the entire program. > > Regardless, is there a reason *not* to have '++'? > It's the kind of shortcut that many programmers expect and I just can't > think of any reason not to have it. Following the principle of Least > Surprise, I'd expect to find this feature, unless there is a good reason > to avoid it. > > Daniel. In other languages, ++/-- is a lot more than just 'x = x + 1'. It's the pre-/post- increment/decrement operator. That is: int x[] = [5,6,7,8,9]; int a = 1; x[++a]; // -> 7; a == 2 x[a++]; // -> 7; a == 3 x[a]; // -> 8; a == 3 Ruby can't/won't replicate this behaviour, so swiping the operators would mislead. I don't know what a[x += 1] does in Ruby, and I'm not going to ask. Gavin