From: Greg McIntyre Date: 2003-11-21T09:37:16+09:00 Subject: Re: New Type Checking System Idea I like your idea, Sean, but it's too much effort! If it is onerous then it won't be used. Perhaps if we based it upon method name and arity (essentially replacing a bunch of respond_to?() calls with arity checks added in as a bonus). This is because it requires no extra effort on the programmer's part, so it fits into the existing Ruby syntax. I took your code and rewrote it a bit... class IO class Stream def eof? # ... end end # Class IO::Stream defined. Interface IO::Stream defined: # [[eof?,0]] class InputStream < IO::Stream def read(maxbytes) # ... end end # Class IO::InputStream defined. Interface IO::InputStream # defined: [[eof?,0], [read,1]] end # Class IO defined. Interface IO defined: [] ### Example of class definition using an interface class Stdin implements IO::InputStream # Interface: [] # Needed: [[eof?,0], [read,1]] def eof? # ... end # Interface: [[eof?,0]] # Needed: [[eof?,0], [read,1]] def read(maxbytes) # ... end # Interface: [[eof?,0], [read,1]] # Needed: [[eof?,0], [read,1]] def someothermethod end # Interface: [[eof?,0], [read,1], [someothermethod,0]] # Needed: [[eof?,0], [read,1]] end # RUN-TIME CHECK: Promises fulfilled. Interface Stdin produced. ### Example of re-implementing class methods class Stdin def read(maxbytes=20) # do something different end # Interface: [[eof?,0], [read,-1], [someothermethod,0]] # Needed: [[eof?,0], [read,1]] end # RUN-TIME CHECK: Promises fulfilled. Interface Stdin kept. # => Warning, default value for maxbytes in method read may # never be used by interface(?) # => No warning, interface made more general(?) ### Example of breaking class interface class Stdin def read(maxbytes, retries) # do something different end # Interface: [[eof?,0], [read,2], [someothermethod,0]] # Needed: [[eof?,0], [read,1]] end # RUN-TIME CHECK: Promises broken. Interface Stdin deleted. # => Raise type error(?) ### Example of re-implementing object methods class << $stdin def read(maxbytes) # do something different again end # Interface: [[eof?,0], [read,1], [someothermethod,0]] # Needed: [[eof?,0], [read,1]] end # RUN-TIME CHECK: Interface fulfilled. No action taken. -- Greg McIntyre ======[ greg@puyo.cjb.net ]===[ http://puyo.cjb.net ]===