------ art_4736_3202094.1203805390768 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Sat, Feb 23, 2008 at 3:07 PM, Avdi Grimm <avdi / avdi.org> wrote: > Hi folks, > > I wrote a blog post with the intentionally provocative title above, > which can be found here: > > http://avdi.org/devblog/?p > I don't agree with the title, but I agree almost everything you said. When I first starting using ruby a few years ago, I thought the idea "monkey patching" was a very powerful and useful technique. Later, I came to the same conclusions as you. I know we are in the minority. I believe that "monkey patching" in packages can easily kill interoperability with other packages. I think this comment of yours hits the nail on the head: "And this is really the point. Monkey patching is the new black. it's what all the hip kids are doing. To the point that smart, experienced hackers reach for a monkey patch as their tool of first resort, *even when a simpler, more traditional solution is possible*." So true. Here are a couple cases I can think of people doing "monkey patching" and the alternative traditional solution: * adding new (or perceived missing) functionality (methods) to a class. The traditional solution would be to just inherit from the class and use the derived class instead where you want this new functionality. Since you can't inherit from some classes (i.e. immediates, a problem with the language IMHO), you can instead use something like Forwardable instead. * adding #to_* methods to String. A single letter is quite common for the * which can make a collision all the more likely. The more encapsulated solution would be to class method for creating one of these objects from a String (i.e. klass#from_s(s)). Every case I thought that I needed "monkey patching", I've found a relatively simple solution. I usually only do monkey patching in the following cases which have no reuse: top-level script, testing, and quick hacking. Eric ------ art_4736_3202094.1203805390768--