3 ms·
Writing maintainable code in most languages involves knowing exactly when to apply the "cool stuff". Ruby meta-programming can be incredibly powerful - e.g. I'm
by vidarh 9y ago
Writing maintainable code in most languages involves knowing exactly when to apply the "cool stuff". Ruby meta-programming can be incredibly powerful - e.g. I'm working on a project at the moment where we dynamically build a very large, complex REST API by introspecting the ORM models augmented with data about access control etc. The entire web API is maybe a tenth of the code it'd have been if we wrote all the code manually, and that proportion is steadily dropping as we add more models.
But the key there is that the meta-programming involved is very, very limited for a very high payback. As it is, it raises the barrier for new hires, and we want to make sure not to raise it higher.
And most of the rest of the code is taking an increasingly functional approach.
I tend to think there is "too much magic" in a lot of Ruby projects, so I try to be very careful and limit it to places were it so drastically cuts down on the amount of code that we can justify quite a lot of explanation and still come out far ahead. But when everything lines up, the benefits can be dramatic.