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

Michael Truog mjtruog@REDACTED
Wed Sep 24 23:47:48 CEST 2014


On 09/24/2014 02:04 PM, Kostis Sagonas wrote:
> 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(...) -> ...

I prefer option 1 because I find it more immediately descriptive. However, I think the ordering is better as "callback_optional" since it is definitely a callback (like the other callbacks), "optional" is just a adjective to modify what type of callback is being defined.  So, having "callback" first provides a contextual scope and an aid for the human eye as it tracks from the upper-left to the lower-right.

>
>
> %%----- 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
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list