From: Jim Weirich Date: 2009-02-26T06:09:48+09:00 Subject: [ruby-core:22505] Re: YASNP (Yet Another Selector Namespace Proposal) On Feb 25, 2009, at 12:23 PM, Brian Ford wrote: > When do you put one method in? If one method, why not two? Where are > the boundaries in a library, framework or application? You should use a namespace whenever you add a method to a module or class that is not part of your library. For example, Rake adds an "ext" method to String. If selector namespaces were available, Rake would scope that "ext" method in a Rake namespace. Allowing other libraries/frameworks to also define their own independent version of "ext" and allow users to explicit control which version they call. You should probably not use namespaces on modules or classes that you own and control. > The essence of my objection is that you will so cleverly put into a SN > a method that someone else will want to change. Putting something in a namespace does nothing to prevent someone from intentionally changing the method. > Again, there has been no justification for why SNs are *needed* to > solve the problem presented here. You want to have multiple methods > with the same name on the same public, common class but with different > behaviors. A better way to say this is that we want to be able to enhance shared classes with framework specific methods without: (1) needing to coordinate non-conflicting names across all libraries for all time, (2) needing to name our methods with ugly, conflict resolving prefixes (e.g. calling using "rake_ext" instead of "ext"). > You think, "I'm so smart about programming my app, no one will want to > monkey patch this method." ... Selector namespaces are not about preventing intentional monkey patching. If Rake put the "ext" method into a namespace, you could still monkey patch it. It is to prevent accidental name collision. If anything, it makes monkey patching safer and easier. Knowing that no one will accidently overwrite my 'ext' method on String, I am more likely to go ahead and add the method to String (where it belongs). -- -- Jim Weirich -- jim.weirich@gmail.com