On Feb 7, 2006, at 2:18 PM, Erik Veenstra wrote:

>
> I had a discussion with a friend. A Java guy. He wants the
> arguments of a method call being checked. "I want the first one
> to be an Integer. And the second one is a String. Period." No
> discussion. I explained our duck-typing paradigm. He's not
> convinced. He thinks Java. So, he gets Java.
>
> Lets check the types of the arguments of a method call!
>
> (This post is not about type checking at all. It's about how to
> implement such a type checker. Or, more general, it's about
> monitoring-functions.)
>
> I wanted to do this with a nice and clean implementation, with
> the real magic pushed down to a place I would never come again
> ("write once, read never"). I wanted something like this (focus
> on line 7):
>
>      1   class Foo
>      2     def bar(x, y, z)
>      3       # x should be Numeric
>      4       # y should be a String
>      5       # z should respond to :to_s
>      6     end
>      7     typed :bar, Numeric, String, :to_s   # !!!!!
>      8   end
>
> Focus on line 7, once again. Make it three times. It's all
> about line 7.
>
> That was good enough for him. "But you can't do this. You
> simply can't. That's magic." I laughed at him, turned around
> and did it...

For bonus points, record stats for every time your assertion fails  
and you generate a "type error" compared with every time it does  
nothing.  Hopefully you can show your coworker how useless the code  
really is.

-- 
Eric Hodel - drbrain / segment7.net - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com