Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Use Macros appropriately #7

Merged
merged 1 commit into from
Sep 15, 2014

Conversation

elbrujohalcon
Copy link
Member

rule

Macros should not be used as abbreviations. Also, no code should be allowed in macros, except for extenuating circumstances which must be documented.

##### bad
-define(IS_VALID_SERVICE(__Service), lists:member(__Service, pg2:which_groups())).
-define(IS_VISIBLE_SERVICE(__Service), (lists:keyfind(__Service, 1, application:which_applications()) =/= false)).
reasoning

Having logic in macros obscures its meaning. If having the code there complicate the logic, or duplicates code, or the logic is not related to the location the macro is invoked, then the macro'ed code should be in a function, with a proper semantic name.

@igaray
Copy link
Member Author

igaray commented Sep 15, 2014

-1
I would actually go for Loic's "Don't use macros", period.
Use functions instead.

@unbalancedparentheses
Copy link

I never understood why people use so many macros. Functions are better, even for abbreviations.

@igaray
Copy link
Member Author

igaray commented Sep 15, 2014

Furthermore, some common exceptions may be added to relax restrictions:
"Do not use macros, except to add meaning to magic numbers (non-configurable values pertaining to the code's correct functioning) and when you require that arguments not be evaluated."

igaray added a commit that referenced this pull request Sep 15, 2014
…os_appropr

Suggestion: Use Macros appropriately
@igaray igaray merged commit 45af036 into master Sep 15, 2014
@elbrujohalcon elbrujohalcon deleted the elbrujohalcon.7.suggestion__use_macros_appropr branch September 15, 2014 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants