As you might have read in my last post, I'm trying to get some additional reading in this year. One the of the books I got for Christmas was Bruce Tate's Seven Languages in Seven Weeks. I've polished off the reading for the first language, Ruby.
Overall this is an enjoyable book so far. One point of irritation however is the references to answers at the back of the book, which were never published. Not only is this irritating because it should have been an easy typo to fix, but because the best parts of the book so far have been the example problems. I thoroughly enjoyed thinking through the problems and the lack of answers (which I wouldn't miss as much if references had not been made to them) reduces my understanding of the author's perspective. Frequently I found myself wondering if I was missing some basic aspect of the language (particularly a bit of syntactic sugar in Ruby) when solving a problem. Perusing blogs helped to some extent, but often I felt like the example answers I could find were missing some elegance that Tate had in mind. If they didn't have some significance, why did he choose that problem to print?
Metaprogramming in general has been one section of Ruby that I've been extremely interested in learning how to apply appropriately. Seven gives a good synopsis and certainly shows how it can remove boilerplate code. It is part of the magic of the Rails framework, but I still remain unconvinced as to its place as a part of a programmer's standard kit. I think there is a balance to be found between boilerplate overload and metaprogramming negative space. When you hide the context of an operation inside the black box of metaprogramming I think you lose a fair amount of perspective into the design of a program. Simpler (concise) becomes more complex (abstraction). We risk losing ourselves in the metaphors.
Hopefully, I'll find a use case that makes me really appreciate the magic box of the method_missing and related tricks in Ruby and other metaprogramming toolsets. Until then I'll probably just piggyback on the frameworks like Rails that have used it so well. If you feel like explaining why method_missing is awesome, please do so on the StackOverflow question below.