[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Question about 2005 Ruby critique...

barcaroller

9/24/2007 9:49:00 PM

I come from a C/C++/Perl background and I have been reading up on Ruby for a
while (no hands-on experience yet, except for a few tutorials). Most of the
stuff sounds/looks very positive but I recently found this critique of the
Ruby language on the web and I was wondering whether these statements have
any validity at all.


========================================
Ruby: better than Perl - but what isn't?
----------------------------------------

Ruby is the second-most vulgar programming language in wide usage. It
succeeds at its intended goal of being better than Perl, but its design
manifests a total ignorance of basic programming language theory.

Updated 9 January, 2005: Bruce Eckel apparently isn't bowled over, either.

Ruby's creator, Yukihiro "matz" Matsumoto, crossed the Perl language with
Smalltalk-inspired OO features including a fully-unified type system and
closures, then added exception handling and simulated multi-threading. The
result is certainly an improvement over Perl, but it is terribly
disappointing as a language.

The main philosophy of Ruby seems to be, "Side-effects rock!" We can
probably blame the C language for blurring the distinction between
imperative and applicative code. Maybe that blurring makes some amount of
sense for C, which is essentially a high-level assembly language. However,
languages such as C++, Java, and Perl have carried that foul practice
forward. And now Ruby takes it to new heights: every statement is an
expression, and every expression is a statement. Every method is a
procedure, and every method also is a function. Functions and expressions
with side-effects abound in Ruby.

Worse, Ruby exalts global side-effects. In a nominally multi-threaded
language, this is unseemly to say the least. As an everyday example, the
statement

x = gets

reads a line and sticks it into x just like you'd probably expect, but it
also has the side effect of sticking the line into the global variable $_.
WTF???

Ruby seems to love the magical global variables carried over from Perl.
There are dozens of them, all with nonintuitive names like $_, $!, $*, and
$~. Yuck. These things get set as side effects, and often are used
implicitly.

Ruby's exception mechanism combines the above failures into an astounding
disaster. When an exception occurs, an exception object is created and
stored into $! which is a global variable. Apparently you aren't supposed
to get exceptions in more than one thread at a time. Updated 9 January 2005:
It turns out that this isn't actually an issue; read the comments for
details.

Ruby also blurs the line between names of variables and methods. The
Uniform Access Principle is an excellent idea. at least in a language where
both variables and methods have to be declared and cannot overlap. But Ruby
allows a symbol to identify both a variable and a method, and the
disambiguation process is best described as eccentric.

Ruby delights in the bizarre usage of operator overloading. "<<" normally
means "left shift", but it also means "here document follows," "append to
string," and "extend array." Other operators have similar illogical
overloadings; for example, the "<" operator not only means "less than" but
also "is a subclass of."

Ruby throws a basic OO principle to the wind by allowing anyone to add
members and methods to an existing class, even outside of the original class
definition. The methods thus added have full access to all other members and
methods, including private ones. The usual term for this is "breaking
encapsulation," although I dislike that term because it misuses the word
encapsulation. A better term is "violation of the Open/Closed Principle," in
that the original class is not kept closed against modifications.

Ruby's multi-threading seems to be a misfeature from tip to toe. Ruby's
multi-threading is simulated: it only runs on a single CPU and is
fundamentally incapable of taking advantage of multiple CPUs or multiple
cores within a CPU. Which is just as well, because Ruby doesn't define a
memory model for coordinating data between CPUs or cores. Then there is the
problem of global variables being changed as side effects and accessed
implicitly. Writing multi-threaded code in Ruby looks like a good way to
cause yourself immense non-deterministic grief.

Ruby code can be written to be very clean and readable-something that cannot
really be said about Perl-but Ruby can also be written just as poorly as
Perl is. Unfortunately, most of the Ruby code that I've seen, including
various introductory guides to the language, seems to prefer the slutty side
of Ruby: procedural code using global variables and magical side effects.
I'm
not sure that I see how Ruby is better than Perl in those cases.

I've written some Perl over the years, and I probably will be transitioning
to Ruby for those tasks. Ruby certainly is better than Perl, especially if
you choose the high road and write clean code that eschews the side effects
and global variables. But I'm not at all happy with Ruby, because it easily
could have been so much better than it is.

Friday, 7 January, 2005





9 Answers

Chad Perrin

9/24/2007 10:07:00 PM

0

On Tue, Sep 25, 2007 at 06:50:09AM +0900, barcaroller wrote:
> I come from a C/C++/Perl background and I have been reading up on Ruby for a
> while (no hands-on experience yet, except for a few tutorials). Most of the
> stuff sounds/looks very positive but I recently found this critique of the
> Ruby language on the web and I was wondering whether these statements have
> any validity at all.
>
>
> ========================================
> Ruby: better than Perl - but what isn't?
> ----------------------------------------

I think that line really says it all. There's a *lot* of stuff that
isn't better than Perl. Perl's a great language, especially within its
particular niches of choice. Ruby is certainly better than Perl at some
things, and Perl is better than Ruby at others. Both are better than
Python at some things. Et cetera.

The so-called critique (more of an attempt at character assassination) is
filled with questionable value judgments without much value outside
personal preferences, presented as facts. I don't think it requires much
addressing beyond pointing out the ridiculous assumptions embodied in
that headline. Further indications that the author has no clue what
he/she is talking about include the implication that Perl doesn't support
closures, that Ruby's functional (read: no side effects) capabilities are
anathema to the language's core design philosophy, that side effects are
necessarily bad, and so on.

With such devastating exercises of logical rigor in making an argument as
"WTF???" and "Yuck," against which I have no defense, I feel I have been
bested on the field of honor. I shall now withdraw.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
Patrick J. LoPresti: "Emacs has been replaced by a shell script which 1)
Generates a syslog message at level LOG_EMERG; 2) reduces the user's disk
quota by 100K; and 3) RUNS ED!!!!!!"

Marc Heiler

9/24/2007 11:06:00 PM

0

I think the point about "side effects" is rather weak...

Has anyone ever ran into a side effect that killed his program due to
setting of $_?

The << is a very easy operator in the sense (for me) that it just means
"add this stuff"... its one of the things i liked in C++ a lot.... cout
<< "hello world" << some_var << "\n" (or something, my C++ is so rusty
and i never spent a lot of time with it...)

The < well... he maybe has a very small point there ... it also means
smaller than ... ok, but I dont think this is really any issue at all,
and its short as well :)
To be honest, I believe the "speed reason", even if I dont care really
how "slow" ruby is anyway - i think that reason would be better than
stuff like "side effects" $_
(The variable names are really non-intuitive and ugly though, i always
use the long version if available... maybe except when one-liners would
matter)

"but Ruby can also be written just as poorly as Perl is."
I think this is a _VERY_ weak point. Basically, everyone can obfuscate
every language! Lets take an expert perl coder that tries to write good
perl code and compare the same to one doing that with ruby. I did so (i
am not at all a perl expert), IMHO the ruby code looks very very clean
and thus beautiful.

I can not say the same about python in this regard to all the extent i
do for ruby, although I'd share that getting rid of the end's is not
that bad at all (but I have a huge problem with the def foobar():, and
the need for the .method() and also implicit self in python ... in ruby
i choose my way and feel free, in python well... ;> )

Just choose the solutions you like and try to opt for clean and brief
ways (if possible). Didnt Larry Wall once wrote that the key to use perl
is, to use its strength, and not its weaknesses? (He must be one of the
funniest programmers alive! :-) )

Anyway, i think python is also a LOT better than perl in this clean-ness
regard, at least I could see myself maintaing python scripts more likely
than perl scripts. But for many problems, getting the problem solved
quickly will suffice. For me I just wanted to have scripts that I look
at a later time in my life again, and I am in big love with ruby's OO
too so ... ;-)
--
Posted via http://www.ruby-....

Bill Kelly

9/24/2007 11:35:00 PM

0


From: "barcaroller" <barcaroller@music.net>
>
[...]
> I recently found this critique of the
> Ruby language on the web and I was wondering whether these statements have
> any validity at all.
[...]
>
> Ruby is the second-most vulgar programming language in wide usage. It
> succeeds at its intended goal of being better than Perl, but its design
> manifests a total ignorance of basic programming language theory.

Meh. Ruby's design to me represents a rather surprising balance
between expressiveness, orthogonality, consistency, and pragmatism
that few other language designers have been able to achieve.

I really like these slides from matz' oscon 2003 talk.
http://www.rubyist.net/~matz/slides/...

To me those slides give a flavor of the qualities and values that
matz had (has) in mind while designing Ruby, and help paint a
picture of how ruby became as fun to program in as it is for many
of us.


> The main philosophy of Ruby seems to be, "Side-effects rock!" We can
> probably blame the C language for blurring the distinction between
> imperative and applicative code.

Yes: Ruby isn't Haskell. Moving on . . .


> Maybe that blurring makes some amount of
> sense for C, which is essentially a high-level assembly language. However,
> languages such as C++, Java, and Perl have carried that foul practice
> forward. And now Ruby takes it to new heights: every statement is an
> expression, and every expression is a statement. Every method is a
> procedure, and every method also is a function. Functions and expressions
> with side-effects abound in Ruby.

This seems to be complaining about an aspect of Ruby that I
actually like.

I love that statements are expressions. It's a quite elegant
elimination of an unnecessary distinction in imperative languages,
in my view.


> Worse, Ruby exalts global side-effects. In a nominally multi-threaded
> language, this is unseemly to say the least. As an everyday example, the
> statement
>
> x = gets
>
> reads a line and sticks it into x just like you'd probably expect, but it
> also has the side effect of sticking the line into the global variable $_.
> WTF???
>
> Ruby seems to love the magical global variables carried over from Perl.
> There are dozens of them, all with nonintuitive names like $_, $!, $*, and
> $~. Yuck. These things get set as side effects, and often are used
> implicitly.

Not to worry. These Perlisms don't tend to get used except in the
case of one-liners. Some folks would rather they were banished
from Ruby entirely, but I like the ability to do concise one-liners
from the shell in Ruby, because it means I don't have to use Perl.

An example of the kinds of one-liners I appreciate being able to
knock off in ruby right from the command prompt:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-...


> Ruby delights in the bizarre usage of operator overloading. "<<" normally
> means "left shift", but it also means "here document follows," "append to
> string," and "extend array." Other operators have similar illogical
> overloadings; for example, the "<" operator not only means "less than" but
> also "is a subclass of."

So because << means "left shift" for integers, it has to mean
"left shift" for strings and arrays and classes too? :duh:

I'd say << is an ideogram. Let it mean something appropriate
in context.


> Ruby throws a basic OO principle to the wind by allowing anyone to add
> members and methods to an existing class, even outside of the original class
> definition. The methods thus added have full access to all other members and
> methods, including private ones. The usual term for this is "breaking
> encapsulation," although I dislike that term because it misuses the word
> encapsulation. A better term is "violation of the Open/Closed Principle," in
> that the original class is not kept closed against modifications.

It sounds like the sky is falling. But Ruby's "open classes" are
one of my favorite features.

Yes, one has to be careful, especially when writing library code,
so as not reopen classes in a way that might conflict with other
libraries.

But it's also a very powerful feature. Quoting matz:

| "open class" is so strong (often too strong), we can break things
| easily. In other word, Ruby trust you to give you sharp knives, where
| Python don't. From the Python point of view, it's wrong, I guess.

:)

More on the subject: http://vying.org/blog/2007/05/ruby...


> Ruby's multi-threading seems to be a misfeature from tip to toe. Ruby's
> multi-threading is simulated: it only runs on a single CPU and is
> fundamentally incapable of taking advantage of multiple CPUs or multiple
> cores within a CPU. Which is just as well, because Ruby doesn't define a
> memory model for coordinating data between CPUs or cores. Then there is the
> problem of global variables being changed as side effects and accessed
> implicitly. Writing multi-threaded code in Ruby looks like a good way to
> cause yourself immense non-deterministic grief.

There are arguments pro- and con- green threads vs. OS threads.

However, the author's worries about global variables seem to be
entirely misplaced. The variables he's apparently worried about
are thread-local, not global. (Much ado about nothing?)


> Ruby code can be written to be very clean and readable-something that cannot
> really be said about Perl-but Ruby can also be written just as poorly as
> Perl is.

:duh:


Anyway, . . .


Hope this helps,

Bill



Terry Poulin

9/24/2007 11:50:00 PM

0

> I think that line really says it all. There's a *lot* of stuff that
> isn't better than Perl. Perl's a great language, especially within its
> particular niches of choice. Ruby is certainly better than Perl at some
> things, and Perl is better than Ruby at others. Both are better than
> Python at some things. Et cetera.
>
> The so-called critique (more of an attempt at character assassination) is
> filled with questionable value judgments without much value outside
> personal preferences, presented as facts. I don't think it requires much
> addressing beyond pointing out the ridiculous assumptions embodied in
> that headline. Further indications that the author has no clue what
> he/she is talking about include the implication that Perl doesn't support
> closures, that Ruby's functional (read: no side effects) capabilities are
> anathema to the language's core design philosophy, that side effects are
> necessarily bad, and so on.
>
> With such devastating exercises of logical rigor in making an argument as
> "WTF???" and "Yuck," against which I have no defense, I feel I have been
> bested on the field of honor. I shall now withdraw.
>
> --
> CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
> Patrick J. LoPresti: "Emacs has been replaced by a shell script which 1)
> Generates a syslog message at level LOG_EMERG; 2) reduces the user's disk
> quota by 100K; and 3) RUNS ED!!!!!!"
>
>

I'm familiar with a number of languages if not strongly with putting OOP into
practice. You could say collecting languages and programs has been some thing
of a hobby of mine for a short number of years now.


I remember when I first met the C style for loops, like "for (i = 0; i < foo;
i++) { ... }" and how archaic I thought them at first. In my travels I've
occasionally shouted "Dang I wish this was like language X" when doing some
thing in language Y -- I think most people have!


My policy is, I didn't write it, I didn't design it, and I didn't help them
create the language. So why complain about their decisions. As long as they
document the ruddy thing who cares.


Perl makes a fair bit of usage of $who_the_heck_can_remember_this_symbol
variables too, looking at quick references for Ruby. I usually see stuff that
allows me to bring knowledge of other languages into play and thus learn and
use Ruby more effectively. Because it borrows from other languages also in
common usage; good for programmers who know those languages. Although if I did
design a programming language I would probably be the worlds biggest critic of
it. ^_^


There is an old saying that if you try to please *everyone* you will please
*noone* at all. Although Perl might be able to do both reasonably well
depending on the type of person you are.


TerryP.


PS: Chad Perrin, nice quote in the sigblock :-)



--

Email and shopping with the feelgood factor!
55% of income to good causes. http://www.ip...


Chad Perrin

9/25/2007 4:38:00 AM

0

On Tue, Sep 25, 2007 at 08:49:42AM +0900, Terry Poulin wrote:
> >
> > --
> > CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
> > Patrick J. LoPresti: "Emacs has been replaced by a shell script which 1)
> > Generates a syslog message at level LOG_EMERG; 2) reduces the user's disk
> > quota by 100K; and 3) RUNS ED!!!!!!"
>
> PS: Chad Perrin, nice quote in the sigblock :-)

Thanks. I've got a million of 'em. Well, a few dozen, anyway.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
McCloctnick the Lucid: "The first rule of magic is simple. Don't waste your
time waving your hands and hopping when a rock or a club will do."

Wilson Bilkovich

9/25/2007 4:58:00 AM

0

On 9/24/07, barcaroller <barcaroller@music.net> wrote:
> I come from a C/C++/Perl background and I have been reading up on Ruby for a
> while (no hands-on experience yet, except for a few tutorials). Most of the
> stuff sounds/looks very positive but I recently found this critique of the
> Ruby language on the web and I was wondering whether these statements have
> any validity at all.
>
>
> ========================================
> Ruby: better than Perl - but what isn't?
> ----------------------------------------

Just a single correction here.. I won't bother with the rest..
The "side-effect globals" the author abhors are actually thread-local,
so they don't present a problem for multithreaded code. They just
happen to look like 'regular' globals.

Gaspard Bucher

9/25/2007 6:58:00 AM

0

> The < well... he maybe has a very small point there ... it also means
> smaller than ... ok, but I dont think this is really any issue at all,
> and its short as well :)

I think the "smaller then" sign is great. It means "This subclass is a
descendant (smaller/younger) class of this other class."

Child < Parent makes perfect sense.

PS:
(I like the "postmodern mess" of Perl, but it tended to jump back at
me a couple of weeks later. I feel I have the same freedom with Ruby,
with a more secure feeling allowing me to write large applications
without fear. Perl was the first language I felt joyful with. Ruby
took the same path in my heart.)

Gaspard

Chad Perrin

9/25/2007 7:28:00 AM

0

On Tue, Sep 25, 2007 at 03:58:09PM +0900, Gaspard Bucher wrote:
>
> PS:
> (I like the "postmodern mess" of Perl, but it tended to jump back at
> me a couple of weeks later. I feel I have the same freedom with Ruby,
> with a more secure feeling allowing me to write large applications
> without fear. Perl was the first language I felt joyful with. Ruby
> took the same path in my heart.)

I like that description of your feelings about Perl and Ruby. I feel
similarly, with the exception that Ruby doesn't really make me feel any
safer than Perl -- because I feel "safe" enough with both. Where Perl
falls down for me, as compared with Ruby, is basically just where object
oriented programming is called for. OOP in Perl is kind of a painful
experience, especially compared with Ruby. On the other hand, there's a
lot of coding that really doesn't have any need for OOP and, in many
cases, might even be made more difficult or otherwise less "good" by
forcing it into an OOP paradigm -- and for that stuff, Perl is still one
of my favorite languages.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
Baltasar Gracian: "A wise man gets more from his enemies than a fool from
his friends."

Michael Neumann

9/25/2007 7:44:00 AM

0