[erlang-questions] -spec notation for unexported functions?
Kostis Sagonas
kostis@REDACTED
Fri Jan 23 09:54:35 CET 2009
Adam Lindberg wrote:
> Hi,
>
> When using Dialyzer and augmenting the code with -spec specifications, what is the preferred level of brevity? For ALL functions in a module or only for the exported interface functions? Which way gives a more correct analysis?
This is an excellent question.
My approach is the following:
- Add specs for *all* exported functions.
To make sure I have not forgotten any I always compile with the new
compiler option +warn_missing_spec which warns for missing specs for
exported functions. This way, the module interfaces are checked for
violations.
- The above typically is enough, but to see whether some module-local
function might need a -spec, I run typer in the file (this is very
simple: typer file.erl) and inspect the specs that typer infers for
all module local functions. If they look OK, then I stop there.
If some of them look too weak, e.g. an argument is inferred to be
the any() term when I intend to use that argument with an integer(),
then I add a few -specs for these functions too. Typically, this
action strengthens some more inferred -specs for module-local
functions.
Kostis
PS. The emacs support for -specs and -types is indeed missing, but we
lack the expertise to fix it. Help on this one is appreciated.
More information about the erlang-questions
mailing list