Hacker News new | ask | show | jobs
by brunoc 5139 days ago
I don't get why these models get bloated. If there's a language that makes it east break up classes into any number of components, surely that's Ruby! Mixins, open classes, modules, etc..
2 comments

Mixins/modules and open classes do not separate your class in to multiple components - merely multiple files. As I explain in the article, for separate components to be useful, they have to be "protected" from each other - encapsulation, in other words.
Mixins (well, as they're supposed to be used) do provide encapsulation; specifically, they enforce the boundary between instance scope (e.g. access to instance vars) and method interface. I view them as a part of a coupling continuum:

[instance methods] --- [composed subclasses] --- [mixins] --- [the outside world]

But Modules provide more than that. module_function allows for unattached namespaced functions which can be referenced by full name, relative name, or imported into the local scope. Great way to express functions which are decoupled from instance state--much like the services and policies you're advocating for. It's an under-appreciated aspect of the language, I think.

No doubt - That's just good OOP. Looks like this gem will help people achieve that.
I find that ruby projects end up breaking things up into modules, but fail to gain much benefit from it, since there's a tendency for the logic from the different "modules" to be tightly coupled. It's actually really hard to refactor ruby, since because it's so dynamic and so much state is shared, it's very hard to make safe changes.