C
Caleb Clausen
While this is technically true (because the reference actually *is* the
Fixnum value) I think this is a bad way to express it. The reason is
that it looks into implementation details of the interpreter when one
tries to describe a phenomenon of the language Ruby. It actually
complicates things more than necessary which IMHO hinders understanding.
Rick said:I thing that the value of thinking of this as call by object
(reference) is that in languages like Smalltalk and Ruby the object
references are opaque, and provide a barrier between the caller and
the object's implementation. The only way for another object to get at
any state on the other side of that barrier is by sending a message to
the object, even if that message is instance_variable_get/set.
The problem I have with this viewpoint is that you are then stuck with
a set of strange and arbitrary (seeming) rules about how things work.
Such as: A Fixnum is always a singleton object, whereas a Bignum is
not. For that matter why do we even have the distinction between
Fixnum and Bignum at all? Why isn't there just one Integer class? If
you don't understand the lower level representation, then these are
real head-scratchers. They're just commandments from On High about How
It Shall Be. Whereas if you do know the underlying realities, then
it's not only easier to remember all this stuff, it's easier to reason
about it as well.
One of the important skills a programmer needs is the ability to work
on multiple levels of abstraction simultaneously. You need to be able
to zero in one one layer which is most relevant to the task while
simultaneously keeping the other layers in the back of your mind; not
completely forgotten, but just submerged and ready to come back to
the surface when the concerns relevant to that layer arise again.
Knowing as many of these layers as possible makes it easier to reason
about programs. I know it makes me a better programmer.