From: "David A. Black" Date: 2008-08-29T19:04:31+09:00 Subject: Re: Please don't flame me...why is there no "++" in Ruby again ? Hi -- On Fri, 29 Aug 2008, Robert Dober wrote: > On Fri, Aug 29, 2008 at 7:27 AM, David Masover wrote: >> On Thursday 28 August 2008 16:25:59 Joel VanderWerf wrote: >>> John Pritchard-williams wrote: >>>> I did check my Ruby books by the way, but they just "unlike C there is >>>> no ++ operator in Ruby...." :) >>> >>> In ruby, operators are methods and they operate on objects, not on >>> variables. >> >> That's not really a valid reason, and not entirely true -- there is no += >> method for you to define. It behaves as though it's a macro: > You are right of course, the original question was, why is there no > x++ as syntactic sugar for x = x + 1. > No idea ;). Matz has always said that the reason is that he doesn't like the idea of an assignment that looks like incrementation. In other words, if you did: x = 1 x++ you wouldn't be incrementing x (because then 1 would be 2, which would cause chaos); rather, you would be assigning to x. Wrapping that in a notation that typically means something different (incrementing a variable) would be unidiomatic and misleading. David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL Advancing with Rails January 19-22 Fort Lauderdale, FL * * Co-taught with Patrick Ewing! See http://www.rubypal.com for details and updates!