Richard Bucker

Ruby MetaProgramming? Really?

Posted at — Apr 18, 2012

Let’s tee one up with another visit to PragProg. This time it’s metaprogramming. I do not take issue with the book or the publisher. The book is well written and if I did not like the publisher I would not be buying from them,,, and I have plenty.In the very first few pages of the book the auth describes metaprogramming: wrappers and “magic”… bend the syntax… remove duplication… stretch and twist ruby… … and code generationWhich inspired me to tweet these: Ruby metaprogramming may be best implemented by ruby l337 but even they move on. It’s not scalable or sustainable. Ruby metaprogramming is unmaintainable in any environment where maintenance is important. Worse than read-only Perl!!! Ruby metaprogramming = NoRubyCode generation is reasonable and good. You can leverage data to produce realized code paths instead of completely data driven code paths. In many cases debugging is easier because you test and debug the fragments and how they stitch together instead of every possible combination as driven by data alone.But that’s where metaprogramming shines.All of the other meta attributes suggest that Ruby “bend and twist” to be something other than what it is. And that is what drove me to tweet. It’s Ruby but not really Ruby... How much metaprogramming would it take for Ruby to simulate python?Traditionally metaprogramming was described by code and data… not by adjustment to the syntax or the language. One needs another name for whatever that syntax mangling function is called. But also, good luck to you and your read-only-ruby.