Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror

The Ruby Way 81

Posted by samzenpus
from the way-she-goes-boys dept.
Tim Hunter writes "Hal Fulton's The Ruby Way, Second Edition doesn't try to be the only book a Ruby programmer needs. It tries to be a book every serious Ruby programmer needs, and it succeeds. The Ruby Way is a book about programming with Ruby, the object-oriented programming language from Japan. Ruby is free software and runs on Linux, Microsoft Windows, Apple OS X, and other operating systems. It is available for download from its web site, www.ruby-lang.org or its companion site www.rubyforge.org. Read the rest of Tim's review.
The Ruby Way, Second Edition
author Hal Fulton
pages 839
publisher Addison-Wesley
rating 9
reviewer Tim Hunter
ISBN 0-672-32884-4
summary A task-oriented book about the Ruby programming language


I read the first edition of The Ruby Way when it was published in 2002, not long after I starting programming in Ruby. I was a member of the discussion group Fulton organized during the writing of this edition. I am also the author of RMagick, one of the libraries described in this book, and did the technical review of that section.

This is a review of the second edition of The Ruby Way. The first edition described the then-current Ruby syntax and libraries and showed novice Ruby programmers how to perform common programming tasks. In the past four years Ruby has evolved and its community has grown immensely. Consequently, the first edition was starting to look a little long in the tooth and the Ruby community has been eager for the appearance of a new edition. This edition is almost a complete rewrite. Saying that it's 260 pages longer minimizes the actual scope of the changes. There are a dozen new chapters. Some of the new material expands on topics that were present in the older work, like regular expressions and data structures. However, much of the new material covers topics that simply didn't exist 4 years ago, such as Ruby's XML and RSS libraries, RubyGems (Ruby's answer to CPAN), and Rake, the Ruby version of make.

The Ruby Way doesn't try to teach how to program in Ruby. For that, you need Dave Thomas' Programming Ruby: The Pragmatic Programmer's Guide or a similar book. The goal of The Ruby Way is nothing less than describing the universe around the Ruby programming language. In one 800+ page volume, it describes Ruby's design principles, history, syntax, built-in classes, standard libraries, 3rd-party add-on libraries, related development tools, and user community. The examples and Fulton's explanations emphasize Ruby programming best practices, hence the title.

Fulton describes The Ruby Way as an "inverted reference." A typical reference book for a programming language lists the libraries, classes and methods by name, which you can use to discover their purpose. The Ruby Way, on the other hand, groups Ruby's libraries, classes and methods by purpose, from which you can discover their names. Section titles tend to describe tasks, such as "Tokenizing a String" and "Interacting with an IMAP Server". The sections then describe the split method in the String class and the net/imap library, respectively. Several chapters group Ruby libraries by related tasks. For example, Chapter 15 describes Ruby libraries used to process specialized data formats such as XML, RSS, images, and PDF. In this chapter you will learn that XML processing in Ruby is typically done with REXML and that PDF files can be created with PDF::Writer, etc. Organizing topics by purpose or function instead of by name makes it easy to discover what parts of Ruby you need to complete a task.

Unlike many of the 2-inch thick books about programming for sale lately, there is no fat in The Ruby Way. It hits the ground running with an introduction to object oriented programming and a whirlwind tour of Ruby syntax. It covers Ruby's built-in classes in considerable depth. The String class gets an entire chapter, as do regular expressions. Array and Hash rate yet another chapter. Fulton continues with an in-depth survey of Ruby's extensive standard library. Interested in object persistence? Chapter 10 describes Ruby's YAML library. Wondering about unit testing? Go to Chapter 16 to read about the Test::Unit library. One of the most frequently asked questions to the ruby-lang mailing list is "what GUI libraries are there for Ruby?" Chapter 12 supplies sample applications that demonstrate graphical interface libraries such as Ruby/Tk, FXRuby, and QtRuby. Chapter 19 is dedicated to web application development tools ranging from the famous Ruby on Rails to the lesser-known but equally useful Nitro. Chapter 22, "The Ruby Community," tells where other Ruby programmers hang out. Catering to his programmer audience, Fulton peppers each section with code snippets and complete example programs. (The source code for the book can be downloaded from Fulton's web page.)

Although Ruby is thought to be a "Linux-centric" language it also has a large audience in the Microsoft Windows community. Fulton addresses these users' needs with a description of the "One-Click Ruby Installer" for Windows. This description is accompanied by a section about the Ruby libraries available for scripting on Windows. For example, Fulton shows how to open a file dialog box using the Win32OLE library.

Fulton says that he doesn't expect anybody to read his book from front-to-back. Nevertheless The Ruby Way is quite readable and (if not for its considerable weight) would make a good book for browsing while waiting for the bus, or between classes. Some sections contain a surprising amount of general background information, such as the remarkably in-depth description of Unicode in Chapter 4. Not content to simply educate the reader, Fulton continues his practice in the 1st edition of entertaining the reader with thoughtfully chosen quotes, geek humor, and personal observations.

Is there anything not to like about this book? Well, to be perfectly honest I occasionally found myself wondering if sometimes Fulton spread himself too thin. The amount of coverage for individual classes and libraries varies widely. Some of the standard libraries, like REXML, get several pages of description and an accompanying example while others, such as open-uri, get only a cursory introduction and a pointer to the on-line documentation. At 4 pages, the section on Rails is perfunctory and, given the number of very good books already available on the subject, redundant. (Fulton himself says the material is "cursory.") I have to wonder if it isn't there simply because "everybody" expects books about Ruby to say something about Rails. Similarly he devotes a single page to ActiveRecord, which, as a part of Ruby on Rails, is capably documented elsewhere. That page would've been better used to double the number of pages spent on Og, another Ruby ORM which is not so richly documented.

I recommend this book to any programmer who has already learned the basics of Ruby syntax and its built in classes and who wants to learn more about using Ruby to accomplish typical programming tasks. While it will be particularly useful to the novice Ruby programmer, it is a handy reference for Rubyists at any level of experience.


You can purchase The Ruby Way, Second Edition from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived. No new comments can be posted.

The Ruby Way

Comments Filter:
  • by Zarniwoop_Editor (791568) on Wednesday November 08, 2006 @01:11PM (#16771383) Homepage
    I only became aware of Ruby and Rails a few short weeks ago. Since then I have already built my first Ruby/Rails website http://www.f1newstoday.com/ [f1newstoday.com] and it was the most enjoyable experience I've had for some time. The site seems to perform well so far and developing it with Rails was very very quick and easy.

    Sure, It's a shameless plug for my site but I'm just so jazzed about Ruby and Rails lately I just had to share.

  • by Anonymous Coward on Wednesday November 08, 2006 @01:16PM (#16771477)
    My god do we love Ruby here in our company. We've been slowly dumping all of our old and messy Perl scripts and replacing them with Ruby versions.

    Such a nice clean feeling. There were a few Perl specific libraries that held up the process, but the Ruby libraries have rapidly come of age and I don't know of anything now that would keep someone from completely migrating from Perl to Ruby.

    I just cringe when I come across Perl code these days.

  • Re:Ruby! (Score:3, Interesting)

    by sammy baby (14909) on Wednesday November 08, 2006 @01:28PM (#16771689) Journal
    Perl and Ruby have a lot in common, but they also have some extremely big differences. Probably the biggest is that Ruby is a real, honest to god Object Oriented Language. Perl ain't - it's object support is essentially bolted on. Good if you're not a big fan of objects, bad if you're not.

    For a better list of differences/similarities, try here [ruby-lang.org].
  • Re:Ruby! (Score:2, Interesting)

    by Cafe Alpha (891670) on Wednesday November 08, 2006 @01:42PM (#16771933) Journal
    I think of Ruby as being more like common-lisp, without the horrible, unreadable S-expression syntax (good as that is for automated code analysis, it's hell on humans). It does have regular expressions though, which I suppose seems familiar to Perl programmers.
  • Re:Ruby! (Score:5, Interesting)

    by Enahs (1606) on Wednesday November 08, 2006 @01:51PM (#16772143) Journal
    I think once YARV is ready for general consumption, it'll take off like wildfire. They're doing a lot of cleanup, and it'll be considerably faster than the current Ruby.

    Once you look beyond Rails, you find it's a great language. Whether it'll overtake Perl and/or Python remains to be seen, but for what little scripting I do on a regular basis, I'd die if I had to use anything other than Ruby.
  • Re:Ruby! (Score:3, Interesting)

    by porkThreeWays (895269) on Wednesday November 08, 2006 @01:57PM (#16772317)
    Ok I know no one is actually going to discuss the book and just discuss Ruby so I'll partake!

    I'm going to come out and say it. Ruby is a badass language. Forget Rails. Ruby isn't Rails. Ruby was badass way before Rails ever became popular. It's nice to see a usable, clean language that truly is 100% object oriented. So many other languages claim to be object oriented but are actually a hybrid language (Java, Python, C#). The fact that Ruby's creator had enough insight to weave regular expressions right into the language (via ~ operator) is very important. It's annoying to compile regular expressions and have to deal with raw strings and other gotchas. I like to match with =~ and have it return $1 $2 $3. Object oriented regular expressions still exist and actually ~ is just a shortcut. I also like the convention using exclamation marks for in place modification. So chomp returns the chomp'd argument while chomp! modifies in place. Other languages it can be a guessing game whether it's going to modify in place or not.

    All in all Ruby is one of the most fantastic languages I have ever dealt with.

    Now for the bad news... While the language design was magnificent, there are pragmatic issues that keep me from using it a lot. I'm going to compare it to Perl and Python because Ruby would be most attractive to that crowd. While the language itself is mature, it wasn't until a few years ago that Ruby was translated to English (the documentation anyway). So even though it's been around awhile, it's only picked up steam recently. This means the actual implementation of Ruby isn't nearly as mature. It's much slower than Python and much much slower than Perl. There are serious projects in place to solve this issue, but as it stands today it's somewhat slow. Also, (and this is the biggest reason) there just aren't a whole lot of supporting libraries out there (compared to Python and Perl anyway). Since it is somewhat new in popularity you can't really assume it's easy to get. So code that has to run on a lot of machines (usually Unix and Linux flavors), it may be a lot of work for them to install it. We have some older Linux and Unix installs, and most have Python and they all have Perl. None have Ruby and very few have a native package available.

    But there is hope! All the above mentioned problems are just due to Ruby's youngness. Python was in a very similar situation a few years ago. Ruby has a pretty good snowball it's building. It's immensely better than just 3 years ago, and I think 3 years from now it will have reached mature Python status.
  • by chromatic (9471) on Wednesday November 08, 2006 @02:19PM (#16772867) Homepage

    A language that came out slightly before Java did is new?

  • by misleb (129952) on Wednesday November 08, 2006 @03:54PM (#16774819)
    The good news is that he doesn't have an index.php [f1newstoday.com], unlike certain other sites [rubyonrails.org]...


    Please note that rails is a framework intended for web applications, not web sites with small bits of dynamic content. So it isn't necessarily damning that the Rails website is written in PHP. Use the right tool for the job. For simple, dynamic content PHP works just fine where Rail would be overkill.

    -matthew
  • by misleb (129952) on Wednesday November 08, 2006 @04:21PM (#16775399)
    Ruby has a lot of work in the library department, and a HELL of a lot of work in the documentation department.


    I never really understood the documentation complaint about Ruby (I use Rails, mostly). Most everything I need to know about the core libs is in http://www.ruby-doc.org/ [ruby-doc.org] and http://api.rubyonrails.com/ [rubyonrails.com] is nearly complete. It is no worse than the PHP online documentation. Actually, it is better. I find RDoc much faster to search (CTRL-F). And you can get the first edition of the book, Programming Ruby: The Pragmatic Programmer's Guide online at http://www.rubycentral.com/book/ [rubycentral.com] to get more in depth knowledge of how Ruby works. The IRC channels are very active and helpful (I help lots of people there myself). There is a great mailing list/form at http://www.ruby-forum.com/forum/3 [ruby-forum.com] And there are a million Rails tutorial out there. I learned Ruby/Rails to a point where I could do useful things in like 5 days without any prior exposure with no hassle. So what is missing, exactly?

    -matthew
  • Re:Ruby! (Score:2, Interesting)

    by Cafe Alpha (891670) on Wednesday November 08, 2006 @07:28PM (#16778025) Journal
    There are alternatives.

    I'm starting a project adapting the strongtalk vm [strongtalk.org] to Ruby.

    The strongtalk vm is based a very sophisticated new technique called type-feedback, where statistics are taken on the program while it runs, and inlining, specialization and other optimization take placed based on what types are seen to be the common cases in running code.

    Probably the most exotic thing the VM does deoptimize running code (for debugging and when the definitions of classes change in a way that invalidates the optimizations), because it actually transforms the activation records on the stack (rewrites the stack!) in order to match the transformation of the object code.

    Currently Strongtalk only runs on Windows, and it's not entirely debugged, but it is working and fast. It would need some extensions for Ruby, but even YARV lacks support for continuations...

    Another much-better-than-most compiler that I may adapt to Ruby is Steel Bank Common Lisp. [sbcl.org] It runs on all Unix platforms and is the fastest lisp. It's a more conventional compiler than the Strongtalk VM. I think it's optimizations are all static, and so it can't do much with optimizing polymorphic calls, unlike strongtalk, but it's static optimizations are very good.

Our business is run on trust. We trust you will pay in advance.

Working...