Erlang/OTP Forums

Author Message

<  Erlang patches mailing list  ~  Callback attribute for better definition of behaviour callba

Guest
Posted: Tue Jun 29, 2010 3:34 pm Reply with quote
Guest
Hi!

On March the following thread appeared in the erlang-questions list:

http://www.erlang.org/cgi-bin/ezmlm-cgi?4:sss:50104:201003:hbmaknhcnnhjngliogof

In that thread there was discussion about how the current idiom to define a
behaviour lacks specific information about what the callbacks are supposed
to do. The proposal was to somehow use '-spec' attributes in order to
provide better information about the type of the arguments that each
callback function requires and its result. This patch implements this using
a new attribute: '-callback'.

The reason why the already existent '-spec' keyword can't be used is that
lint checks are performed to ensure that specs exist only for functions
defined in the module where the spec is defined. This is not what a callback
function requires, as it's going to be defined in another module.

These '-callback' attributes can then be used to automatically generate the
usual 'behaviour_info(callbacks)' export, required by the compiler to
confirm that a module that implements a behaviour exports all the required
callbacks.

The patch can be obtained with:

git fetch git://github.com/aronisstav/otp.git callback-attr

Included in this patch are:

- updates in the syntax of Erlang (erl_parse.yrl) to allow the new attribute
with a form similar to that of the already familiar '-specs'
- updates in the lint (erl_lint) to ensure that no duplicates are defined
and no behaviour_info/1 function is defined as it will be automatically
generated and exported
- updates in the stdlib's, kernel's and inet's behaviours to use the new
syntax. The type information I've added is based on current published
documentation and comments in the files so it might be incorrect
and should be double-checked by someone who has more experience in the
actual usage of these behaviours than me.
- updates to the bootstrap files

Future additions:

- Dialyzer can use such attributes to find errors in the inferred callback
function types. (I've already implemented this but it's a different thing so
I'm gonna make a separate request for it)
- Documentation tools can use these attributes instead of comments to
specify the types of the arguments and the result of callback functions.

As this is my first patch, any feedback is gratefully accepted!

Stavros Aronis


Post received from mailinglist
Guest
Posted: Tue Jun 29, 2010 3:34 pm Reply with quote
Guest
Hi!

On March the following thread appeared in the erlang-questions list:

http://www.erlang.org/cgi-bin/ezmlm-cgi?4:sss:50104:201003:hbmaknhcnnhjngliogof

In that thread there was discussion about how the current idiom to define a
behaviour lacks specific information about what the callbacks are supposed
to do. The proposal was to somehow use '-spec' attributes in order to
provide better information about the type of the arguments that each
callback function requires and its result. This patch implements this using
a new attribute: '-callback'.

The reason why the already existent '-spec' keyword can't be used is that
lint checks are performed to ensure that specs exist only for functions
defined in the module where the spec is defined. This is not what a callback
function requires, as it's going to be defined in another module.

These '-callback' attributes can then be used to automatically generate the
usual 'behaviour_info(callbacks)' export, required by the compiler to
confirm that a module that implements a behaviour exports all the required
callbacks.

The patch can be obtained with:

git fetch git://github.com/aronisstav/otp.git callback-attr

Included in this patch are:

- updates in the syntax of Erlang (erl_parse.yrl) to allow the new attribute
with a form similar to that of the already familiar '-specs'
- updates in the lint (erl_lint) to ensure that no duplicates are defined
and no behaviour_info/1 function is defined as it will be automatically
generated and exported
- updates in the stdlib's, kernel's and inet's behaviours to use the new
syntax. The type information I've added is based on current published
documentation and comments in the files so it might be incorrect
and should be double-checked by someone who has more experience in the
actual usage of these behaviours than me.
- updates to the bootstrap files

Future additions:

- Dialyzer can use such attributes to find errors in the inferred callback
function types. (I've already implemented this but it's a different thing so
I'm gonna make a separate request for it)
- Documentation tools can use these attributes instead of comments to
specify the types of the arguments and the result of callback functions.

As this is my first patch, any feedback is gratefully accepted!

Stavros Aronis


Post received from mailinglist
Guest
Posted: Wed Jun 30, 2010 10:24 am Reply with quote
Guest
Two issues:

1) Your first commit (05ac0898ead518c92cd884bdbd2ffa78877f050b) adds a file
bootstrap/lib/stdlib/egenerl_parse.erl but there is already a generated
file bootstrap/lib/stdlib/egen/erl_parse.erl, which makes me suspect
you slipped on the keybord on this commit... Is that so?
2) All your commit taglines has a trailing dot, which we prefer not to
have, and if you are fixing the first commit, it is a good opportunity
to take care of this too...

On Tue, Jun 29, 2010 at 06:33:54PM +0300, Stavros Aronis wrote:
> Hi!
>
> On March the following thread appeared in the erlang-questions list:
>
> http://www.erlang.org/cgi-bin/ezmlm-cgi?4:sss:50104:201003:hbmaknhcnnhjngliogof
>
> In that thread there was discussion about how the current idiom to define a
> behaviour lacks specific information about what the callbacks are supposed
> to do. The proposal was to somehow use '-spec' attributes in order to
> provide better information about the type of the arguments that each
> callback function requires and its result. This patch implements this using
> a new attribute: '-callback'.
>
> The reason why the already existent '-spec' keyword can't be used is that
> lint checks are performed to ensure that specs exist only for functions
> defined in the module where the spec is defined. This is not what a callback
> function requires, as it's going to be defined in another module.
>
> These '-callback' attributes can then be used to automatically generate the
> usual 'behaviour_info(callbacks)' export, required by the compiler to
> confirm that a module that implements a behaviour exports all the required
> callbacks.
>
> The patch can be obtained with:
>
> git fetch git://github.com/aronisstav/otp.git callback-attr
>
> Included in this patch are:
>
> - updates in the syntax of Erlang (erl_parse.yrl) to allow the new attribute
> with a form similar to that of the already familiar '-specs'
> - updates in the lint (erl_lint) to ensure that no duplicates are defined
> and no behaviour_info/1 function is defined as it will be automatically
> generated and exported
> - updates in the stdlib's, kernel's and inet's behaviours to use the new
> syntax. The type information I've added is based on current published
> documentation and comments in the files so it might be incorrect
> and should be double-checked by someone who has more experience in the
> actual usage of these behaviours than me.
> - updates to the bootstrap files
>
> Future additions:
>
> - Dialyzer can use such attributes to find errors in the inferred callback
> function types. (I've already implemented this but it's a different thing so
> I'm gonna make a separate request for it)
> - Documentation tools can use these attributes instead of comments to
> specify the types of the arguments and the result of callback functions.
>
> As this is my first patch, any feedback is gratefully accepted!
>
> Stavros Aronis

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB

________________________________________________________________
erlang-patches (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-patches-unsubscribe@erlang.org

Post received from mailinglist
Guest
Posted: Wed Jun 30, 2010 10:24 am Reply with quote
Guest
Two issues:

1) Your first commit (05ac0898ead518c92cd884bdbd2ffa78877f050b) adds a file
bootstrap/lib/stdlib/egenerl_parse.erl but there is already a generated
file bootstrap/lib/stdlib/egen/erl_parse.erl, which makes me suspect
you slipped on the keybord on this commit... Is that so?
2) All your commit taglines has a trailing dot, which we prefer not to
have, and if you are fixing the first commit, it is a good opportunity
to take care of this too...

On Tue, Jun 29, 2010 at 06:33:54PM +0300, Stavros Aronis wrote:
> Hi!
>
> On March the following thread appeared in the erlang-questions list:
>
> http://www.erlang.org/cgi-bin/ezmlm-cgi?4:sss:50104:201003:hbmaknhcnnhjngliogof
>
> In that thread there was discussion about how the current idiom to define a
> behaviour lacks specific information about what the callbacks are supposed
> to do. The proposal was to somehow use '-spec' attributes in order to
> provide better information about the type of the arguments that each
> callback function requires and its result. This patch implements this using
> a new attribute: '-callback'.
>
> The reason why the already existent '-spec' keyword can't be used is that
> lint checks are performed to ensure that specs exist only for functions
> defined in the module where the spec is defined. This is not what a callback
> function requires, as it's going to be defined in another module.
>
> These '-callback' attributes can then be used to automatically generate the
> usual 'behaviour_info(callbacks)' export, required by the compiler to
> confirm that a module that implements a behaviour exports all the required
> callbacks.
>
> The patch can be obtained with:
>
> git fetch git://github.com/aronisstav/otp.git callback-attr
>
> Included in this patch are:
>
> - updates in the syntax of Erlang (erl_parse.yrl) to allow the new attribute
> with a form similar to that of the already familiar '-specs'
> - updates in the lint (erl_lint) to ensure that no duplicates are defined
> and no behaviour_info/1 function is defined as it will be automatically
> generated and exported
> - updates in the stdlib's, kernel's and inet's behaviours to use the new
> syntax. The type information I've added is based on current published
> documentation and comments in the files so it might be incorrect
> and should be double-checked by someone who has more experience in the
> actual usage of these behaviours than me.
> - updates to the bootstrap files
>
> Future additions:
>
> - Dialyzer can use such attributes to find errors in the inferred callback
> function types. (I've already implemented this but it's a different thing so
> I'm gonna make a separate request for it)
> - Documentation tools can use these attributes instead of comments to
> specify the types of the arguments and the result of callback functions.
>
> As this is my first patch, any feedback is gratefully accepted!
>
> Stavros Aronis

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB

________________________________________________________________
erlang-patches (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-patches-unsubscribe@erlang.org

Post received from mailinglist
Guest
Posted: Wed Jun 30, 2010 2:29 pm Reply with quote
Guest
On Wed, Jun 30, 2010 at 03:13:09PM +0300, Stavros Aronis wrote:
> Thanks for pointing these out!
>
> I've addressed the two issues mentioned and updated the patch.
>
> On Wed, Jun 30, 2010 at 1:23 PM, Raimo Niskanen <
> raimo+erlang-patches@erix.ericsson.se<raimo%2Berlang-patches@erix.ericsson.se>
> > wrote:
: :
> > On Tue, Jun 29, 2010 at 06:33:54PM +0300, Stavros Aronis wrote:
> > > Hi!
: : :
> > > The patch can be obtained with:
> > >
> > > git fetch git://github.com/aronisstav/otp.git callback-attr

Thank you! It will be included in 'pu'.

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB

________________________________________________________________
erlang-patches (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-patches-unsubscribe@erlang.org

Post received from mailinglist
Guest
Posted: Wed Jun 30, 2010 2:29 pm Reply with quote
Guest
On Wed, Jun 30, 2010 at 03:13:09PM +0300, Stavros Aronis wrote:
> Thanks for pointing these out!
>
> I've addressed the two issues mentioned and updated the patch.
>
> On Wed, Jun 30, 2010 at 1:23 PM, Raimo Niskanen <
> raimo+erlang-patches@erix.ericsson.se<raimo%2Berlang-patches@erix.ericsson.se>
> > wrote:
: :
> > On Tue, Jun 29, 2010 at 06:33:54PM +0300, Stavros Aronis wrote:
> > > Hi!
: : :
> > > The patch can be obtained with:
> > >
> > > git fetch git://github.com/aronisstav/otp.git callback-attr

Thank you! It will be included in 'pu'.

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB

________________________________________________________________
erlang-patches (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-patches-unsubscribe@erlang.org

Post received from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum