Things That Newcomers to Ruby Should Know (11/24/02)

Hi Bill (aka William Djaja Tjokroaminata [mailto:billtj@y.glue.umd.edu]):

You wrote to the point:

My point was that you were giving the impression that the
lack of ++
for Fixnum was an implementation issue, and that alternative Ruby
implementations might support it. Given that you produce a document
aimed at newcomers, it was important to me that this
misunderstanding
was cleared up.

Well, as you already read, different people gave different
reasons why Fixnum#succ! is “impossible”. Without the
concept of “immutability” being formally introduced in the
Ruby programming language, I can always give the reason from
the implementation point of view. (In theory, I can make
Fixnum to be mutable; whether this is good or bad is a different
story. Guido thought that strings should be immutable; Matz
thought otherwise. Python insists that hash keys be
immutable objects; Ruby allows any objects, with the
consequence of the need for “rehash” in certain situations.)

Without any formal treatment of immutability in Ruby, your
previous post is the only reference that I can use if in the
future these questions are asked again:

  1. Why Fixnum is immutable (no Fixnum#succ!) while String is
    mutable (String#.succ! is provided)?

  2. How do I know which objects/classes are mutable and
    immutable? (Answer: just read all the methods, and if no "!"
    methods are provided, it is immutable (?))

Very clearly said.
I hope your questions will be answered clearly and posted to faq.

Regards,

Bill

Best regards,
-botp

···

Dave Thomas Dave@pragmaticprogrammer.com wrote: