Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If monkey patching is permitted in both Ruby and Python, why is it more controversial in Ruby?

In many discussions I have heard about Ruby in which people have expressed their reservations about the language, the issue of monkey patching comes up as one of their primary concerns.

However, I rarely hear the same arguments made in the context of Python although it is also permitted in the Python language.

Why this distinction?

Does Python include different types of safeguards to minimize the risks of this feature?

like image 935
Paul Dexter Avatar asked Apr 04 '09 17:04

Paul Dexter


1 Answers

It's a technique less practised in Python, in part because "core" classes in Python (those implemented in C) are not really modifiable. In Ruby, on the other hand, because of the way it's implemented internally (not better, just different) just about anything can be modified dynamically.

Philosophically, it's something that tends to be frowned on within the Python community, distinctly less so in the Ruby world. I don't know why you assert that it's more controversial (can you link to an authoritative reference?) - my experience has been that monkey-patching is an accepted technique if one where the user should be aware of possible consequences.

like image 85
Mike Woodhouse Avatar answered Oct 12 '22 13:10

Mike Woodhouse