Not going dark (ruby metaprogramming)
weblog.raganwald.com
weblog.raganwald.com
>> (def foo a, b
>> (a + b)
>> end)
=> nil
>> (foo 1, 2)
=> 3http://iolanguage.com/scm/git/checkout/Io/docs/IoGuide.html#...
Although it wasn't mentioned in this particular post, the problem is acute for people using extensions for their own third-party libraries. If you install gem foo, and it uses something with "stupid method names for Object extensions," your code is now infected with stupid method names for Object extensions.
What happens if you use gems foo and bar and they conflict with each other? Even though you went out of your way to eschew Object extensions, the authors of gems foo and bar may not have been so hygienic.
My hope is that some mechanism for avoiding this problem becomes popular. This may not be it, but crossing yourself and hoping nobody else uses your method names or conflicts with each other does not scale very well.
I have created a library to help manage includes, and make them more like imports in other languages that have real modules. (You can selectively include methods from a module) http://github.com/gregwebs/module-import/
blog post http://blog.thoughtfolder.com/2008-03-11-real-modules-for-ru...
If this used some of your ruby parsing magic to analyze dependencies, it would be a lot better.
class Object
import MethodChain, :tap
end
You will never import MethodChain#chain or any other methods into Object, and you will never have to worry about re-writing those methods.I'm a bit skeptical about the severity of this problem, though. It's the same problem faced by C programmers for the past 30 years, and it hasn't really retarded library development. If anything, the Ruby problem is far simpler, since you can choose one of many different namespaces to add your global symbols to.
However, I am also keenly aware that there are others with different viewpoints. For example, andand was first used in production on an application with a handful of developers and a medium-sized collection of classes.
I have done some work with another application that has dozens of developers in multiple locations and considerably more classes, almost an order of magnitude more. The developers on the second application are far more conservative about extending core classes.
I am also very sensitive to the downstream client problem. When working on your own project, you can do whatever you want. But when writing a gem or plug-in for others to use, you need to be much more conservative about introducing extensions, because they get them whether they want them or not.
For that reason, the rewrite gem doesn't use andand.