Slashdot Mirror


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." Read below for the rest of Tim's review. Beginning Ruby: From Novice to Professional author Peter Cooper pages 631 publisher Apress rating 7 reviewer Tim Hunter ISBN 1590597664 summary An introduction to Ruby programming

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.

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.

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

You can purchase Beginning Ruby: From Novice to Professional from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

10 of 172 comments (clear)

  1. Re:Ruby as a first language? by EveryNickIsTaken · · Score: 1, Informative

    Uh, right. Go ahead and mod me down. Apparently "I disagree with you" is now used for -1 point "Troll." The bottom line is, no newb to programming is going to pick this is their first.

  2. Re:Ruby as a first language? by solevita · · Score: 3, Informative

    Uh, right. Go ahead and mod me down. Apparently "I disagree with you" is now used for -1 point "Troll." The bottom line is, no newb to programming is going to pick this is their first.
    You didn't really argue your point, apart from saying "puh-leaze", so it's hard to describe your post as anything other than trolling. Maybe flamebait, I guess.

    I'm seriously considering starting programming with Ruby and plan to look on Amazon later this evening for this book. Do you have any eloquent reason why I shouldn't?
  3. Re:I would rather have.... by drix · · Score: 2, Informative

    Well, you're in luck.

    --

    I think there is a world market for maybe five personal web logs.
  4. Re:Enlighten me by plams · · Score: 4, Informative

    Ruby isn't any more a server-side language than 68k assembler is. You've probably confused it with Ruby on Rails which is a framework (and an excellent one, I might add) for making websites. Compared to plain PHP it makes web development easy and fun and even supports stuff like AJAX out of the box.

  5. Re:Enlighten me by BrewerDude · · Score: 4, Informative

    Hi

    First, Ruby != Rails. Ruby is the programming language. Rails (or Ruby on Rails) is the web development framework. Ruby has been around a lot longer than Rails, but has certainly had it's popularity boosted by the buzz surrounding Rails.

    Second, I'd disagree that system performance is the biggest factor is selecting a web framework. Rails out of the box will support the load more most websites. There are many things that you can do to tune performance once you start getting enough page views for it to matter: caching pages, selectively replacing ActiveRecord's queries with raw SQL, etc. There are also people starting to focus on rails performance both from a developer's standpoint (e.g., the Rails Express Blog) and from the hosting standpoint (e.g., Engine Yard).

    To me, the first and foremost goal of building a website is to get the functionality there quick in order to attract users. Once you've got that, and have rapidly been able to iterate to what the users want to see, then you can start worrying about performance. And, if your site really makes it big, you are going to have to do custom tuning work no matter what framework you've chosen.

    Personally, I've found Rails to be a wonderfully productive framework to use for web development

  6. Re:Enlighten me by CastrTroy · · Score: 4, Informative

    PHP isn't a framework. It's a programming language. You made the same mistake your parent did. You're comparing a framework (RoR) to a langauge (PHP). If you want to compare them, you'll have to compare it to another framework, like CakePHP.

    --

    Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
  7. Re:Ruby astroturfing by plams · · Score: 3, Informative

    Define "high usage website". RoR-powered sites like 43 Things and ODEO don't seem like backyard hobby projects to me.

  8. Re:It would be a great first language by partenon · · Score: 2, Informative

    You can have 1, 2 and 3 in Ruby without knowing the others. And it would be a pleasant surprise to learn 4, 5, 6 and see that Ruby implemented 1, 2, 3 using them (OOP) :-)

    --
    ilex paraguariensis for all
  9. Re:It would be a great first language by Serious+Callers+Only · · Score: 2, Informative

    Very few languages let you do the first three without worrying about classes and/or functions. If you pick Java as your first programming language you'll have to learn about classes and functions, even to just write your first hello world program. You won't have to know very much, but it's easier to grasp these concepts one at a time. Therefore, I find a good progression of languages to be Basic, C, Java (Or C#,VB.Net,any other OO Language).


    I don't see why you think Ruby would make any of that difficult - perhaps you're getting Ruby mixed up with other languages, it's one of the better ones to learn with in my opinion. In the interactive ruby shell (irb) you can learn this stuff easily:

    1. Learn about variables and doing simple math

    irb > 2+2
    => 4
    irb > x = 3
    => 3
    irb > y = 2
    => 2
    irb > x + y
    => 5

    2. Learn about conditional statements

    irb > if (x > 2)
    irb > y = 10
    irb > end
    => 10
    irb > x + y
    => 13

    3. Learn about looping structures

    irb > 2.times do
    irb * puts "Hello world"
    irb > end
    Hello world
    Hello world

    irb > ["jan","feb","march","april"].each do | month |
    irb * puts month
    irb > end
    jan
    feb
    march
    april

    4. Learn about functions

    irb > def max(a,b)
    irb > if a > b
    irb > a
    irb > else
    irb * b
    irb > end
    irb > end
    => nil
    irb > m = max(4,8)
    => 8
  10. Re:When you step back and consider history by shutdown+-p+now · · Score: 2, Informative

    Sure, but that's not to say they overlap in the same places. I've never come across two programming languages with exactly the same strengths and weaknesses.
    There are plenty of pairs where difference are marginal, though. Say, C# and Java.

    Whatever it is, I'm hoping it will be functional ;)
    C# has first-class functions and lambdas already, and will get neat syntax for them in v3.0. Java is going to get lambdas in the next version. Even C++0x is going to get something similar, though not with true closure semantics. You don't have to wait for the Next Big Thing for functional stuff - it's already here, in the mainstream languages. It just doesn't look as neat as Haskell does, but you shouldn't care all that much about the looks.