Home - Network Programming
Metaprogramming Ruby: Program Like the Ruby Pros
Price:
$16.99
$32.95
& 2-Day * Free Nationwide Shipping! (* details)
Availability: Usually ship in 24 hours if sold by Amazon.com
Product Details
| Binding: | Paperback |
|---|---|
| EAN: | 9781934356470 |
| Label: | Pragmatic Bookshelf |
| Feature: | ISBN13: 9781934356470 Condition: New Notes: BRAND NEW FROM PUBLISHER! BUY WITH CONFIDENCE, Over one million books sold! 98% Positive feedback. Compare our books, prices and service to the competition. 100% Satisfaction Guaranteed |
| Publisher: | Pragmatic Bookshelf |
| Studio: | Pragmatic Bookshelf |
Editorial Reviews
Everyone in the Ruby world seems to be talking about metaprogramming--how you can use it to remove duplication in your code and write elegant, beautiful programs. Now you can get in on the action as well.
This book describes metaprogramming as an essential component of Ruby. Once you understand the principles of Ruby, including the object model, scopes, and eigenclasses, you're on your way to applying metaprogramming both in your daily work and in your fun, after-hours projects.
Learning metaprogramming doesn't have to be difficult or boring. By taking you on a Monday-through-Friday workweek adventure with a pair of programmers, Paolo Perrotta helps make mastering the art of metaprogramming both straightforward and entertaining.
The book is packed with:
Whether you're a Ruby apprentice on the path to mastering the language or a Ruby wiz in search of new tips, this book is for you.
Customer Reviews
i) Highlights the conceptual differences between Ruby and other currently popular languages
ii) Shows how those conceptual differences are expressed in programming constructs by walking the reader through a number of small but realistic example problems
iii) Reviews internal details of a number of pieces of real-world software (most notably Rails) to show how the authors of these packages use the techniques he describes to solve their problems
iv) Provides a number of helpful and applicable guidelines on how to 'think in Ruby'
v) Generates a GoF style catalog of implementation patterns
vi) Skewers the notion that 'metaprogramming' is any different than regular programming
After finishing this book I have a real appreciation of the techniques the author describes, and how they can be used to write flexible, powerful, and maintainable software. Before reading this book I was aware of a number of these techniques, but I didn't necessarily understand how they could be effectively used to solve real problems. Now I do. The book truly covers how to think in Ruby - how to naturally solve problems in Ruby, as opposed to adapting techniques commonly used in languages from the C/C++/Java lineage.
The one major criticism I had of Metaprogramming Ruby was the 'fanboy' tone that permeates a lot of the text. Frequently the author seems more interested in getting you to agree with him that Ruby is great than in conveying the concepts being discussed. There are a lot of gratuitous slams of other languages (especially Java) that were frankly unnecessary and distracted from the book. Had the tone of those comparisons been a little more highbrow and a little less schoolyard, this would have been a better book.
Overall rating: 4.5 stars
Also: the book is well written and organized. I especially like that whenever a particular topic is mentioned a page reference also appears. This makes it easy to do a quick review of the topic before going further, like "Hook Methods (181)."
This book will not sit idly on my shelf. I'll be going back to it again and again for review and further mastery of the topics.
In this scenario, you take the role of a new employee at a company guided by the Ruby expert named Bill, on a one week crash course journey though the object model, method creation, blocks, class internals, and finally putting this all together to write a piece of code that seem oddly familiar to the base files you see in some of the famous gems.
The book then goes on and ties this ruby knowledge to a Rails specific lens, examining the internals of ActiveRecord, taking a quick tour of Merb, and then having a glossary of metprogramming "spells" useful for everyday work.
The technical content of this book is very, very good. The book explains much of the basic structure of ruby (object model, class definitions, blocks, method lookup, etc) in such a way that common idioms that I have previously used without understanding their underlying mechanisms now make complete sense, and my understanding and command of some of the more powerful features of ruby have greatly improved.
Real-world code examples drawn mostly from ruby gems are included, and these are excellent illustrations of ideas presented.
As with many technical books, many of the non-real-world code examples are extremely simple and contrived. For the most part, this is acceptable, but there are instances where the tests/sample output provided for exercises were incomplete -- in the sense that you can come up with a flawed and incomplete piece of code which will still make the test pass.
The thing about this book that drove me up the wall is the insipid story line: You have started a new job, and you have an incredibly chirpy and annoying coworker with whom you must pair program, and who lectures you about the ruby object model, etc. The dialogues are awful; Bill The Asinine Coworker "exclaims" and "shouts" much like characters in bad romance novels supposedly do. The text is littered with irrelevant and distracting details about sipping coffee and grabbing keyboards and ignoring whiteboards in favor of napkins.
This is possibly the best exposition of the ruby object model available, however, so if you are frustrated by the piecemeal information available on the web and you don't have a chirpy co-worker by the name of Bill to mentor you, I would highly recommend reading this book.
The major complaint about the book from these reviews is the narrative style of the exposition. I read the complaints before picking up the book so I was prepared--and found them unwarranted.
The purpose of the story and characters is to provoke thinking and understanding. The method succeeds.
I would read this before reading a Rails book.
The sub-title may be somewhat presumptuous, but it will certainly change the way you approach Ruby programming. This is essential.
After reading this book, I can personally say that some of Rails more magical features don't seem so magical anymore. Now they just make sense!
H
With that out of the way, "Metaprogramming Ruby" is a very good book. The concepts and their presentation are solid and the author knows where to draw the line and leave things for further exploration by the reader. I think there's a slight over-use of footnotes and sidebars, which can disturb the reading flow a bit, but it's not very dramatic and unfortunately this is not that uncommon in technical books.
What I like best is the author repeatedly points out that the distinction between "regular" programming and metaprogramming are blurry in Ruby at best, and that the latter in the end isn't some obscure sort of magic, but "just" a powerful set of tools that can be immensely helpful when used responsibly. Even advanced Ruby programmers are likely to pick up a new trick here or there or at least further their understanding of certain concepts.
Why I like this book?
I could have written the following code like in C:
// C code
int main(void)
{
int i;
for (i = 0; i < 10; i++)
printf("I love you. ");
return 0;
}
But, in Ruby, I can write it more straightforward and simpler -
# Ruby code
10.times{print 'I love you. '}
Ever since I saw this Ruby code, I've fallen in love with Ruby.
After that, I've been enjoying reading tutorials and blogs on the Internet which taught me interesting Ruby tips and tricks. However, what I really wanted to get my hands on was Ruby Metaprogramming.
I've read various articles on Ruby Metaprogramming, but unfortunately I could not understand them well. Everyone said Metaprogramming is too advanced a feature and too early for me to learn. Then I luckily met this book. I started reading the introduction and the story about Bob and Bill.... and I found that I was getting crazy about this book. After reading the first part, Bob and Bill's whole week story, I felt that I wanted to write Ruby code freely. And felt I may be able to do that...
Now I've been reading the second part, Metaprogramming in Rails, again. It's different from the first part. Auther shows us the code which is used in a real project and adds some explanations. I didn't understand it very well on my first read, but after reading and trying out the code again and again, I started becoming comfortable with it.
Auther Paolo says the following in an interview with [...]: When you understand metaprogramming, that's the moment when you start "thinking in Ruby".
We'll be able to write Ruby code as well as native language.... Fantastic!! Well, we need to learn more and more about this, but I'm dreaming with this book!
There's a lot of good information, but you'll have to skim through a lot of bad dialog to find it. For reasons I can't understand, the book superglues you to an annoying and badly-written "programming buddy" named Bill, and way too much of what the book has to teach is buried in his dialog. A third of the book could be pruned by nixing Bill, and the book would be more understandable and less painful to read as a result.
Entire chapters are spent on topics that could be dispensed with in a few paragraphs and the beginning of the book lingers on information that an intermediate programmer would already know. But the strange dialog style buries information so it's difficult to skim or skip. This improves towards the end.
The following quote is an example of what you're in for:
"Forget about method_missing() for now -- we'll get to that this afternoon. To introduce Dynamic Methods, allow me to tell you a story from my youth," he says. "When I was a young developer learning C++", Bill muses, "my mentors told me that when you call a method, you're actually sending a message to an object. It took me a while to get used to that concept. Of course, if I'd been using Ruby back then, that notion of sending messages would have come more naturally to me." Bill launches into a mini-presentation.
A few sentences later comes this: "'Wait a minute,' you interject. 'Why on Earth would I use send() instead of the plain old dot notation?'"
Why on Earth, indeed.
It's condescending, wrong-headed, distracting and agonizing. The concept is very badly suited to the subject matter and that's a shame; the author obviously knows the material and the book could have been excellent. But for some reason, someone decided the book would use a tone usually reserved for explaining rules to slow children. I suspect the book's trying to mimic Why's Poignant Guide to Ruby, which is a horrible trend I see creeping into other Ruby books.
Criticism aside, this is the best book I've found on the topic to date. Bring a highlighter with you and try to ignore Bill. This is the best you'll find for the moment.
A great thing about this book is that it presents these cool but seemingly impractical techniques, and then gives you a great real world example of just how common and practical it really is. Another thing I wasn't expecting is the humor. I laughed out loud reading some sections of the book.
I'm not sure that I'd recommend this for the new Rubyist, but if you have a decent foundation, this book will take you to the next level.
Long story short, if you are serious about taking your ruby skills to the next level, you owe it to yourself to get this book.
Meta-programming is one of those, its beautiful written, whit-full, smart and still as concise as the topic it speaks about.
it may not be the "Ruby" book, nor the library on Meta-programming techniques. i think its best used as a book about
style and programming technique. as in inspiration to learn new tools, understand how those "spill's" work in Ruby
and most important as an inspiration to write cleaner, more esthetic code
Now I'm reading it the second time. It's enjoyable reading it.
If you're a serious Ruby developer, you HAVE TO own a copy of it.
The content of the book is excellent! The techniques described are very useful, and the author uses mostly good examples to illustrate the use of the different recipes. As a side-note, I also recommend the screencast series by PragProg.com about Metaprogramming Ruby. The book has three chapters which cover how Metaprogramming is used in the Rails framework, which is also very useful.
So far, so good, BUT......
The downside of this book is the writing style -- I'm quoting from orangekay's review here on Amazon:
[...] it's written in a really annoying tone that attempts to present said information as a story.
That story is very boring, gets old after the first paragraph, and makes it very difficult to find
the code you want amidst the sea of useless prose.
I can only second that statement! It is extremely annoying to read this book because of the stupid side-story, and it is very hard to find the relevant concepts later. The names of the concepts/recipes discussed in the book are mostly badly chosen, which is both annoying and confusing later.
I'm wondering why this style was chosen.. to add pages? It's so annoying that I feel tempted to take a big fat black marker and x-out all this junk from the silly side-story. If I had this in an editable electronic form, I would re-format the content!
I wish the author would take these comments to heart, and in the next version of the book, would follow a standard format, e.g. a "Cook-Book" approach, to discuss the techniques described in this book -- without a side-story!
If you want to learn in detail how Metaprogramming Ruby works, by all means: buy this book, it is very useful!
I would give this book 4 stars, but because of the obnoxious writing style I rate it as 3 stars.
Create your own review



