Hi,
In message "[ruby-talk:20234] Re: ++ Operator"
on 01/08/24, Dave Thomas <Dave / PragmaticProgrammer.com> writes:
|OK, but... (this is where I make a fool of myself).
You sacrifice yourself for the sake of our enlightnment, don't you?
|Is the fundamental property of Fixnum that its objects are immutable,
|or that its objects do not have copy semantics? If the former, then
|obviously ++ just isn't viable. If the latter, then it's possible to
|imagine implementations that would allow it.
|
|I know we're not going to see ++ in Ruby in my lifetime. However, I'm
|wondering if this is a necessary restriction on the language, or
|simply on implementation convenience.
To implement "++" behavior, we have two choice:
(a) make "++" a special form of assignment. "a++" would be syntax
sugar for either "a+=1" or "a=a.succ".
(b) make numbers mutable, then prepare "++" method to alter the
number value.
You were talking about (b) above, right? I think it's wrong way to
go. It is confusing. I believe almost everyone assume numbers to be
immutable consciously or unconsciously. Also it would be performance
penalty.
If we really want "++", (a) is the way to go, but I don't think it's
worthy to add new assignment syntax. Mostly because we have less
chance to use it in Ruby. Thanks to iterators.
matz.