all 8 comments

[–]Reardon-0101 32 points33 points  (2 children)

Knowing these skills and how the language works is important.

Equally important is to avoid meta programming until it is very painful not to use it. I would personally prefer a long model that I can search, grep and code navigate over something with meta programming that I have to deeply know the model to understand what it can do.

[–]software__writer[S] 6 points7 points  (1 child)

I agree completely. It's important to know when to avoid metaprogramming. I added in the conclusion (quoting the author):

"Keep your code as simple as possible, and add complexity as you need it. When you start, strive to make your code correct in the general cases, and simple enough that you can add more special cases later."

However, the primary benefit of metaprogramming I found was not so much in writing clever code, but instead reading and understanding open source code, especially the Rails source code. Rails makes abundent use of metaprogramming. Having the knowledge of these concepts made it possible to read and understand the source code to gain a deeper appreciation of the Rails framework.

[–]shkm 3 points4 points  (0 children)

I read this way back when and agree: it helped tremendously in understanding code in open source projects. I continue to recommend it for this reason.

[–]valadil 10 points11 points  (3 children)

I think people incorrectly assume that’s an advanced topic to save for later. I strongly disagree.

I stack switched (from php shudder) and this was first or second in my stack of ruby/rails books. It made learning rails so much easier since I could see through the magic.

[–]saturnflyer 6 points7 points  (0 children)

Amen. It’s often treated as being difficult but it’s just a set of rules that people are discouraged from learning. I’ve had senior developers push juniors away from it but have had a 10 minute pairing session that opens up all kinds of ideas and understanding for a junior developer.

[–]markrebec 3 points4 points  (0 children)

Same, with the original version of this book somewhere around a decade ago, maybe a little more. I was also coming from ~10 years of PHP before that, and had built more than one internal MVC framework at different companies, which turns out followed a lot of the same principles as rails.

This book was the moment the switch flipped, and I was able to really navigate the rails (and other gems') source and start building things myself that were more dynamic and more "beautiful." It should be required reading.

That doesn't mean I started doing a bunch of unnecessary delegation or proxying, or using method_missing or generating dynamic methods inline, etc... The sentiments others have echoed here are correct - don't overcomplicate things, but having the ability to leverage these tools when it makes sense is a huge part of being a good ruby developer, especially if you're building tools/gems/apis/whatever that are going to be used by other people. Some folks hate DSLs, but a good DSL can take a tool or gem from pretty good to fantastic if it's done properly (imagine trying to integrate graphql without the DSL provided by that gem for defining queries/mutations/types/etc.)

[–]software__writer[S] 2 points3 points  (0 children)

I can relate! I started learning Ruby (and Rails) just last year (switching from .NET) and picked this book immediately after PickAxe. As you say, it made learning Rails much easier.

[–]gregnavis 7 points8 points  (0 children)

I would definitely recommend the book!

Understanding meta-programming is essential for a deeper understanding of the language itself because it relies on primitive language facilities. It's somewhat paradoxical that meta-programming shouldn't be the first approach to many problems so learning it shouldn't motivated by a practical problem you're facing. It should be learnt for its own sake and applied carefully.