Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Ruby: An Abbot breaks silencewind

by coreolyn (Parson)
on Jun 11, 2001 at 05:33 UTC ( [id://87383] : perlmeditation . print w/replies, xml ) Need Help??

Fellow Monks, I offer this meditation in light of my recent journies.

I've taken the oft given advice to explore other languages. I have lashed my leash to Java and made big rocks into little rocks, and the little rocks into sand. On the side I played played with Squeak with which I cemented the sand back into a big rock. So I continued my search for the right tool for a very large personal itch that needs vast quantities of reusable prototypes. This hunt lead me to Ruby.

In this poll post dated October 27th kapper stated the question, "I am quite suprised that nobody has mentioned Ruby?". Which recieved very little attention maybe because the thread Ruby broached the topic already and it too got little attention.


Yukihiro Matsumoto, a.k.a "Matz" (Ruby's creator) makes this (shamelessly out of context) statement in the forward of the book Programming Ruby (Online Version ), "Then I remembered my old dream, and was toying with it at work. But gradually it grew to be a tool good enough to replace Perl".

That sure put me on the defensive from page xxi.

Now after my initial tinkering with it and reading the first 100 pages or so I'm positive this is definately much more than just another Parrot and in fact I've got to say that looking at a singleton in Ruby fits the way my brain works far easier than by looking at a singleton in java, c++, smalltalk, or Perl. (I do hate that new is a mandantory constructor though -- I really like that about Perl OO).

sub instance { my $class = shift; no strict 'refs'; my $instance = \${ "$class\::_instance" }; defined $$instance ? $$instance : ($$instance = $class->_new_instance(@_)); }
class Logger private_class_method :new @@logger = nil def Logger.create @@logger = new unless @@logger @@logger end end

IMHO trying to get Ruby to replace Perl is not the correct way to attract prospective users though. I think Perl will continue to evolve as the most colorful code with which an artist can apply his paint because Perl is as much culture and resources as it is code.

Ruby is very clean to work with (So far) and its OO implementation seems to be much cleaner than even Java's. For me the real question always comes to scale, but by scale I imply code maintenance and support equally with performance. As most of the usage data is on Japaneese pages (and I'm really lazy) I don't have any data to look at on that front.

So the jury is still out -- though this gem has definately caught my eye. (I fear I am becoming a shameless language slut. I don't think I want to find a language good enough for my project -- then I'd have to work on it.) I do think they might want to edit that forward though. It's a tad bold for such a young language that has yet to feel global pressures of popularity and evolution.

However Ruby is looking very intriguing.


Replies are listed 'Best First'.
Re: Ruby: An Abbot breaks silencewind
by elusion (Curate) on Jun 11, 2001 at 07:02 UTC
    I've experimented with Ruby, and have found it intriguing too.

    The main downside to Ruby is the lack of documentation (at least in English). The only documentation I've been able to find is the online version of Programming Ruby.

    I do like the instance variables though (those prefixed with a @ -- it's like %self in Perl OO). Many of the features work better than Perl OO, but that should change with Perl 6. St. Larry has dabbled in Ruby a little and found some features that he's going to incorporate into Perl.

    Ruby is definitely worth a look.

    - p u n k k i d
    "Reality is merely an illusion, albeit a very persistent one." -Albert Einstein

Re: Ruby: An Abbot breaks silencewind
by Abigail (Deacon) on Jun 11, 2001 at 11:59 UTC
    While I think Perl's OO is rotten to the core, I don't agree that making singletons in Perl is difficult. You certainly don't need the convoluted code you showed!
    package Logger; { my $instance; sub instance { return $instance if $instance; my $class = shift; $instance = bless {@_} => $class; } }

    -- Abigail

      As I didn't trust my own rolling of a Perl Singleton I grabbed that code directly from from CPAN's Though I'm guessing that the use of the Trinary in the CPAN version might give a performance boost over the clearer functionality your code expresses.

      This won't work for classes inherited from Logger. They all get the same instance unless they override instance method. That is genealy not desirable.

        Isn't that why it's called a singleton?

Re: Ruby: An Abbot breaks silencewind
by John M. Dlugosz (Monsignor) on Jun 13, 2001 at 00:12 UTC
    For grins, I tried converting this example from the reference from Ruby to Perl.
    def fibUpTo(max) i1, i2 = 1, 1 # parallel assignment while i1 <= max yield i1 i1, i2 = i2, i1+i2 end end fibUpTo(1000) { |f| print f, " " }
    After all, the oft-touted ability to pass blocks as parameters is something Perl does, too. With the prototype syntax, it should be just as simple, right?

    Well, this brings me to my own Meditation. My first try didn't take. Browsing the perlsub page, I find, “An & requires an anonymous subroutine, which, if passed as the first argument, does not require the sub keyword or a subsequent comma.” So, I need to reverse the order of the arguments. Passing a sub last would require a sub keyword in the call. Why is this so?

    Meanwhile, it doesn't work for methods, so you can't really use the prototypes to give rise to this syntax for general-purpose iterators (that are part of a collection).

    use strict; use warnings; sub fib (&$) { my ($action,$max)= @_; my ($i1, $i2)= (1,1); while ($i1 < $max) { $action->($i1); ($i1,$i2) = ($i2, $i1+$i2); } } fib {print "$_[0] "} 1000;