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

Loïc Hoguin essen@REDACTED
Thu Sep 25 00:18:54 CEST 2014


On 09/25/2014 12:47 AM, Michael Truog wrote:
> 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.

I think this makes sense, though "callback_optional" is a bit weird to 
read. Regardless of the actual name chosen I find the one liner easier 
to read than separated like option 2. I wish I could define and export 
types in one line too.

-- 
Loïc Hoguin
http://ninenines.eu



More information about the erlang-questions mailing list