The best kittens, technology, and video games blog in the world.

Saturday, April 05, 2014

Review of Ruby Under a Microscope: An Illustrated Guide to Ruby Internals

Cat Pimp by nicora from flickr (CC-NC-ND)

I've been digging my way out of an overwhelming pile of book at pace of about 3 a month - a pace at which I have no chance whatsoever to ever catch up with all the absolutely must read stuff. One book I recently found in my pile was a review copy of Ruby Under a Microscope: An Illustrated Guide to Ruby Internals I got a few months ago, which turned out to be by far the best Ruby book I've ever read.

I'm a little jealous of how easy kids have it these days. I learned Ruby internals back in the 1.6 days - that was the time when most programmers have never even heard of this "Ruby" thing (I'm not kidding you here). To learn anything about Ruby internals you had to dig through macro-heavy and very idiosyncratic C codebase (C/C++ codebases tend to be highly idiosyncratic in general, much more than Java or Ruby or Python codebases), and what little documentation there was was mostly in Japanese. And here someone bothered to write a quality book that explains it all, and well just like that. I've learned a lot about 2.0/2.1, JRuby, and Rubinius from it, even if I was already very familiar with 1.8 series (and had some nonzero level of familiarity with others).

I can see two target audiences for this book. First, advanced Ruby programmers who want to learn Ruby internals - to work on one of the Ruby implementations, or write complex C extensions, or to heavily optimize performance of their Ruby apps.

And second, people who want to write their own programming languages. Ruby implementation is uniquely well-suited for study if you're such a person. It's relatively simple, but implements a highly modern language with all the goodies. Studying something like JVM is basically a waste of time - it's a monstrosity implementing a monstrosity, and half of the features you'll absolutely need in your language you'll have to brutally hack into an unsupportive environment, instead of just cleanly implementing them from first principles. And trying to build your language on top of JVM/LLVM or whatnot, while highly pragmatic, robs you of all the learning experience of writing your own first VM - something I believe any serious CS student should go through at least once.

The book itself assumes you're reasonably familiar with Ruby, but nothing out of ordinary, and as far as C goes it assumes you understand pointers, struct declarations, and basic syntax, and that's about it. That makes it surprisingly approachable considering its subject matter, but I found it really useful even already being familiar with all that (or how it was a few years ago at least). It doesn't bore you with compiler theory, but focuses on actual solutions to actual problems, and invites you to think about how things could possibly be solved. Contrary to what you'd expect, it's meant much more for a cover-to-cover reading than as a reference manual - it's over 300 pages, but it's very heavily illustrated, so it doesn't take that much time.

One big weakness of the book was its chapter about Garbage Collection, which spent far too much time on GC theory and far too little about explaining the interesting bits (like write barriers implementations). I don't think it kept up with standards set up by the rest of the book. And of course many subjects could use some elaboration, but you only get that many pages, and its priorities are relatively sensible.

I'm not sure how complete the book is for someone with no prior exposure to Ruby from the inside - it seems to cover all the basics except maybe C extensions (which would require a lot more C knowledge than the book assumes), but even if something you need to know isn't covered, the hardest part is getting started without being overwhelmed by all the interconnected pieces, and the book will definitely give you that.

If you're in one of two audiences I mentioned, it's practically a must read. I don't think it's terribly useful for people who just hack some Ruby on Rails at work, and aren't terribly interested in going deeper. Sample chapter is available on author's website if you're interested.

tl;dr 5/5 stars

1 comment:

Abir said...

Thanks