From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2001-12-11T07:40:32+09:00 Subject: [ruby-talk:28145] Re: The benefits of dynamic typing? In article <3C153282.9000309@vt.edu>, Roy Patrick Tan wrote: >Phil Tomson wrote: > >> then if I, or a user of these >> classes decide that they want a different kind of runnable object that >> performs a differnt function when 'run' is called, all they >> have to do is define another class of their own and make sure it's objects >> respond to 'run'. > > >This is somehow disturbing to me. "Run" is kind of ambiguous, and might >behave differently for different objects, whereas the caller of the >method expects "run" to behave in a certain way, shouldn't a >compiler/interpreter make sure that it *does* behave that way (ie check >the contract)? > But if the caller object "expects 'run' to behave in a certain way" doesn't that imply that encapsulation is broken in the system? Isn't the contract the method signature (the messages an object will respond to) of the runnable object? In my system (and this example is based on a real world framework I've implemented) as long as the object passed defines a 'run' method, it is runnable. The object receiving the runnable object (which then invokes the runnable object's 'run' method) doesn't have any concerns about what invoking 'runnableObj.run' will do. This, in fact, made my framework very simple. Let me explain: I was tryng to distribute tasks to multiple clients using dRuby. And I also wanted users of the framework to be able to create their own runnable objects (I can't think of everything a user might want to use the framework for) - so letting users of the framework define their own runnable classes with the only criteria being that their class define a 'run' method made the whole system much simpler. (BTW: I do check the 'contract' for an object prior to sending it out to a client - I make sure it responds_to 'run'). I know, it's difficult at first to move from the statically typed worldview to a dynamically typed worldview - it's kind of like looking at that popular optical illusion that looks at first like an old hag of a woman with a big nose, but as you stare at it a bit longer you see that within that image is a beautiful young woman. It was like that for me initially as well, at first I missed having type checking, but now that I see it from the other side it is quite freeing and, dare I say it, beautiful. Phil