lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> > You type checking solution is clever, but I'm not sure it will solve the
> > problem you want to solve. The difference between what you're doing here
> > and what C or Java does when it type checks is *when* the type check
> > happens. In C and Java a type error is found at compile time, in your
> > program it's found at run time.
> 
> You're right, it's not as good, but it's an improvement. Dynamic checks 
> are what you get in Python and (sometimes, if you're typecasing) in Java.

I agree, it is better than nothing.

What we did in both of our larger Smalltalk projects, was let the
programmers decide when a value had to be type checked dynamically. We
tried to make it as painless as possible by providing sort, standard
methods for checking. We also had a standard where checks for parameters
went early in the method source so it was easy to see what the types
should be. For example:

    display: image at: p
            image isForm.
            p isPoint.
        "Display the image in the window at the given point."
    self context display: image at: p extent: image extent.


Which in Lua might be

    function Win:display(image, p)
        isForm(image)
        isPoint(p)
        self.context:display(
            image,
            p,
            image:extent())
    end

Your solution is more sophisticated, but I'd prefer to let the programmers
decide when a check is needed. Just my philosophy of development I guess.

  - Tom