[erlang-questions] Specs for optional callbacks (try 2)

Kostis Sagonas kostis@REDACTED
Wed Sep 24 23:04:15 CEST 2014


On 09/24/2014 07:52 PM, Loïc Hoguin wrote:
> So let me ask again, is there any plans for adding something like
> -optional_callback that would do the same as -callback except it would
> not require the callback to be defined? Basically Dialyzer would use it,
> and the compiler wouldn't fail if the callback is missing.

I think this proposal makes sense, if this situation is indeed quite 
common in user-defined behaviors.

One question, esp. if the numbers mentioned below are indicative of 
expected uses of this feature is whether it makes sense to introduce yet 
another spec-variant attribute named -optional_callback to specify the 
types of optional callbacks or uniformly keep the -callback attribute 
for specifying the types of all callbacks and introduce just a 
declaration of which callbacks are optional.

If the previous sentence is too complicated, I am asking which of the 
two proposals below is preferable:

%%----- option 1 -------

-callback foo(...) -> ...
-callback bar(...) -> ...
-optional_callback baz(...) -> ...
-optional_callback boo(...) -> ...


%%----- option 1 -------

-callback foo(...) -> ...
-callback bar(...) -> ...
-callback baz(...) -> ...
-callback boo(...) -> ...

-optional_callback([baz/3, boo/17]).


The two possibilities sketched above have pros and cons, both technical 
and aesthetic ones.  Any opinions?

> As it stands now I am about to remove most -behavior in Cowboy because
> they're starting to make little sense because most callbacks become
> optional. The simplest handler type will have 3 possible callbacks, 2
> being optional. The most complex handler type already has 20+ callbacks
> with only 1 required.

Kostis



More information about the erlang-questions mailing list