From: Eric Mahurin Date: 2008-02-24T17:31:30+09:00 Subject: Re: Monkeypatching is Destroying Ruby ------=_Part_5639_25540376.1203841893445 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Sun, Feb 24, 2008 at 12:06 AM, James Britt wrote: > Avdi Grimm wrote: > > Hi folks, > > > > I wrote a blog post with the intentionally provocative title above, > > which can be found here: > > > > http://avdi.org/devblog/?p=18 > > > > While the title is a bit of deliberate hyperbole, I am genuinely > > troubled about the popularization of monkey patching in the Ruby > > community. > > That so many people use the phrase "monkey patching" suggests many > people don't actually understand how to use it. > > It's no more "patching" than reassigning to a variable is patching. When you are talking about global (and to a certain extent class) variables, there is an analogy. Most languages do have global variables, but they are also usually discouraged (especially changing them) because of the side-effects (state changes). Monkey patching is in this same vein, except worse IMHO (the state changes can be more intrusive). Like global variables, I don't think monkey patching is a good practice for reusable, inter-operable, and maintainable code. On the other hand, one nice time to use it is for creating a ruby-based DSL. But, when making a DSL where monkey-patching helps, I think the monkey patching should be done as a thin layer. The base functionality should use no monkey-patching so that it can be used cleanly with other packages. You'd likely have problems combining multiple monkey-patched DSLs together if you couldn't disable at least some of the monkey-patching. You might also say the same of global variables. If you use them, use them only at the highest user/DSL/script/test level. The baseline reusable functionality should just be passed that global variables and not use them directly. Eric ------=_Part_5639_25540376.1203841893445--