Metaprogramming Ruby 2

Author: Paolo Perrotta
Publisher:  Pragmatic Bookshelf
ISBN: 978-1941222126
Print: 1941222129
Kindle: B00N9I0RMQ
Audience:Ruby programmers
Rating: 5
Reviewer: Ian Elliot

A second edition of a book that claims to teach you "meta" programming. Isn't just programming hard enough?!

You will often hear Ruby programmers say that Ruby is special - this book explains what makes it special and how to make use of these special abilities. It has reached its second edition and it is still the best book on the topic. 

It has a strange style that you need to be warned about this. The entire book takes the form of a tutorial between a master programmer called Bill and his increasingly skilled assistant, i.e. you. The task is to build some software for a remarkably knowledgeable boss figure. Unlike most attempts at this method of presenting technical information, it works!

It is sufficiently well done for it to be a help in explaining some fairly complicated ideas. Even so there were times when I really would have liked a quick simple and direct explanation of what is going on. There are plenty of summaries and overviews, but these are generally placed a page or two ahead of the main narrative.




Metaprogramming has long been regarded as dangerous. It is easier to create a metaprogramming mess than it is to create something easy to understand, easy to debug and modify. Most of the time the ideas and techniques are introduced with a correct degree of caution about the impact of metaprogramming on the system as a whole. However, there are moments when you really should worry about letting this particular genie out of the bottle. 

The first section of the book works its way though the various standard metaprogramming techniques. Each chapter is given the name of a day of the week and the idea is that it takes you through what was necessary to implement an application. Monday introduces the Ruby object model and provides the foundation that a lot of what follows is built on. Tuesday is all about methods - how Ruby works out which method to call and in what context. Here we meet one of the main tools in the metaprogramming toolkit - missing methods. Wednesday is all about blocks - which is a very Ruby idea. However, you do end up seeing blocks as a much more integral part of the language than they seem when you are first introduced to them. The example used is of a simple Domain Specific Language (DSL) and if you have always thought that DSL were a waste of time be prepared to think again. Thursday is also about Class and how the type system works in Ruby. Friday is hardcore metaprogramming as we finally get to code that writes code - scary stuff made to seem very reasonable.

The second part of the book is about Rails and is the only part of the book that has been heavily changed in the second edition. I starts with a tour of Rails and then moves on to ActiveRecord, which is a core Ruby system that makes heavy use of metaprogramming. The new chapters are on the Concern Module, alias_method_chain, Arttribute methods and a final round out. 

The Appendixes are far more useful than you find in most books and are listed as Part III. The first goes over common Ruby idioms and not just metaprogramming idioms. The second is an introduction and advocate of DSLs - if you haven't encountered the ideas before then this is the place to start. The final appendix is a collection of "spells" - small patterns of metaprogramming use. All really useful.




If I have to find a fault with the book then its that it is a bit too enthusiastic about Ruby. If you are a Ruby fan then you will simply agree but if you are trying to see what the fuss is about then it could just put you off. It would have been better to tone it down just a touch.

This is a book that will take you from a Ruby novice to an expert, especially if you have migrated to Ruby from another language and are still using it as if it was another language. Even if you don't want to go too deeply into metaprogramming and don't want to actually make use of these "dangerous" techniques the book will impart enough deep understanding of they way Ruby works and its philosophy for you to be a better Ruby programmer after reading it. 

It probably isn't worth buying the new edition if you have the original unless you want to know about the new Rails features. 

Not for the complete beginner but for just about every other Ruby programmer - highly recommended.



Python All-in-One, 2nd Ed (For Dummies)

Authors: John Shovic and Alan Simpson
Publisher: For Dummies
Date: April 2021
Pages: 720
ISBN: 978-1119787600
Print: 1119787602
Kindle: B091DGDLK8
Audience: People wanting to learn Python
Rating: 2
Reviewer: Mike James
All-in-one refers to the fact that this is seven books put together - why?

T-SQL Fundamentals (Microsoft Press)

Author: Itzik Ben-Gan
Publisher: Microsoft Press
Pages: 608
ISBN: 978-0138102104
Print: 0138102104
Kindle: B0BTLBXF8V
Audience: T-SQL developers
Rating: 5
Reviewer: Kay Ewbank

Itzik Ben-Gan is a highly respected Microsoft Data Platform MVP, and the earlier editions of this book were already ver [ ... ]

More Reviews

Last Updated ( Friday, 29 April 2016 )