fmII
Fri, May 09th home | browse | articles | contact | chat | submit | faq | newsletter | about | stats | scoop 08:44 PDT
in
Section
login «
register «
recover password «
[Article] add comment [Article]

 The Scalability of Ruby
 by Jack Herrington, in Tutorials - Sat, Apr 13th 2002 00:00 PDT

There are lots of reasons to like Ruby. It's a pure object oriented language. The syntax is elegant, and the use of blocks creates a novel feel. Another reason to like Ruby is its scalability. I don't mean scalability in the performance sense, but in regards to how you can code simple Ruby macros to solve small problems and also use Ruby in its object oriented form to support very large or complex applications.


Copyright notice: All reader-contributed material on freshmeat.net is the property and responsibility of its author; for reprint rights, please contact the author directly.

The scalability of a language is a critical factor in understanding how broad of a range of applications it can support. How many times have you started with a ten line macro, only to end with a 15,000 line GUI application as the true requirements were uncovered? A scalable language reduces the barriers to scaling an application from 10 lines to 15,000 lines.

For this article, I will scale the solution of a simple problem to show the various forms of Ruby, from a simple scripting language to one which supports functions, libraries, and, finally, object oriented programming. For the problem, I'll use a simple implementation of the Unix "cat" command. "cat" outputs the contents of all of the files specified on the commandline to STDOUT.

Macros

First, here's a simple macro solution:


ARGV.each{ |fileName|
    inHandle = File::PrivoxyWindowOpen( fileName )
    inText = inHandle.read()
    print inText
}

This iterates through each item of the commandline argument array, opens the file, reads the contents, and prints it. A shortened form looks like this:


ARGV.each{ |fileName|
  print File::PrivoxyWindowOpen( fileName ).read()
}

What about errors? Ruby has easy exception handling built in; here's an example:


ARGV.each{ |fileName|
  begin
    print File::PrivoxyWindowOpen( fileName ).read()
  rescue
    print "Couldn't open file '" + fileName.to_s + "'\n"
  end
}

If any of the expressions with the begin block raise an exception, the block will be terminated and the rescue portion of the block will be called. In this case, we take any exception to mean that the file could not be opened for some reason.

Functions

The next example is a function-based solution:


def print_file( fileName )
  print File::PrivoxyWindowOpen( fileName ).read()
end

ARGV.each{ |fileName| print_file( fileName ); }

First, we define a function named "print_file" that takes one string, a filename, opens the file, reads the contents, and prints it. As above, we iterate through the commandline argument array, but in this case, we send the fileName string to the print_file function.

Libraries

I implement the library approach in this example using a static member function of a class:


class FilePrinter
  def FilePrinter::print_it( fileName )
    print File::PrivoxyWindowOpen( fileName ).read()
  end
end

ARGV.each{ |fileName|
  FilePrinter.print_it( fileName )
}

FilePrinter::print_it is really just the print_file function above, but it is wrapped in the FilePrinter class for some sense of namespace containment.

Objects

An object oriented approach is shown below (even though an OO solution to the "cat" problem is probably overkill...).


class FilePrinter < File
  def print_it()
    $stdout.print read()
  end
end

ARGV.each{ |fileName|
  FilePrinter.open( fileName ).print_it()
}

We extend File into FilePrinter and add the print_it method to it. As we go through each commandline argument, we create a FilePrinter object (instead of a File object) and send the print_it message to it.

Note the use of "$stdout.print" as opposed to just print. The File class supports a print method, but would print to the file instead of to STDOUT. We use the global $stdout to tell Ruby exactly where to print the contents of the file.

Another approach to the object oriented solution is to encapsulate a file within our object instead of extending the file object:


class FilePrinter
  def initialize( fileName )
    @fileName = fileName
    @text = ""
    read()
  end
  def print_it()
    print @text
  end
private
  def read()
    @text = File::PrivoxyWindowOpen( @fileName ).read()
  end
end

ARGV.each{ |fileName|
  FilePrinter.new( fileName ).print_it()
}

The "FilePrinter" class in this example derives directly from "Object" instead of File. It has two member variables, @fileName and @text. When the FilePrinter object is initialized, it sets the @fileName member variable and calls a private read method. Implicit support for access control is unique to Ruby when it is compared with languages like Python and Perl.

Conclusions

While there is no one programming language that can be used to implement every application, Ruby does have the flexibility to scale all the way from simple macros to a large and complex set of classes. This flexibility is one of the attributes that makes Ruby such a fun language to learn and to work in.


Author's bio:

Jack Herrington is the editor of the Code Generation Network, a free information site dedicated to the dissemination of information about code generation techniques. His book, Code Generation In Action, will be released by Manning in July. He is the proud father of six month old Megan Michele.


T-Shirts and Fame!

We're eager to find people interested in writing articles on software-related topics. We're flexible on length, style, and topic, so long as you know what you're talking about and back up your opinions with facts. Anyone who writes an article gets a t-shirt from ThinkGeek in addition to 15 minutes of fame. If you think you'd like to try your hand at it, let jeff.covey@freshmeat.net know what you'd like to write about.

[Comments are disabled]

 Referenced categories

Programming Language :: Ruby

 Referenced projects

Ruby - An object-oriented language for quick and easy programming

 Comments

[»] Perl Examples
by Stathy - Apr 16th 2002 16:54:11

Dude, your giving Perl hackers a bad name ; ) 3 of the 4 samples above do not work as expected. It would have been wise to test them first. In my experience this has been the exact reason companies have an aversion to using Perl in a production environment. Too many hackers hacking too quickly while their hacks don't provide what was initially asked for : )

[reply] [top]


    [»] Re: Perl Examples
    by Vincent Janelle - Jul 19th 2002 20:04:42


    > Dude, your giving Perl hackers a bad
    > name ; ) 3 of the 4 samples above do
    > not work as expected. It would have
    > been wise to test them first. In my
    > experience this has been the exact
    > reason companies have an aversion to
    > using Perl in a production environment.
    > Too many hackers hacking too quickly
    > while their hacks don't provide what was
    > initially asked for : )
    >

    My experience with perl is that people are tired of new releases breaking their code..

    [reply] [top]


      [»] Re: Perl Examples
      by Bruno - Dec 6th 2002 18:51:31


      >
      > My experience with perl is that people
      > are tired of new releases breaking their
      > code..
      >

      There are a few other issues with Perl besides that:
      Whenever you start with a simple language and then
      add a bunch of features not planned for at the begining
      you end up with corner cases and gotchas.
      I once wasted a log of time tracking a bug from a
      customer script. Due to reference, a destructor for an
      object was being called twice. Once by the user on the alias, and once by perl itself when the object got out of scope. That second call messed the Perl interpreter internal data structures and the script crashed much
      later. (But since I built the Perl interpreter all the fingers
      pointed to me :-)
      You can argue that the programmer didn't know what he was doing, but I would argue that a languages that
      do garbage collection for you but forces you to
      understand how the underlying data structures work is
      dangerous.
      In that respect, Ruby is a much safer language and much
      easier to learn: Everything is a reference to an object. Done.
      I put Perl in the same basket as C++: A language that
      has a lot of good features, but which also has too many
      warts added to its core. Too many little things get
      in the way. You have to watch context when using
      things like arrays. You have to know that something is a hash, something is an array, something is a scalar...
      Too many little rules.
      In that respect, Ruby is much more elegant and simple to
      learn, at least if you've done a lot of OO programming.
      It's like Smalltalk without the weird environment.
      Much better for rapid prototypes than something more rigid
      like C++: You don't even have to stub a function. You
      just call it, and if the object doesn't support it you get
      an exception.

      bruno.

      [reply] [top]


[»] Scalability ?
by Patrice Ossona de Mendez - Apr 16th 2002 04:27:37

Scalability goes to two direction, for a language:
High level: can you define a new language high level construction,
such as a new kind of "objects", new kinds of "types" (I don't mean
objects or types, but things at the abstract level of 'object' and 'type'),
new modularity construction ?

Medium level: can you integrate an application at language level ?
(for instance: database integration by creating new castings, assignments, implicit type creations,etc.) Can you change casting
rules ?

Low level: can you add a new processor code and some optimizer
rule to use it for the last Intel processor that just comes out ?

-----------------------------------------

All this you can do with Pliant, for instance.

--
Pom

[reply] [top]


[»] Nice Introduction for the Neophyte
by Jon Tyson - Apr 14th 2002 23:54:55

Thank you for this introduction to Ruby. For a complete outsider, it is nice to get a tour of the features of the language as well as an opinion concerning its suitability for various tasks by someone who knows how to use it.

Personally, I find it easy to disregard the "My Perl is bigger than your Ruby" bs above.

[reply] [top]


[»] Perl
by Juerd - Apr 13th 2002 16:32:04

Just for educational purposes, here are Perl translations of the example scripts.

"Macros" - A single line of Perl does the same as the given 7-line Ruby example, including error reporting.
The code:
    print <>;

"Functions" - Not much trouble. Why even have a function for this?
The code:
    sub printfile { local @ARGV = @_; print <>; }
    printfile @ARGV;

"Libraries" - There is no point in having doing simple things in such a complex way.
The code:
    {
        package FilePrinter;
        sub print_it { local @ARGV = @_; print <>; }
    }
    FilePrinter::print_it @ARGV;

"Objects" - The author finally discovered that some things are overkill. Oh well, here goes:
The code:
    {
        package FilePrinter;
        sub _read { local @ARGV = @_; <>; }
        sub new { bless [ _read pop ], shift; }
        sub print_it { print @{ shift }; }
    }
    FilePrinter->new($_)->print_it for @ARGV;

Come on, you can do better than this. This has nothing at all to do with scalability, or advanced programming. Ruby can do more than this - BASIC can do more than this. You're giving Ruby a bad name.

--
Blaaat :)

[reply] [top]


    [»] Re: Perl
    by Morty Abzug - Apr 14th 2002 04:45:03


    > Just for educational purposes, here are
    > Perl translations of the example
    > scripts.

    You can reduce the example in perl to the following one liner:
    perl -pe ""

    Ie. perl -pe "" /etc/resolv.conf /etc/lilo.conf

    It even does error checking. ;)


    [reply] [top]


      [»] Re: Perl
      by Juerd - Apr 14th 2002 04:50:57


      > You can reduce the example in perl to
      > the following one liner:
      > perl -pe ""

      I didn't know we were golfing...
      perl -pe1

      --
      Blaaat :)

      [reply] [top]


    [»] Re: Perl
    by Guillaume Laurent - Apr 15th 2002 05:32:20

    It seems that you read the article, totally missed the point, and somehow felt that you needed to show that Perl could achieve the same things in less lines. What you did show, though, is that how quickly Perl becomes unreadable.

    [reply] [top]


    [»] Re: Perl
    by kinginyellow - Apr 15th 2002 20:48:09


    > Just for educational purposes, here are
    > Perl translations of the example
    > scripts.
    >
    > "Macros" - A single line of Perl does
    > the same as the given 7-line Ruby
    > example, including error reporting.
    > The code:
    >     print <>;

    Wow, fewer lines of code... it must be better. And this way is so much more readable.


    > "Functions" - Not much trouble. Why
    > even have a function for this?
    > "Libraries" - There is no point in
    > having doing simple things in such a
    > complex way.
    > "Objects" - The author finally
    > discovered that some things are
    > overkill. Oh well, here goes:

    Yep, that attitude is why I switched from Perl to Ruby. ;-)

    Seriously, though, you're completely missing the point of the article. The idea was not to show the best solution to the problem, but rather how Ruby supports some different approaches. The scalability the author was talking about stems from being able to attack a problem using different methodologies - procedural, OO, functional... Perhaps the author could have demonstrated this more clearly using some different examples. The fact that Perl, Python, LISP, etc also support some of the same things is irrelevant - the author wasn't making any assertion that they don't. No need to try to start a language war.


    > Come on, you can do better than this.
    > This has nothing at all to do with
    > scalability, or advanced programming.
    > Ruby can do more than this - BASIC can
    > do more than this. You're giving Ruby a
    > bad name.

    Nice attitude. Don't you have any constructive comments? Do you think you can write a better article? Then by all means please do so. I would love to read it - and I mean that sincerely. Freshmeat needs more good articles. On the other hand, if you're not going to contribute something, don't make bullshit jabs like this at those who do. It serves no purpose other than to make you look like a jerk.

    [reply] [top]


      [»] Re: Perl
      by Juerd - Apr 16th 2002 02:40:50


      > %     print <>;
      > Wow, fewer lines of code... it must be
      > better. And this way is so much more
      > readable.

      No, I didn't write the Perl examples to show that you can do more in less lines with Perl.
      I did write them to show to the readers of this article/forum that there is in fact more than one way to do it, and that Perl is a nice alternative to Ruby, especially when it comes to things like this. A single line that is a basic "cat" implementation, but that has no explicit literal "open" or "argv", or "readline" in it shows that Perl has built-in shortcuts for those simple tasks, so you can focus on the important parts of your program. The examples that I gave were to compare the two languages - the comparison itself and the conclusions drawn from it are up to the reader. One of the possible conclusions is that Ruby's syntax is more BASIC-like, and thus clearer and free of excessive punctiation. This may or may not be a good thing, it depends on the reader.


      > Yep, that attitude is why I switched
      > from Perl to Ruby. ;-)

      You pick your programming language by the attitute of some programmers that happen to use it? Maybe that's an option if you code for aesthetic purposes, or if you feel you need to be part of a larger community to be a good coder, but I like to base my choice of language on personal experience, not the attitude of others.


      > Seriously, though, you're completely
      > missing the point of the article.

      I am beginning to think I did. I thought the article was going to be about scalability, and would point out some nifty Ruby features. Until I clicked the link. I was disappointed - there was no in-depth discussion of scalable code, or the swell object orientation that Ruby offers. There was only a very basic file reading tutorial that does nothing more than skimming the surface. If you're going to write an article about a specific language, at least use something that is specific to it.
      The article in question has nothing to do with scalability, and has little to do with Ruby. The only real connection between Ruby and this article is that Ruby happens to be the language that the author chose to write the examples in. Almost any language could have been used. And when it's about clean, punctuationless syntax, I would prefer Visual Basic.


      > The idea was not to show the best solution
      > to the problem, but rather how Ruby
      > supports some different approaches.

      So it's a programming language with loops, functions, libraries and object orientation. I'm terribly sorry if my expectations are too high, but those are simple features that I expect to be in every modern programming language. Those are not at all specific to Ruby, as even a crappy language like PHP has them. Since when does TIMTOWTDI (There Is More Than One Way To Do It) have anything to do with scalability? A scalable solution only points out the Best Way To Do It, because re-coding something to use a Better Way is a sign of bad scalability. Scaling has to do with expanding and refactoring, not with multiple approaches of the same problem.


      > The scalability the author was talking about
      > stems from being able to attack a
      > problem using different methodologies -
      > procedural, OO, functional... Perhaps
      > the author could have demonstrated this
      > more clearly using some different
      > examples.

      I agree.


      > The fact that Perl, Python,
      > LISP, etc also support some of the same
      > things is irrelevant - the author wasn't
      > making any assertion that they don't. No
      > need to try to start a language war.

      I provided some examples of how Perl "attacks" this "problem". It was not my intention to start a language war, that's just how some readers interpret my reply.


      > Do you think you
      > can write a better article? Then by all
      > means please do so. I would love to read
      > it - and I mean that sincerely.
      > Freshmeat needs more good articles.

      No, I can not write a better article, but I didn't choose to do write one. The author of this article did choose to write something, and when you do so, you can expect some comments, both positive and negative. If negative comments were not welcomed, there should be a warning about that.
      Freshmeat needs more _good_ articles, yes. That's why I think this particular article is deplorable, as in my opinion, the article is not "good".


      > On the other hand, if you're not going to
      > contribute something, don't make
      > bullshit jabs like this at those who do.

      So you think that a reply, complete re-write and negative comments are not a contribution of some sort? I think it does contribute, and so does your reply. Just like in usenet, there's no need to start new threads to be meaningful to the community, and there's no need to act all friendly if you don't mean it. Fortunately, Freshmeat provides a way to comment on articles, and I decided to do so. "Contribute" and "write an article" are not the same, the latter does imply the first though.


      > It serves no purpose other than to make
      > you look like a jerk.

      If that's how you see me, I can probably not alter that image. Hopefully some people understand that comparison of languages is the only way to come to a good decision. Non-coders who want to learn a language will have to pick one to start with, and a good way is to see equivalent code in multiple languages.

      --
      Blaaat :)

      [reply] [top]


        [»] Re: Perl
        by kinginyellow - Apr 16th 2002 08:13:52


        > > Yep, that attitude is why I switched
        > > from Perl to Ruby. ;-)
        >
        >
        > You pick your programming language by
        > the attitute of some programmers that
        > happen to use it?

        I meant that to be facetious, but maybe I didn't make it clear. Although, when I was in grad school, I had to work with a couple of 700 line nightmares written without libraries or classes in Perl. It was horrible. That's more of a reflection on the programmer than on Perl, but Perl does not make modular programming easy for beginners. Maybe that will be different with Perl 6. I hope so.


        > The article in question has nothing to
        > do with scalability, and has little to
        > do with Ruby. The only real connection
        > between Ruby and this article is that
        > Ruby happens to be the language that the
        > author chose to write the examples in.
        >...
        > So it's a programming language with
        > loops, functions, libraries and object
        > orientation. I'm terribly sorry if my
        > expectations are too high, but those are
        > simple features that I expect to be in
        > every modern programming language.
        > ...
        > A scalable solution
        > only points out the Best Way To Do It,
        > because re-coding something to use a
        > Better Way is a sign of bad scalability.
        > Scaling has to do with expanding and
        > refactoring, not with multiple
        > approaches of the same problem.

        You should have said that in your original post.


        > I provided some examples of how Perl
        > "attacks" this
        > "problem". It was not my
        > intention to start a language war,
        > that's just how some readers interpret
        > my reply.

        I think that's mostly because you made a "here's the same thing in x lines of Perl"-type comment. In a language discussion, that's usually a good indication of a troll, though maybe not this time.


        > No, I can not write a better article,
        > but I didn't choose to do write one. The
        > author of this article did choose to
        > write something, and when you do so, you
        > can expect some comments, both positive
        > and negative. If negative comments were
        > not welcomed, there should be a warning
        > about that.

        There's a difference between negative comments on an article and an insult. What you wrote above about refactoring and so forth was a good comment - the "you're giving Ruby a bad name" crack you closed on sounded more like an insult to me. Maybe it wasn't meant that way. Anyway, I didn't intend to imply anything about the value of negative comments. The crux of what I was trying to say is that if you're going to slam an article, you should offer some clear criticisms of it. You didn't do that with your original post, you basically just just wrote some Perl code and said the article was crap. I'll take back my jerk comment, though.

        [reply] [top]


    [»] Re: Perl
    by aotto - Apr 24th 2002 10:54:01

    Hi, just my 2 cents

    I have no experience in ruby and some small experience in perl but very good experience in tcl/tk, shell, sql ...

    I can read the ruby code without any problems I can not read the perl code

    The core problem of perl is perl

    [reply] [top]


      [»] Re: Perl
      by Aristotle Pagaltzis - Aug 3rd 2002 14:30:46


      > I can read the ruby code without any problems
      > I can not read the perl code

      That's because the Perl examples were written with deliberately little red tape. They can be written with as much red tape as the Ruby examples.

      print <>;

      can also be written as

      foreach my $filename (@ARGV) {
          open FH, "     @lines = <FH>;
          print @lines;
      }

      Just because the language allows you to use less red tape doesn't mean you have to forgo it. With most languages, however, you don't have the choice in the first place, and are stuck spelling the same mindnumbing things out over and over and over. Perl does not force anything upon the programmer, it lets them be as non-/verbose as desired. The quality and readability of Perl code depends on the programmer's skill.

      That means Perl is a bad choice for newbies. It also means it's an excellent choice for seasoned programmers who know to write clean code without the need for a bondage and discipline language's confines.

      [reply] [top]


    [»] Re: Perl
    by Matthew Hawkins - Apr 30th 2002 21:44:29


    > "Macros" - A single line of Perl does
    > the same as the given 7-line Ruby
    > example, including error reporting.
    > The code:
    > print <>;

    The 7-line Ruby example is doing exception handling.
    You are not.
    Your Perl is not doing the same thing.


    > "Functions" - Not much trouble. Why
    > even have a function for this?

    Gee, this is a hard one. I'm going to have to think for a while before coming up with an answer to why you would use a function to demonstrate functions.


    > The code:
    > sub printfile
    > {
    > local @ARGV = @_;
    > print <>;
    > }
    > printfile @ARGV;

    Thanks for demonstrating that your Perl function is longer and far less obvious as to what it's doing. Any cretin can read

    print File::open( fileName ).read()

    and understand it is opening a file and reading it.
    What the hell is:

    local @ARGV = @_;
    print <>;

    To the average person, you're overwriting the commandline arguments to your program with a magic token and printing another magic token. (Note: I know Perl and know what its doing, I'm asking from the viewpoint of a casual reader who may not know the language, eg a new employee brought into the team who understands programming but not the specific syntaxes of the particular language being used on the project)


    > "Libraries" - There is no point in
    > having doing simple things in such a
    > complex way.
    > The code:
    > {
    > package FilePrinter;
    >
    > sub print_it {
    > local @ARGV = @_;
    > print <>;
    > }
    > }
    > FilePrinter::print_it @ARGV;

    ... is hardly less complex, even ignoring the line noise with magic tokens that implements your functionality.


    > "Objects" - The author finally
    > discovered that some things are
    > overkill. Oh well, here goes:

    No, the author simply states that an OO version of cat is probably overkill, considering the size of the OO version compared to the initial macro that does the same thing.

    Read: this is an example of why object oriented design is not the be all and end all of programming. It is also an example of how Ruby can provide both procedural and object-oriented approaches anyway (the purpose of the article as stated from the beginning).


    > The code:
    > {
    > package FilePrinter;
    >
    > sub _read {
    > local @ARGV = @_;
    > <>;
    > }
    >
    > sub new {
    > bless [ _read pop ], shift;
    > }
    >
    > sub print_it {
    > print @{shift};
    > }
    > }
    >
    > FilePrinter->new($_)->print_it for @ARGV;
    >
    > Come on, you can do better than this.

    The author did! 8 lines of Ruby versus 14 lines of Perl,
    and your Perl version did not demonstrate inheritance (a very base OO principle) as the Ruby version did. You have taken up 6 more lines of code to do far less functionality, and the Perl implementation is once again unreadable line noise with magic tokens.


    > This has nothing at all to do with
    > scalability

    As many other responders also suspected, you just didn't get it, did you? I suggest next time you don't cram multiple statements onto the one line in an effort to make longer code look shorter, and you provide more credibility to your argument by implementing the exact functionality, not a minor subset, before making a comparison.

    --
    -- Matt

    [reply] [top]


      [»] Re: Perl
      by Aristotle Pagaltzis - Aug 3rd 2002 15:04:07


      > The 7-line Ruby example is doing
      > exception handling. You are not.
      > Your Perl is not doing the same thing.

      Wrong. <> will handle errors automagically.


      > % The code:
      > % sub printfile
      > % {
      > % local @ARGV = @_;
      > % print <>;
      > % }
      > % printfile @ARGV;
      > Thanks for demonstrating that your Perl
      > function is longer and far less obvious
      > as to what it's doing. Any cretin can read
      >
      > print File::open( fileName ).read()
      >
      > and understand it is opening a file and
      > reading it.

      Maybe Juerd should have duplicated the Ruby version closer:
      sub printfile {
      open FH, " print while <FH>;
      }
      printfile $_ for @ARGV;
      which can still be written in a half dozen slightly different ways, each of which can be about twice as verbose as well as half as verbose as the given example, if you so chose. Now what was your point, again?


      > % "Libraries" - There is no point in
      > % having doing simple things in such a
      > % complex way.
      > % The code:
      > % ...
      > ... is hardly less complex, even
      > ignoring the line noise with magic
      > tokens that implements your functionality.

      Are you intentionally missing the point? The "complexity" Juerd was referring to was in creating a library in the first place to solve such a simple problem, and not implying that the Ruby version was much more complex than the Perl one.


      > % "Objects" - The author finally
      > % discovered that some things are
      > % overkill. Oh well, here goes:
      > No, the author simply states that an OO
      > version of cat is probably overkill,
      > considering the size of the OO version
      > compared to the initial macro that does
      > the same thing.
      > Read: this is an example of why object
      > oriented design is not the be all and
      > end all of programming.

      Duh. That's exactly what Juerd was saying - the author finally discovered that using OO to write cat is indeed overkill considering the size of the OO version compared to the initial macro that does the same thing. As was using a function and then a library for this job.


      > and your Perl version did not
      > demonstrate inheritance (a very base OO
      > principle) as the Ruby version did.

      Obviously, since in Ruby everything is based on objects you cannot not use inheritance, so in which way did the sample code demonstrate a feature?

      [reply] [top]


[»] Good to see a Ruby article, wish there was greater depth
by whytheluckystiff - Apr 13th 2002 13:31:13

I see what you're trying to illustrate: how simple it is to restructure your code in Ruby. To make the code become modular. Your examples are indeed quite short. It would be nice to see an article that discussed the growth of an actual script into what is now a established library.

One *truly* good example of maintainable and scalable code is the RubyX11 library by matju. This library is an implementation of the X11 protocol (not Xlib) in Ruby. The author developed a set of base classes that handles the protocol (packing structs and communicating with the server). The rest of his code is all basically metadata that defines the interface classes for the user. It's the most readable code I've ever seen. I was skeptical of how Python and Ruby differed, but the advantages of Ruby became clear to me. Ruby is a practical language whose syntax and typing doesn't get in the way of allowing you to do what you need to do.

I'm also aware that in Python you can similiarly construct classes to appear closer to metadata. I also find Ruby's to be more natural in the context of the language. I give no strikes against Python. It's a fine language, but Ruby's so much more natural for me. Having coded sizeable projects in Perl, PHP, Python and Zope: they are all quite managable but Ruby is a breeze.

[reply] [top]


    [»] Re: Good to see a Ruby article, wish there was greater depth
    by Jack Herrington - Apr 13th 2002 20:17:03


    > I see what you're trying to illustrate:
    > how simple it is to restructure your
    > code in Ruby. To make the code become
    > modular. Your examples are indeed quite
    > short. It would be nice to see an
    > article that discussed the growth of an
    > actual script into what is now a
    > established library.


    You are correct. The first question I get about a language is whether it can 'do everything or not?' The answer to that question is obvious. So I decided focus this introductory article on Ruby on the second question that I get which is, 'can it work on the big projects?' To answer that question I keep the problem constant and slide the solution complexity. Is scalability the right word? Perhaps not, but I hope the point comes through.

    As for the size of the examples. I wanted to keep the article fairly short, so I picked a small problem that is easily understood.

    I have another, much more in-depth article, in the queue that is on text templates. The code samples are larger and I think it's more akin to what you want, an implementation of a library that is moved from simple to grand, but can be useful at any point along the curve dependending on the nature of your problem.

    --
    -Jack D. Herrington Author of "Code Generation in Action" Editor, Code Generation Network, www.codegeneration.net

    [reply] [top]


[»] How does any of this show Ruby is scalable?
by Tom Pinckney - Apr 13th 2002 11:47:19

The example programs never exceed a few lines of code...at best this article showed that ruby can be used for very small projects easily. The only other interpertation that could be made is that the mere presence of classes, name spaces, etc leads to scalability for large projects. But based on that criteria most programming languages are suitable for large tasks and so what is the value add of Ruby?

[reply] [top]


    [»] Re: How does any of this show Ruby is scalable?
    by Jonathan - Apr 13th 2002 12:32:44


    > The example programs never exceed a few
    > lines of code...at best this article
    > showed that ruby can be used for very
    > small projects easily. The only other
    > interpertation that could be made is
    > that the mere presence of classes, name
    > spaces, etc leads to scalability for
    > large projects. But based on that
    > criteria most programming languages are
    > suitable for large tasks and so what is
    > the value add of Ruby?

    The problem is that most object-oriented languages are quite annoying for the small tasks that Perl and Awk are generally used for. Ruby works well for both large and small projects. Give it a try -- Ruby is what Python should have been.

    [reply] [top]


      [»] Re: How does any of this show Ruby is scalable?
      by Ian Bicking - Apr 15th 2002 16:38:07


      > Ruby is what Python should have been.
      I'm not against Ruby or anything, but nothing said here distinguishes Ruby. Very little I've read anywhere distinguishes Ruby. Ruby and Python are both almost identical in all these examples (except for syntax). I was going to write translations (as done with Perl), but found them terribly boring because they were so similar.

      So I'd say Python is what Python should be. It's practical, it's easy, it's elegant. If it's not perfect in all respects, oh well. There's a number of places where Python isn't practical (though really very few, IMHO), but I'd be hard up to find a problem domain where Ruby is significantly better than Python. I could probably give 20 where Python is better -- mostly because of better library and application support. And that's not fair, because libraries aren't the same as languages, but life isn't fair :)

      [reply] [top]


        [»] Re: How does any of this show Ruby is scalable?
        by Aristotle Pagaltzis - Aug 3rd 2002 14:37:17


        > mostly because of better library and application support. And that's not fair, because libraries aren't the same as languages, but life isn't fair :)
        Library and application support is merely a function of time of existance multiplied by community size. The first factor is unchangeable, but the latter depends on the language. I don't see the Python community being very large, so if Ruby really is all that it's made out to be, it shouldn't have trouble catching up to Python in the mid-term.

        [reply] [top]




© Copyright 2007 SourceForge, Inc., All Rights Reserved.
About freshmeat.net •  Privacy Statement •  Terms of Use •  Trademark Guidelines •  Advertise •  Contact Us • 
ThinkGeek •  Slashdot  •  ITMJ •  Linux.com •  NewsForge  •  SourceForge.net  •  Surveys •  Jobs •  PriceGrabber