[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN]otate
- From: Philipp Janda <siffiejoe@...>
- Date: Thu, 25 Apr 2013 14:43:05 +0200
Am 25.04.2013 08:29 schröbte Geoff Leyland:
On 25/04/2013, at 10:02 AM, Philipp Janda <firstname.lastname@example.org> wrote:
Hello fellow Lua users!
Do you like Python's docstrings or their Lua equivalent?
Do you want your Lua function definitions to look like this ...
... to get type checking for function arguments and/or return values?
 does a similar argument-checking thing. It parses special LDoc comments (that LDoc now supports) and uses a hook, rather than a decorator (hooks are unfortunately very slow, but at least optional).
I think those tools have more chances of being successful if they reuse
information that is already there or at least has other benefits besides
type checking. It increases the motivation to actually write
annotations, and maybe you can even detect outdated documentation during
unit testing[*]. So reusing LDoc comments is a good idea, IMHO.
Comment syntax is inspired by , which is also an argument checker, and there was a conversation about argument checking last year 
There is also this wiki page, and some time ago I implemented the
typecheck decorator outlined here. But what upset me was that none of
my attempts at type checking could even handle the Lua standard library
(especially table.insert( table, [pos,] value ) was #$!%..., and return
values are not that easy either (e.g. somevalue _or_ nil,errormessage)).
Btw., that's also the reason why I'm not entirely convinced that
Luadoc's/LDoc's current comment format is the best fit for Lua.
I already knew about checks, and I like it because it requires little
code, and probably is faster than most other attempts (although I would
have merged the checks function and the checkers table into one
functable and returned it via require without setting a global). The
custom type functions for checks and annotate should be compatible.
[*]: Ahh, new idea: Unit testing using examples in the docstring ...