# Background on why Ruby doesn't support ++

**URL:** <https://www.ruby-forum.com/t/background-on-why-ruby-doesnt-support/173677>\
**Category:** Ruby\
**Created:** [August 13, 2009, 8:20am UTC](https://www.ruby-forum.com/t/background-on-why-ruby-doesnt-support/173677 "2009-08-13T08:20:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![b1gtuna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@b1gtuna](https://www.ruby-forum.com/u/b1gtuna)\
**Post date:** [August 13, 2009, 8:20am UTC](https://www.ruby-forum.com/t/background-on-why-ruby-doesnt-support/173677/1 "2009-08-13T08:20:03Z")

</div>

Hi All,

I’m a big Ruby fan and I’m not trying to complain.

I’m just curious as to why Ruby doesn’t support the ++ or – operators.  
Is there some syntactical ambiguity that’s associated with it or  
something.

Anyone know the history on this deliberate omission?

Thanks!

Adam

---

<div class="post-metadata">

**Author:** ![b1gtuna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@b1gtuna](https://www.ruby-forum.com/u/b1gtuna)\
**Post date:** [August 13, 2009, 8:32am UTC](https://www.ruby-forum.com/t/background-on-why-ruby-doesnt-support/173677/2 "2009-08-13T08:32:51Z")

</div>

On Wed, Aug 12, 2009 at 11:20 PM, Adam L.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Anyone know the history on this deliberate omission?

Matz addressed this in ruby-talk 2710:

[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2710](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2710)

HTH!  
Shajith

---

<div class="post-metadata">

**Author:** ![b1gtuna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@b1gtuna](https://www.ruby-forum.com/u/b1gtuna)\
**Post date:** [August 13, 2009, 1:16pm UTC](https://www.ruby-forum.com/t/background-on-why-ruby-doesnt-support/173677/3 "2009-08-13T13:16:46Z")

</div>

On Thu, Aug 13, 2009 at 11:31 AM, Robert  
Klemme[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> incremented.  
> Makes sense, though strictly speaking x++ could be syntactic sugar for  
> x+=1 or x =x +1  
> but this would probably be very confusing for many folks for the very  
> reason you gave.  
> Cheers  
> Robert

---

<div class="post-metadata">

**Author:** ![b1gtuna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@b1gtuna](https://www.ruby-forum.com/u/b1gtuna)\
**Post date:** [August 13, 2009, 3:10pm UTC](https://www.ruby-forum.com/t/background-on-why-ruby-doesnt-support/173677/4 "2009-08-13T15:10:55Z")

</div>

Don’t forget there’s already

x.next

although there is not the orthogonal x.prev, which seems like the  
Principle of Most Surprise in effect :-). One way to rectify that is  
to open up Integer yourself:

class Integer  
def prev  
self - 1  
end  
end

---

<div class="post-metadata">

**Author:** ![b1gtuna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@b1gtuna](https://www.ruby-forum.com/u/b1gtuna)\
**Post date:** [August 13, 2009, 11:31am UTC](https://www.ruby-forum.com/t/background-on-why-ruby-doesnt-support/173677/5 "2009-08-13T11:31:59Z")

</div>

2009/8/13 Shajith C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> On Wed, Aug 12, 2009 at 11:20 PM, Adam L.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Anyone know the history on this deliberate omission?
> 
> Matz addressed this in ruby-talk 2710:
> 
> [http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2710](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2710)

Basically it is a consequence of the decision to make integers  
immutable which makes assignment necessary for a variable which is  
incremented. I guess Matz wanted to make this explicit, hence “+=”  
Co.

Otherwise you need a counter class, e.g.

Counter = Struct.new :value do  
def initialize(x = 0)  
self.value = x  
end

def plusplus  
self.value += 1  
end

alias incr plusplus

def minusminus  
self.value += 1  
end

alias decr minusminus  
end

🙂

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![b1gtuna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@b1gtuna](https://www.ruby-forum.com/u/b1gtuna)\
**Post date:** [August 13, 2009, 4:13pm UTC](https://www.ruby-forum.com/t/background-on-why-ruby-doesnt-support/173677/6 "2009-08-13T16:13:26Z")

</div>

2009/8/13 Mark T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> self - 1  
> end  
> end

There is also #succ and #pred. But this is not the point: all of them  
work by returning _a different object_. You can easily verify by  
looking at the result’s #object\_id. Operators ++ and – in C++ on the  
other hand change the object (int, long etc.) itself. The difference  
is whether you will have aliasing or not.

Kind regards

robert
