From: Austin Ziegler Date: 2003-11-20T06:03:54+09:00 Subject: Re: "stereotyping" (was: Re: Strong Typing (Re: Managing metadata about attribute types) On Thu, 20 Nov 2003 03:52:30 +0900, Sean O'Dell wrote: > On Wednesday 19 November 2003 10:27 am, David A. Black wrote: >> A Ruby module or class is neither a contract, nor a fixed >> collection. I really don't think, for example, that what Betrand >> Meyer meant by "design by contract" was Ruby classes :-) > 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 defines a collection of methods that could be called an interface. However, an instance of a Ruby class need not implement that interface. Again, a pathological example: f = File.open("foo.txt") class << f undef write end The object referenced by f *is* a File, but it doesn't support #write. >> What you're doing is pressing the closest thing Ruby has to >> something that *looks* like the kind of type-checking you want >> (i.e., kind_of?) into service as a type check, which it isn't. > Yes, but no one cares if an object being passed in is really of a > certain type, all they care about is if it has the interface their > method(s) need. I don't want a type check, I just want some > enforcement that an interface exists where I need it. Which #kind_of? does *not* do. *Why* do you want or need that enforcement? When I first used dynamic languages, I wanted them to act like the static languages that I worked with, but I quickly grew out of it. I briefly experimented with #kind_of? checking in Ruby, but found few cases where I really needed it. -austin -- austin ziegler * austin@halostatue.ca * Toronto, ON, Canada software designer * pragmatic programmer * 2003.11.19 * 15.53.42