Tony Arcieri wrote: > [Note: parts of this message were removed to make it a legal post.] > > On Fri, Oct 30, 2009 at 12:03 PM, Rick DeNatale <rick.denatale / gmail.com>wrote: > >> I think that theres a more fundamental problem with ++ in a language >> like ruby, which has to do with the difference between objects and >> variables. >> > > Personally I see nothing interesting about the behavior of ++ in any mutable > state language. > > >> Now, consider not immutable objects, but defining ++ for a mutable >> object. I've named the method plus_plus instead of ++ since I can do >> the former, but not the latter. >> > > How is ++ any different from << except for << taking an argument? (given > hypothetical C-like ++ behavior) > Maybe I am missing something but how would one print a variable and increment it with the same statement? In C one would just write printf ("%i/n", x++). I haven't seen any easy way to do this with Ruby. Using << or +=1 you have to have a separate statement for the assignment. So instead of having something like: i = 1 while (i < 10) puts i++ end you have to have: i = 1 while (i< 10) puts i; i +=1 end I can see a reason for not being able to do 2++, but not i++. > There is already extensive precedent in Ruby for destructive method calls > that mutate state, and they all lead to the same confusion. > > There is nothing interesting with Ruby in this regard, except that Ruby does > seem to go out of its way to do things immutably by default, which, in my > opinion, is pretty cool. But in the end Ruby is still very much a mutable > state language. >