lua-users home
lua-l archive

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


Thatcher Ulrich wrote:
Static typing is really effective at finding some kinds of errors.
But I have a feeling it would add too much size and complexity to Lua.

Fear, uncertainty, doubt. The proposed type system is very light weight: The types are opaque. You can give a name to a type structure, but you do that by example. There is no syntax to build the type structure explicitly. So the changes to the syntax are minimal: Optional type specifiers in a few productions, and a very simple production for the type names themselves.

There are no changes in language semantics, so therefore there are no changes to the bytecode generator, the bytecode itself or the runtime API. It is possible for the compiler to use the type information to optimise the bytecode, but that is purely optional.

The changes can be put into a separate typing pass right after parsing, or it could even be a part of the parsing.

I believe this is a very light-weight proposal.

Also, it is the standard way of catching the class of errors we are discussing. Yes, some subset of the problems can be caught by extending lint, special casing globals and other such tricks like this, and that is what we have today. These solutions are not satisfactory, because they only handle special cases, are not portable, and are not integrated with IDEs. When there is a problem, the programmer does not understand what cases are caught by the checker, and which are not.

I believe there is a large class of errors which could be caught by static type checking. This is not restricted to misspelled variables. It is also expressions involving the wrong existing variables, which are automatically converted to the required type and thus not discovered until runtime.

If you add a light weight type system, you give the programmer better control and a more familiar environment. You put him in control of what needs checking and what need not, and he will feel right at home.

Compare to the upvalues in Lua: Those were a neat little trick, which solved a large part of the problem. But programmers were not used to just a concept, and in the end, we ended up with traditional static typing, and I believe everybody agrees that this is much better.

The same principle applies here: Go for the standard solution from the start, rather than some non-standard, special case solution.

Regards,
Asger Ottar Alstrup