Highly Recommended Book: The Ruby Programming Language

16 commentsWritten on August 15th, 2010 by
Categories: Books

I first learned about Ruby about 8 years ago, when another programmer that i only knew from some Linux-related forum (yup, i was a die-hard linux user at the time) kept claiming that it was one of the nicest and purest OO languages available. I kept thinking "yeah right, nobody is using Ruby for real stuff so it can't be good". In my defense, i was only 21 at the time and at that age a lot of people can still be quite ignorant at times (or even quite frequently). But that doesn't change the fact that i was just plain stupid.

Fast forward 8 years, and here i am: a developer who was once convinced of the virtues of static languages, but is increasingly frustrated by both the static nature of C# (regardless of the introduction of the dynamic keyword) because of the limits it places on my creativity, as well as the entire .NET world for a variety of reasons. So i figured it was time for me to learn exactly what was so good about these dynamic languages. At first, i doubted between going for Ruby and Python. I picked Ruby, mostly because it has more momentum than Python. And since i hate learning something new from some simple online tutorials, i wanted to get some good books on the subject to make sure i really learned what it was all about. The first book i ordered was The Ruby Programming Language which seems to be the definitive guide to the Ruby language. It ought to be, with that title :)

Books about programming languages are generally pretty boring. It's not the fault of the writers, or the language, it's just because so many boring details need to be covered when learning a new language. I was very happy to see that this book certainly minimizes those boring parts. The book starts off with a quick introduction to Ruby. It very quickly goes over some code with very brief explanations as to what the code is doing. Not sure if everyone will agree on this, but for me it was like the perfect appetizer. It really made me want to learn the language thoroughly.

The next 4 chapters aren't nearly as interesting as the introduction was. The 2nd chapter deals with the structure of Ruby code. Important, but not exactly thrilling to read. The 3rd chapter discusses some of the standard data types and you'll also learn more about how objects work in Ruby. The stuff about objects was very interesting, but the descriptions of the data types are, as they always are, pretty boring. The 4th chapter (Expressions and Operators) and the 5th one (Statements and Control Structures) are also quite boring. But then again, i can't possibly imagine how anyone could write about these kinds of topics in a way that is truly interesting, regardless of the programming language that is used. In fact, i'd say that these topics were dealt with in a manner that is at least less boring than how they're usually covered in programming books. And even though those parts are not the most interesting to read, it is great reference material if you quickly need to figure out something or need to refresh your memory while working with the language.

The next 3 chapters however were (IMO) immensely interesting. Chapter 6 tells you everything you need to know about Methods, Procs, Lambdas and Closures. You might be thinking "how could that possibly be immensely interesting?", but trust me, it is. I also think that this chapter will either strongly increase your appreciation of the Ruby language, or might be a little off putting, depending on how you generally feel about the importance of static typing vs dynamic. Most developers will see the possible dangers here and you'll either feel fear for what people can do in a method, or you'll love the power and flexibility while still recognizing the dangers (with an increased appreciation for automated tests, hopefully).

Chapter 7 deals with everything there is to know about classes and modules, and it's an absolute joy to read. At this point, i really started to feel stupid for not having learned about this years ago. Lots of interesting stuff here, and the ideas it planted in my head are surely gonna hurt me frequently while coding in C# at work. Chapter 8 was even worse in this regard... it discusses Ruby's reflection capabilities and the whole metaprogramming thing. It made my head spin, in the good way. I know i can really take serious advantage of those capabilities and i can't wait to actually experiment with it.

The 9th chapter discusses the Ruby Platform, which is basically a succinct run down of what you can do with a lot of the standard Ruby classes. I largely skipped this chapter since the next book on my reading-list (The Ruby Way) covers all of that and more, in depth. The final chapter covers the Ruby interpreter and the general Ruby environment. It's somewhat interesting, but nothing spectacular.

I generally approach programming language books as necessary reading (at least when you're learning a language) but a chore at the same time. While some of the chapters in this book suffer from a lot of the same problems that you'll find with other programming language books, it at least is less boring to read. Chapter 6 through 8 however are more than worth the cost of the book and could really change the way you think and feel about OO and if i could legally get away with it, i'd force every programmer to read those. It's certainly not going to convince everyone, but it could open a lot of people's eyes. This book is not only ideal to learn the Ruby language, it'll also be an invaluable reference resource to keep on your desk as you keep taking more steps in your Ruby journey.

I already know it's gonna take a long while before this book moves from my desk to my bookshelf.

  • http://blog.dynamicprogrammer.com Hernan Garcia

    Another books on Ruby/Rails I highly recommend are Programming Ruby, Agile web development with rails and The RSpec Book: Behaviour Driven Development with RSpec, Cucumber, and Friends all from the PragProg guys.
    From Manning I like The Well-Grounded Rubyist (although I haven’t finished yet). Some of the material overlaps but the different approaches also help in the learning process.

  • http://davybrion.com Davy Brion

    Thanks, i’ll probably add those to my list :)

    next up are:
    The Ruby Way
    Metaprogramming Ruby
    Ruby Best Practices

  • http://budts.be/weblog Teranex

    I have the Ruby Way and i think it is a *really* interesting book. If i remember correctly Item has the ‘pickaxe’ which seems to be /the/ ruby book, according to the ruby community. (but i can be wrong ;) )

  • Jeremy

    Yes, the pickaxe book should be next. If fact, It should have been first, from what every Ruby pundit has told me. I would love to hear what you think of that one after having read and reviewed this one.

  • Leon Breedt

    Programming Ruby was my intro to Ruby as well, back in the day (2003? 2004? It’s all a blur).

    If you get it, just make sure you match Agile Web Development with Rails with the correct Rails version.

    Only 4th ed will cover the Rails 3 changes, you’ll want 3rd ed for Rails 2.

  • http://computeristsolutions.com josh

    It sounds like it covers very similar material, but I’d highly recommend Well Grounded Rubyist by David Black. Available on Manning.com. It was my first pure Ruby book, and think it was really good.

  • http://davybrion.com Davy Brion

    @Teranex

    you’re right, i found it in the old bookshelf :)

  • http://typesafe.be/ Gino

    At this point, i really started to feel stupid for not having learned about this years ago.

    No more a few weeks ago, I felt just like this. Better late then never, I guess :-) .

  • kilfour

    C# isn’t statically typed, it’s dynamically typed.
    It is however strongly typed.

    Don’t bash strongly typed languages, just because C# get’s it wrong.

    SmallTalk, and I don’t know a lot of ruby, but from what I’ve seen, I reckon there’s a lot of SmallTalk in there, is still one of my favourite languages.
    Weak, dynamical type-system and all.

    One of my other favourite languages is OCaml, strongly and statically typed. But it does not suffer from the restrictions hybrid languages such as C/C++, Java or C# impose.
    I can pass a Dog, a Car, a Furniture or even a BlackHole instance to a function without there being any relation between these things and as long as I only use stuff these classes have in common the compiler sorts this out and will alert me up front if I get it wrong.

    Parametric polymorphism vs ad-hoc polymorphism.
    Both have their merits.

    A metaphor I read on some Haskell tutorial :
    In a weakly typed language every piece of the puzzle is a square and you need to look at the picture everytime you add a piece to make sure it fits (i.e. have an automated test-suite).
    In a strongly typed language each piece has it’s own particular shape, making it a lot harder to initially add it to the picture, but once it’s there, you can be sure it’s in it’s proper place.

    The fact that C# makes you jump through a lot of burning hoops, does not mean that all strongly typed languages suffer from the same inconveniences.

  • kilfour

    I have to correct myself.

    C#/Java/… is weakly, statically typed.
    Ruby/SmallTall/… is weakly, dynamically typed.
    ML/Haskell/.. is strongly, statically typed.

    I.e. in my previous comment I got Weak/Strong and Static/Dynamic confused.

    My main gripe rests however :
    Weakly, statically typed languages are hybrids that usually lead to a lot of unnessary casts, a horrible ‘meta-class’ system and a lot of boiler-plate code.

  • http://davybrion.com Davy Brion

    @Kilfour

    one thing that i find particularly interesting about Ruby (and Python has this too, i’ve been told) is that i can add methods to an existing class if i want to, without having to subclass it. I can change methods of existing classes. I can even remove them. I can generate methods and add them to new or existing classes. And i can do all of this conditionally whenever i want it to happen.

    again, it can be quite dangerous if you do this kind of stuff without proper discipline, preferably a very thorough automated testsuite. But then again, i always aim to have a very thorough automated testsuite in C# as well. So that’s not really an issue for me. In the mean time, i get to benefit from increased productivity, as well as not having my creativity limited because the compiler needs to be kept happy at all times ;)

  • http://braincells2pixels.net Rams

    Thank you for the very timely (for me) review. For the past couple of days I have be agonizing over which book to but to start delving into Ruby which I can no longer ignore. Many of the cross-mobile-platform frameworks (Rhodes) use dynamic languages and Ruby will probably server better than Obj-C.

  • http://blog.dynamicprogrammer.com Hernan Garcia

    @Teranex The ‘pickaxe’ book is Programming Ruby http://is.gd/em96u

    @Davy @Kilfour
    About extending and/or Opening classes; another dynamic language that have the same facilities is JavaScript although implemented a bit differently since is a prototypical language. +1 on having a good suite of tests.

  • Pingback: Book Review: The Ruby Way, Second Edition | The Inquisitive Coder – Davy Brion's Blog

  • Pingback: Recommended Book: IronRuby Unleashed | The Inquisitive Coder – Davy Brion's Blog

  • Anonymous

    This book is quite simply one of the finest software development books anytime written. The style, the length, the scope, and the structure are all absolutely perfect.

    toshiba direct coupon code