Hacker News new | ask | show | jobs
by jshen 5816 days ago
"That said, I threw my hands up after running into multiple libraries duck punching (monkey patching) ActiveSupport into a mangled, conflicting mess one too many times. The open classes thing really is harmful, no matter what anyone tells you. It's a feature that, when used with care, can be very powerful...but the problem is in my experience it's not used with care very often in the Rails world."

I don't quite agree with this. Of course I agree that you should use monkey patching with care, but it's the implications I disagree with.

First, you can monkey patch in python too. Python doesn't make this safer, but it is used more in the ruby world. I think the implication that I take issue with is that it's rails fault that some other library you used monkey patched rails. It's the libraries fault, and people should look into libraries before they use them. Just as you should use monkey patching with care, you should use other peoples libraries with care. Peek at the code before using it.

Rails 3 makes it easier to change things without monkey patching so it should occur less frequently going forward.

1 comments

I guess the issue is the prevalence with which it occurs in Ruby, as you say. I've been programming professionally for over a decade now, in at least as many languages, and I've only had this problem with ruby.

Still, I enjoy ruby very much, and I haven't seen my last project in it or Rails. I just need reliability and consistency now, and Python seems to offer more of it. I may as you say hit this same problem in Django, but I haven't yet.

"I've been programming professionally for over a decade now, in at least as many languages, and I've only had this problem with ruby."

It's a trade off. Take away monkey patching and you get other problems. Just look at java projects. Once you make an interface and someone else uses it you can't change it anymore without breaking everyones code. Check out the eclipse code base for examples.