From: Isaac Gouy Date: 2005-12-23T14:47:50+09:00 Subject: Re: Diff of opinion on dynamic stuff Bob Hutchison wrote: > On Dec 22, 2005, at 4:27 PM, Drew Mills wrote: > > > Let me preface this post by saying that I'm no Ruby expert. I like > > it. > > It's fun. But I won't claim extensive knowledge on it. > > > > So when this guy blogs about a Python quality that he feel is better > > than a Ruby quality: > > > > It's the second generation that's going to be less enthused, > > that's going to stare in bafflement at these classes that > > mysteriously spawn methods, and trying to figure out what's > > going when there's an exception in dynamically generated > > code. You can monkeypatch code in Python pretty easily, but we > > look down on it enough that we call it "monkeypatching". In > > Ruby they call it "opening a class" and think it's a cool > > feature. I will assert: we are right, they are wrong.> > > > -- http://blog.ianbicking.org/theres-so-much-more-than-rails.html > > > > I am curious what this means. Is Python against dynamic stuff? And > > Ruby for it? And so we just agree to disagree? Or do I > > misunderstand? > > Well, Python is plenty dynamic. I think he is complaining about > Ruby's ability to re-open a class. This can make it difficult to find > the complete definition of a class (imagine doing this in a > completely random way in multiple files). So while it can be abused, > it can also be an incredible simplification of the code you write. > One thing it does is flattens inheritance hierarchies, you don't > need to introduce specialising classes just to add a few methods. > Using xampl as an illustration: the Ruby version of xampl generates 1 > class for every 3 generated by the Java version of xampl, one of > those classes is eliminated because I can re-open classes (the other > is eliminated due to duck typing). Another thing reopening classes > does is, obviously, to allow you to extend the built in Ruby classes > (they are just classes after all). I suppose Ian would think things > even worse because in Ruby you can do this to objects as well as > classes. > > This 'monkeypatching' is very similar to concepts in Smalltalk and > CLOS (Common Lisp's object system). Nobody in those communities > complains too much (though Smalltalk's browser reassembles classes > for you, and new CLOS programmers are sometimes at a bit of a loss > because in CLOS methods may belong to two or more classes and it > doesn't seem that the obvious thing to do is the right thing). Ruby > just makes thing a lot easier. Yes, the equivalent of "method_missing" has been used for many things in Smalltalk. Glorifying in how we can hack "doesNotUnderstand:" avoids having to admit that there's been a problem with the language. "This comparison highlights that the most commonly used technique based on the specialization of the doesNotUnderstand: method is not the best one. As a first explanation of this situation, one should note that the ability to directly execute a method has only lately been introduced in the interpreters (methods valueWithReceiver:arguments: on CompiledMethod class in VisualWorks and executeWithReceiver:andArguments: in IBM Smalltalk). Moreover, this comparison shows that the techniques based on VM lookup method or method wrappers should be considered by more programmers than it is currently the case." "Evaluating Message Passing Control Techniques in Smalltalk" http://www.iam.unibe.ch/~scg/Archive/Papers/Duca99aMsgPassingControl.pdf > > Just be careful where you aim that thing. > > Cheers, > Bob > > > > > Just curious. > > > > Drew > > > > > > ---- > Bob Hutchison -- blogs at > Recursive Design Inc. -- > Raconteur --