Why no pre/post increment/decrement in Ruby?

I've been wondering why you can't do c++ in Ruby. Finally I found this post by Matz explaining (in somewhat broken English).

I guess it make sense, given that in Ruby, variables are essentially just names or aliases for objects. So c = 1; c++ would be the same as 1++. What would 1++ mean in any language? "Add 1 to 1, and assign the resulting value to 1"? Best you could do is have c++ return a new separate 2 object, which isn't what you'd expect if you come from a C-like background.

Tags:

Leave a Reply

You can use these tags in comments (Note: HTML is automatically escaped inside <pre> tags, nowhere else, so if you post source code, put it in <pre>):

<pre lang="some_programming_language"> 
<em>
<strong>
<a href="url">

NOTE: Comments are automatically spam-filtered. If your comment fails to appear, it was likely munched by the filter. Try not to link-spam or post anything that looks like it was typed by a robot.