Charles Hixson <charleshixsn / earthlink.net> writes: > Actually, I believe that you can implement a run-time constraint. > It just isn't obvious what kind of standardized action should be > taken. So it's not clear how the language could reasonably respond. > Also, it's not clear how one should declare a parameter to be of a > type. I guess I'm asking: what would the point be? If you pass in an object that you weren't expecting to receive, then you'll get an exception thrown when you try to use it and it contains the wrong methods. Is there much point in slowing down the language by adding parameter checking, that merely moves this exception throwing a few lines up the source code? > > Objective C had the concept of protocols, which are similar to > > Java's interfaces, which specified what messages an object > > supports. This _could_ be added to Ruby (I have a quick hack that > > implements them in Ruby itself). > > I think that Ruby already has such a list, but I could be confusing > it with Python (and don't know how to look this up quickly). This > isn't a formalized thing created for users. It's just that the > compiler uses a list to keep track of things, and that isn't hidden > away. (If you've done that "quick hack", then I'm sure you know > what I'm referring to.) My quick hack was different: you define a protocol as a set of method signatures, and then say that objects must implement that protocol. It checks dynamically as objects are mutated at runtime, so it should keep in step. I stopped working on it because I never really found the need to use it. I come back to an earlier question: > > However, let me ask a question: how often do you get bitten by this in > > reality? And, having been bitten, how long does it take to fix? I guess I could see a syntax like def fred(a : String, b : File) which added runtime checks that 'a' and 'b' were compatible with Strings and Files respectively, but I'd only support it if the qualification were optional. I'd personally use it mostly as a documentation tool. However, remember that this still isn't type checking. In Ruby, unlike Java and C++, classes and types are different beasts. Regards Dave