[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: how to prevent bugs without static type checking?
- From: "Thijs Schreijer" <thijs@...>
- Date: Wed, 24 Oct 2012 11:43:47 +0200
> Behalf Of Geoff Leyland
> Sent: woensdag 24 oktober 2012 10:29
> Subject: Re: how to prevent bugs without static type checking?
>
> > On 24/10/2012, at 8:47 PM, steve donovan <steve.j.donovan@gmail.com>
> > wrote:
>
> > Beyond primitive types we get the 'type description' problem. Say
> > someone defines a type Foo, somewhere. A useful discipline is to use
> > named types as much as possible in code, because it's easier to
> > document.
> >
> > But checking an argument of type 'Foo' requires some assumptions about
> > how objects are organized - they have a metatable yes, but where to
> > put the type's name? E.g. in Penlight the convention is that
> > getmetatable(obj)._name will be the name of the class, but this only
> > happens automatically if using the 'class.Frodo()' syntax. So even in
> > one library it's not a guarantee!
>
> At the moment it tries mt.__type, mt.__typename, mt.__typeinfo[type]
> (but not mt._name - I missed that!), then searches for globals and
upvalues
> with the same name as the type and checks if they match the metatable.
> You could easily make "type detectors" pluggable.
>
I think this could combine very well with this message;
http://lua-users.org/lists/lua-l/2012-10/msg00122.html
If the "typical" library by Rob Hoelz can be combined with my "typex"
library, then that could pretty much fill this gap.
A preprocessor that can be run on the command line (similar to LuaCov usage)
would be nice then to prevent extra manual steps in the process