From: Sean O'Dell Date: 2003-11-20T04:37:50+09:00 Subject: Re: "stereotyping" (was: Re: Strong Typing (Re: Managing metadata about attribute types) On Wednesday 19 November 2003 11:05 am, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: "stereotyping" (was: Re: Strong Typing (Re: Managing > metadata about attribute types)" > > on 03/11/20, "Sean O'Dell" writes: > |A contract is any interface, and a Ruby class is an interface. True, a > | Ruby class isn't the definition of a contract, but any OO class serves > | the function well enough. Despite Ruby's flexibility, at any given > | point, a class implements an interface. It can be extended or changed, > | but it definitely describes an interface. > > A class has interface; a class can be used as interface (by set of its > methods); but it should not be checked by kind_of? or anything based > on inheritance, just because it hinders flexibility of dynamic typing > so much; remember StringIO or tempfile examples. But again, that flexibility is LOST when you have to pass an object to a method that REQUIRES it to behave a certain way. The flexibility is already gone; it wasn't eliminate by a language quirk, it was eliminated by the need of the method being called. > |It's just informational. It's just for the purpose of speeding up > | development and making the code a little more robust through a good > | report of what is going wrong when someone passes in an object that can't > | be used by the method. It doesn't prove that an object correctly > | implements an interface, and the object can definitely break the > | interface, but the facility would be there for programmers who can make > | use of it. For those that tend to break interfaces when programming > | rather than use them properly, there are always QA jobs. =) > > I admit type checking can gain you something, at the cost of > flexibility, which I don't want to pay in Ruby. If you prefer static > typing to dynamic typing, it's OK, there so many statically typed > languages out there. Go ahead. No, I prefer BOTH. There are times when dynamic typing works, and times when you need enforcement of an interface. I'm clear on the subject of dynamic typing, and I'm not an advocate for static typing. Being a strong advocate for one or the other is foolish, in my opinion. Both are useful, and both can be employed here, so I BEG you to please employ SOME form of built-in interface checking. Having absolutely NO mechanism leaves people who need to check for certain methods and parameters hanging in the wind. I'm only talking about checking that a certain interface is present. Just for the purpose of providing an informative error message when an object which cannot fulfill the needs of a method is passed. Right now, it just explodes with an ugly message about something that happened deep in the called method. Something more informative would go a LONG way. Reconsider, Matz. Sean O'Dell