by rufugee · 16y ago · 0 comments
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've heard Scala solves the issue with open classes by keeping things in context with the code that surrounds it, but I personally haven't verified it. Besides, that's not what you asked.
Here's a metaphor that I really feel holds true: Rubyists are magicians...Pythonistas are masons. If you have to rely on your own code only, then by all means delve as deep into magic as possible. However, if you have to rely on other's work, the mason's approach is much more intuitive, reliable, and safe.
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.
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.
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.
Sinatra is more of a "micro-framework" and puts you closer to the http method.
Basically, the api mimics http more closely, you literally use get, put, post, and delete methods to define your routes and actions.
In Sinatra, you define your routes in the same place where you program your Resource's functionality, so less mapping is required. In Rails, you have a separate controller and route files.
The model layers between Sinatra and Rails are very similar. For example, you can use ActiveRecord in Sinatra.