The pre/post increment/decrement operator (++
and --
) are pretty standard programing language syntax (for procedural and object-oriented languages, at least).
Why doesn't Ruby support them? I understand you could accomplish the same thing with +=
and -=
, but it just seems oddly arbitrary to exclude something like that, especially since it's so concise and conventional.
Example:
i = 0 #=> 0
i += 1 #=> 1
i #=> 1
i++ #=> expect 2, but as far as I can tell,
#=> irb ignores the second + and waits for a second number to add to i
I understand Fixnum
is immutable, but if +=
can just instanciate a new Fixnum
and set it, why not do the same for ++
?
Is consistency in assignments containing the =
character the only reason for this, or am I missing something?
+=
operator. In C I try to use++
/--
only inside conditionals, preferring for the more literal+=
/-=
in a basic statement. Probably because I learned Python (long after C though...) – Unaccompanied