From: Sean O'Dell Date: 2003-11-20T04:00:20+09:00 Subject: Re: "stereotyping" (was: Re: Strong Typing (Re: Managing metadata about attribute types) ) On Wednesday 19 November 2003 10:33 am, David A. Black wrote: > > On Thu, 20 Nov 2003, Sean O'Dell wrote: > > But if something derives or mixes in an interface, then it *does* > > implement the interface. The module or class *is* the implementation. > > Sure, you can hack it out; that can happen in any language. I can pass > > pointers to int where a FILE pointer is expected in C and C++. That's > > not the point. > > This is similar to Ryan Pavlik's comments to the effect of "Sure, if > you want to write broken code you can change an object's > interface...." :-) The thing is, though, it's not about hackery or > brokenness; it's about a language design which accomodates dynamic > type (interface) change, and in which such behavior is not > incompatible with the achievement of good, well-designed code. But you can't dynamically re-implement a method and change the parameters it takes and then pass an object of that class to a method that doesn't know about the new parameters. Sooner or later, you have to fix the interface in stone and the flexibility is out the window. It just is. Even if Ruby doesn't have a mechanism to enforce type checking, you can't pass objects that have been modified radically to libraries that expect a former version to be present. If you alter parameters, you're going to get hit with a semi-descriptive error. You will be forced to either abandon the call, or modify your object to conform. Either way, the enforcement occurs, regardless of whether Ruby helps you or not. The dynamicism is gone. Listen, I don't mean to be obtuse, but declaring Ruby's flexibility is not a guarantee of flexibility. It's flexible until a library requires certain methods and parameters. Then you're stuck. It's better to get a nice, descriptive message like "your object does not conform to the :memorymap interface" than to get a message that says "in line 45,289 of a file you know nothing about in the middle of a bunch of code you didn't write, a call was made to some object whose name you have to trace to find out where it came from and that call didn't have the right number of parameters. Figure it out for yourself, bubba." See what I'm getting at? Your flexibility is already gone at this point. I'm not advocating taking away any more. I'm just advocating a mechanism for reporting these incompatibilities, so when you are hit with this problem, you can very quickly assess what went wrong and make an adjustment. Sean O'Dell