tags:

views:

61

answers:

2

Is there a runtime overhead if I use this sort of decoration?

get_next_state(_SPid=undefined, _NextPort=undefined) ->
    stop;
+3  A: 

No, there is no overhead. You can check if you make a dummy module with and without the decoration and compile it using the 'S' flag.

Zed
+1  A: 

It's not a decoration, but an alias. It allows to you both have your cake and eat it. You can both have a pattern which is matched as usual and have a variable which is bound to the corresponding part of the term. So in

foo([a,b,c|_]=List) -> ... .

will match a list with the first 3 elements a,b and c and bind List to the whole list. It can be used anywhere in a pattern and is useful as it can save you from rebuilding the term. Using it as a form of comment is no problem but I honestly don't see the point of it, it just clutters up the head. I would write your example as

%% get_next_state(SPid, NextPort) -> ... .

get_next_state(undefined, undefined) ->
    stop;
rvirding
rvirding: (1) I didn't know how to call this idiom, now I know thanks to you. (2) I know I can use the shorthand without the alias, I just find this idiom for enhancing clarity without having to write a documentation block. I do this for simple/private functions.
jldupont