Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror

Submission Summary: 0 pending, 3 declined, 3 accepted (6 total, 50.00% accepted)

Programming

Submission + - Practical Ruby Gems, by David Berube

TimHunter writes: "I was skeptical when I first saw the title of David Berube's new book, Practical Ruby Gems, from Apress. Do Ruby programmers really need a book devoted entirely to add-on libraries? Most Ruby programmers already know about the RubyGems package management system, and most already have their set of favorite gems. But, about a third of the way through the book I grudgingly admitted that Rubyists might be able to use this book. After all, even long-time Ruby programmers are unlikely to know about all the gems covered in this book. So then I had a new question. Would I find something in this book that made me say "I didn't know you can do that with Ruby!"

Ruby is an object-oriented programming language in the same family as Perl and Python. The programming language used by Ruby on Rails, Ruby is very popular for writing web applications but also widely used for general-purpose programming tasks. Ruby is open source with a commercially friendly license, and is available for Linux, Mac OS X, and Microsoft Windows. RubyGems is Ruby's system for managing, delivering, and installing third-party libraries and applications. It is similar to Perl's CPAN or the Python Package Manager.

Libraries distributed by RubyGems are called "gems." RubyForge is the central Ruby software repository and the primary distributor of gems. According to sysadmin Tom Copeland, RubyForge currently hosts about 1400 different gems. Of that number, Berube selected 29 useful and interesting libraries for his survey of "practical" gems. All of the gems described in this book work the same on Linux, OS X, and Windows.

Practical Ruby Gems is divided into three parts. Part 1 describes the RubyGems system itself. This part explains how to install the RubyGems software and then use RubyGems to install and manage individual gems. (RubyGems is not part of Ruby's standard distribution, except in the "one-click installer" for Microsoft Windows.) The section entitled "What is require_gem?" in Chapter 3 demonstrates one of the problems with writing technical documentation for a moving target like RubyGems. Practical Ruby Gems describes RubyGems 0.9.0. After the book went to press the RubyGems team released a new version that replaced the require_gem method with a method called simply gem. Currently all uses of require_gem generate a warning message. (The remedy for this mistake is simple: attach a yellow sticky with the words "s/require_gem/gem/g" to page 20.) This is really a nitpick, though. Generally the text and examples in the book work as well for the new release as they did for 0.9.0.

Part 2 is by far the largest and has a chapter devoted to each of the 29 gems. The chapters in this part share a common structure. After a short introduction to the gem, there is a section entitled "How Does It Work?" which explains the purpose of the gem and how it's used. Frequently this section includes a small example. "How Does It Work?" is followed by a complete example script. Then, "Dissecting the Example" steps through each part of the example, explaining how it works and pointing out important classes and methods. The examples frequently combine two or more gems, such as the example for pdf-writer, which also uses the net-sftp gem, and the example for the mongrel web server gem, which also uses the Camping web micro-framework gem.

The examples — always practical, frequently interesting, at least to a geek like me — are the heart of the book. Berube said that "no one wants to pay to read a chapter that regurgitates [the gem's built-in documentation]....I wanted to write a book that you could take the examples and actually be interested in what they accomplished." For instance, Chapter 6 describes the BlueCloth text-to-HTML conversion gem. The example in this chapter is a script that converts lightly marked-up text to PDF by combining BlueCloth with html2ps and ghostscript. Chapter 12 describes the yahoofinance gem, a library for retrieving stock quotes using the Yahoo! Finance API. The example for this library combines yahoofinance with the fxruby GUI library to produce a rudimentary stock ticker in less than 100 lines of code. (The source code for all of the examples in the book can be downloaded from the Apress web site.)

But not every example is perfect. Several of the examples rely on MySQL, which I found a chore to install. I wish Berube had chosen a simpler data base for these examples. I never did get the Camping example to run successfully. I suspect the problem was caused by some change to a gem introduced after the book went to press.

In Chapter 22 I got my "you can do that with Ruby?" moment. This chapter explains runt, a Ruby library for creating "temporal expressions," objects that describe dates that reoccur, such as "every Thursday" or "the last Thursday of every month." The example combines runt with linguistics, a small gem that extends some of the Ruby core classes with methods that support such things as pluralization and conversion from numbers to words. The result is a program that lists a set of dates expressed as "the 3rd Mondays of 2026." I was impressed by both gems, not only for the functionality they provide but by their natural and elegant interfaces as expressed in the example script. I not only learned about two very practical Ruby gems, but something about Ruby programming itself. This particular example may not strike everybody the way it did me, but I believe that most readers will find an equally pleasant surprise.

Part 3 is a tiny, advanced topics section which describes how to create and distribute your own Ruby gems and how to run a private gem server on a local network.

Practical Ruby Gems is not for the novice. Berube assumes that his reader is familiar with programming in general and Ruby specifically, and is also familiar with the operating system in which Ruby is running. This is an appropriate assumption because Practical Ruby Gems will be most useful to readers who are serious about programming Ruby, such as professionals or serious amateurs, or those would like to become professionals or serious amateurs. For that readership, I'm giving the book an 8 out of 10.

Practical Ruby Gems is available in PDF format from the Apress web site at about half the price of the paper book.

I have been programming Ruby as a hobby for over 5 years. I am the maintainer of RMagick, one of the gems reviewed in this book. Apress gave me a review copy of Practical Ruby Gems, but otherwise I have no connection to the author or publisher."
Programming

Submission + - Beginning Ruby

TimHunter writes: "Peter Cooper's Beginning Ruby: From Novice to Professional has two audiences, novices with no programming experience who want to learn Ruby as their first programming language, and veterans who want to add Ruby to their programming toolkit. Cooper's response to this challenge is a solid entry in the limited arena of Ruby tutorials. Even though the early chapters are marred by the occasional reference to an advanced topic, readers will appreciate the plentiful examples and thoughtful description of the Ruby language.

Ruby is an object-oriented programming language in the same family as Perl and Python. Ruby is very popular for writing web applications but also widely used for the general-purpose programming tasks. Ruby is available for Linux, Mac OS X, and Microsoft Windows. It is Open Source software with a commercially friendly license.

I agreed to review this book in particular because, even though the Ruby community has a strong tradition of encouraging newcomers, there are actually very few resources for the Ruby beginner. Ruby has gained a repuation for being easy to learn and therefore is attractive to people with limited or no programming experience. Novice programmers post almost daily requests for help and direction to the ruby-lang mailing list. Responses usually include pointers to why the lucky stiff's Why's (Poignant) Guide to Ruby and Chris Pine's Learn To Program , both of which have been around for several years. Newcomers to the field of Ruby tutoring are Satish Talim's Learning Ruby which bills itself as "study notes" for Ruby, and the infant Ruby Mentor project which tries to couple novices with experienced Ruby programmers for one-on-one help. However, although the (Poignant) Guide is unquestionably a work of art, its reliance on allegory hinders literal-minded newcomers. Learn To Program covers only the most basic programming concepts. The Ruby Mentor project is well-intentioned but it's too soon to tell if it will be effective or not. In short, in the small pond of elementary Ruby tutorials, Beginning Ruby has an opportunity to make a big splash.

In addition to serving people with no progamming experience, Beginning Ruby is also aimed at experienced programmers who want to learn Ruby. Progammers coming from languages such as Java or C++ often struggle with Ruby's dynamic typing and (even with the recent explosion of Ruby-related books) the relative scarcity of documentation. Beginning Ruby tries to satisfy this audience by explaining Ruby's design, history and place in the programming world and including an extensive survey of the currently-available Ruby libraries.

Beginning Ruby is divided into 3 parts. The first part is aimed at neophytes. Experienced programmers, especially those experienced with object-oriented programming, will be able to skip chapter 2 and skim chapters 3 and 4.

The book starts simply. Chapter 1 isn't even about programming. This chapter explains how to install Ruby on Windows, OS X, and Linux. The instructions are thorough and aimed squarely at beginners. For example, Cooper explains how to get a command prompt on Windows and how to run Terminal.app on OS X.

Chapters 2 and 3 introduce fundamental concepts such as variables, expressions, control flow, classes, and objects. Cooper emphasizes experimentation. He says that irb, Ruby's interactive programming module, "provides the perfect environment for tweaking and testing the language, as you cannot do any real damage from within irb." Such assurances are helpful, especially to the beginner who may be slightly afraid that he's going to somehow make a mistake that will "break" his computer.

Explaining programming to beginners is hard. I've read a number of books that try to teach object-oriented programming concepts to people with no programming experience whatsoever. None were stunningly successful. This one isn't either. The problem is that books are linear, but there are simply too many things – concepts, keywords, tools – that have to be introduced nearly simultaneously and initially taken on faith. Cooper distracts his readers by peppering his text with too many "don't worry about this yet" disclaimers and assurances that explanations will appear later. His references C and Perl will be meaningless and possibly confusing to the beginning programmer.

Chapter 4, "Developing a Basic Ruby Application," starts by explaining what a text editor is and offering a few recommendations for text editors on Windows, OS X, and Linux. Then it guides the reader through his first real program, a script to read a text file and compute simple statistics such as the number of lines and words. This is a well-chosen example that will, when completed, make the student feel like he's accomplished something.

Chapter 5, "The Ruby Ecosystem," feels out-of-place. This chapter doesn't teach anything about Ruby programming. Instead it explains Ruby's history, introduces Ruby On Rails, and talks about the Open Source movement. Little, if any, of this material will be interesting to a fledgling programmer. The chapter finishes with a list of internet-based Ruby resources such as mailing lists, IRC, and blogs. All of this seems much better suited as an appendix and indeed the list of resources appears again in Appendix C.

Part 2, "The Core of Ruby," has a slower pace. With the very basic material covered, Beginning Ruby gets a better footing. Starting in this part the material is useful to both beginners and veterans.

This is probably as good a place as any to talk about the examples, which are numerous and very likely the best part of the book. Most of the the examples are short and to the point. A few extend over several pages. My overall impression is that they are well-chosen and well-coded. I especially like the way the examples appear on the page, visually distinctive but without interrupting the flow of the text. Source code for all of the examples may be downloaded from the Apress web site. However, even though the files are divided into a directory per chapter, the examples aren't numbered in the text so it's difficult to find the code for the example you're looking at. I ended up using grep to search for keywords in the sources.

Chapter 6 is a slower pass through Ruby, focusing on Ruby's object-orientation. Though fewer than part 1, there are still problems with references to concepts that have not yet been introduced. For example, Cooper uses the require method in the context of namespaces even though require has not been introduced. Indeed, it's not even necessary to mention namespaces at all in this chapter since the entire concept could've been held off until the next chapter, which explains how to create programs from code in multiple files.

The remaining chapters in this part start to address the needs of the serious Ruby programmer. This is a lot of ground to cover, including documentation, debugging, test-driven development, I/O, databases, and how to deploy Ruby programs. I particularly liked Cooper's thorough instructions for installing and creating RubyGems, Ruby's third-part library management system. There are so many topics to cover that each one gets only an introduction, but Cooper uniformly provides links to extended online documentation.

The last chapter in this part works through an even larger example, a Ruby "chat bot." This is an ingenious and entertaining example, the kind of program that, had I read it when I was just starting to learn programming, would have spent many happy hours tweaking. Call me a geek, but I got a chuckle out of the example on page 383 of two very stupid bots conversing.

Part 3 is called "Ruby Online." Of course it starts with the obligatory chapter on Ruby on Rails. I suppose publishers require such a chapter in all Ruby books, even though RoR is more than amply covered by other excellent books. I'm not a RoR programmer so I blew off this chapter.

Chapter 14 describes Ruby's support for the Internet via its HTTP, email, and FTP libraries. Chapter 15 covers other networking support libraries. As usual there are many excellent examples. Chapter 16 is a very good survey of the standard and add-on libraries that the serious Ruby programmer will find useful. Each library is demonstrated with an example, and Cooper provides a link to the complete documentation.

At the start of this review I said that Beginning Ruby is divided into 3 parts, but actually there are four. The last part consists of 3 appendices. Appendix A is a summarization of Part 2. Appendix B is sort of a "semi-reference" to Ruby's core libraries. This is not intended to be a complete reference. Instead, Cooper limits his discussion to the most useful methods of the core classes. As I mentioned earlier, Appendix C is a list of Internet-based Ruby resources such as web pages, mailing lists, IRC channels, and blogs.

Bottom line: I'm giving Beginning Ruby a 7. It's a good book for someone who wants to learn Ruby as his first programming language. It could be better. I liked Cooper's patient and thoughtful explanations about installing Ruby and RubyGems, how to use a command line, and what a text editor is for. Cooper supplies answers to all the typical Ruby-nuby questions, but his explanation of basic concepts is marred by the occasional confusing reference to advanced or even irrelevant topics. For the experienced programmer who learns best by reading and working through examples this book is a good choice. Dave Thomas' Programming Ruby, The Pragmatic Programmer's Guide (a.k.a. the Pickaxe) is a tough competitor, but each book has a considerable amount of material that is not found in the other book. For example the Pickaxe's core library reference is exhaustive but it has only a limited amount of the kind of tutorial explanations that is Beginning Ruby's strength.

Beginning Ruby is available in PDF format from Apress' web site at about half the price of the paper book.

I have been programming Ruby as a hobby for over 5 years. Apress gave me a review copy of this book, but otherwise I have no connection to the author or publisher."
Programming

Submission + - The Ruby Way, Second Edition

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. 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.

[EDITORS, PLEASE NOTE — Please only print my obfuscated address!]"

Slashdot Top Deals

Honesty is for the most part less profitable than dishonesty. -- Plato

Working...