On Sun, 20 Jul 2003 03:33:43 +0900, Ben Giddings wrote: > On Saturday, July 19, 2003, at 02:11 PM, Mark J. Reed wrote: >> However, to address the specific example, I would just use >> each_with_index: >> >> > Right, but my point was that I didn't really want to touch the iterator > because the index part was just a temporary hack to get some debugging > info. The goal was to change the code in such a way that when I found > the source of the problem I could nuke a few lines and the code would be > the same as before. Aside from the ease of "ctrl-k" or "dd" (depending > on your editor), it also makes it easier to spot the change if you do a > diff against the original. > > It was a weak attempt to come up with a situation where x += 1 was > useful. > Any other times when it is handy? I use iterators all the time, but I > also find myself using x += 1 all the time (though offhand I don't > remember when). > > I'm on the fence about x++. I use it all the time in other languages, > and it would save some keystrokes when I wanted to do the equivalent > thing in Ruby. I agree it could cause problems if someone tried to do > 0xDEAD++, but 1) it should be easy to write a parser to catch that and > 2) someone who does that is really odd and deserves whatever they get. > On the other hand, right now if you are modifying an object, the method > either has an equal sign in it, or has a bang in it. This would be yet > another special case. Maybe instead Fixnum should have a #succ! method? > > Ben Fixnum#succ! has come up before. Do a google groups search on it. Personally I don't use x++ even in C. My reason? Changing the value of a variable is important enough that we should spend some visual weight on it, and x++ doesn't deliver as much impact in code as x += 1. (I think of it as having more pixels, or ink.) There's only one place I use x++, and that's in the 3rd expression in a for statement. It's a common C idiom and doing anything different would be confusing. As for the pre-increment and both flavors of decrement, forget it. The pre- and post-increment/decrement operators are only there because the machines on which C originally ran had INC and DEC machine instructions and it was easy to get the compiler to generate them. They're a remnant of the old days.