From: mathew
Date: 2005-08-19T06:21:16+09:00
Subject: Re: First Ruby Program
Gibbs Tanton - tgibbs wrote:
> Before I begin I would like to say that there were two things that
> bit
> me over and over again. The first was that !0 == false. This is just
> unintuitive to me as a C++/Perl programmer and was very frustrating.
> The second was the need to clone to avoid references to the same object.
> Once again, this was unintuitive to me.
I used to think the same. However, I eventually decided Ruby does the
right thing. My logic is as follows:
- Perl sidesteps the issue (mostly) by using sigils, so that references
vs values are always visibly different. Given that Ruby doesn't use
sigils, let's consider the three options: everything's a reference,
everything's a value, or 'it depends'.
- Option 1: Everything by value. This doesn't work, because it's very
inefficient when passing objects as function arguments.
- Option 2: "It depends". Java does this. I find it incredibly
irritating, because it means I have to remember which types are passed
by value, and which are passed by reference, and code accordingly. The
"it depends" style of behavior then ends up being extended to other
parts of the language--for example, '+' dereferences its arguments if
they're references to strings, but not if they're references to
integers. If you take some code written to perform a calculation on
ints, and use it to calculate the same thing for complex values, it may
not work, or may overwrite your variables. "It depends" also makes
polymorphism harder. So, I don't like that option.
- Hence by a process of elimination, the best option is Option 3:
Everything by reference.
(Actually, there's one more option: don't have imperative variables. If
you like that, try ML.)
> **************************************************************************
> The information contained in this communication is confidential, is
> intended only for the use of the recipient named above, and may be legally
> privileged.
Yeah, right.
mathew
--
WE HAVE TACOS