News for hackers. Stuff that matters.
Re:Responsible Monkeypatching in Ruby by Groxx on Friday August 27, 2021 @02:35AM (#28324937)
I wish every language had open classes for this reason. It makes ruby such a joy to write in. Something like Kotlin's class extensions might be a happier middle ground for many languages though, since that way you only get what you pulled in, in any given file.

Yes, of course you can do horrific things with it. But the ruby community has largely been absolutely stellar about not doing that - most keep insanities tightly bounded, where they can be used to make pleasant and error-resistant APIs. And even when they're not (which is usually self-inflicted by internal code), the language is flexible enough to let you unfuck just about any fuckery that you run across, if needed.

Re:Responsible Monkeypatching in Ruby by Fire-Dragon-DoL on Friday August 27, 2021 @08:59AM (#28327234)
I'd argue the opposite. Most ruby codebases are infected with monkey patches, extracting libraries now depends on activesupport being used, forcing the dependency
Re:Responsible Monkeypatching in Ruby by Groxx on Friday August 27, 2021 @01:19PM (#28330480)
Activesupport is hugely widespread, yeah. It's a bit unfortunate since it provides so much, and it's rare that all (or even most) of it is used.

But beyond that though, the vast majority of issues I've seen with monkey patching has been stuff that was created in the project/company that's experiencing the problems. Libraries are generally very good about how they monkeypatch (because doing it wrong with hundreds of using-projects VERY quickly runs into problems), but those ad-hoc internal monkeypatches are routinely done by people who don't fully understand what they're doing, or take shortcuts. Those can have latent bugs linger for a very long time, and yeah - they can be nasty to unravel.

Re:Responsible Monkeypatching in Ruby by lovegoblin on Friday August 27, 2021 @01:32PM (#28330661)
> Activesupport is hugely widespread, yeah. It's a bit unfortunate since it provides so much

Even this is becoming less and less necessary as more of the commonly-used syntactic sugar gets pulled into Ruby core.

Re:Responsible Monkeypatching in Ruby by quetzthecoatl on Friday August 27, 2021 @07:38AM (#28326501)
Open classes are against SOLID principles (O stands for - classes should be extendable, but not modifiable). So, a big no in some circuits. Aside from open classes, ruby also have instance_eval and class_eval taking to violating that principle to whole new level.