Skip to content

Naming function arguments #38

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

Open
ghost opened this issue Oct 21, 2015 · 5 comments
Open

Naming function arguments #38

ghost opened this issue Oct 21, 2015 · 5 comments

Comments

@ghost
Copy link

ghost commented Oct 21, 2015

Dear emacs-lisp-style-guide,

I've always been afraid of naming things. Things began to go wrong when as a child I named my pet hamster C-x C-( # and all the kids in the school's vim user group made fun of me. A year later I named my pet chimpanze "grandma" and got no present for christmas! I had to steal some tinsel off the tree and take it to school pretending it was a new brand of "soft, linear slinky". It's just so difficult! The uncertainty and arbitrariness involved always make me feel like I've made the wrong choice and It has always been an endless source of mental anguish. That is why I am so glad to have a resource such as this, so that now when I make a bad choice I can simply point at someone else and claim "They made me do it!", just like that murder trial they put me through.

Ever since I began using your guide my life has been transformed. I now feel dynamic and vivacious, even vigorous. My wife tells me I've grown several inches, an unexpected delight at my ripe old age of 117! and I'm getting taller too!

One nagging issue I still have trouble with, which this admirable compandium of sound advice has provided no guidance on thus far, is the question of properly naming a function argument when writing a higher-order function. Should I use a suffix like -func or -f? should I use a descriptive action name like score-of or compare? perhaps there is an even better way?

Anxiously Awaiting your Advice,

Kind regards,
Trepidatious in Trinidad

@dgutov
Copy link
Collaborator

dgutov commented Oct 21, 2015

For function arguments and local vars, the convention seems to be to use -fun. Or simply call it fun when clarification is not needed.

@Malabarba
Copy link
Collaborator

pred and predicate are also common

@dgutov
Copy link
Collaborator

dgutov commented Oct 21, 2015

But if the clarification (which predicate) is needed, the convention is to end the variable name with -p (or without the hyphen):

http://www.gnu.org/software/emacs/manual/html_node/elisp/Type-Predicates.html
http://www.gnu.org/software/emacs/manual/html_node/elisp/Predicates-on-Numbers.html

@ghost
Copy link
Author

ghost commented Oct 21, 2015

Well, a function argument isn't necessarily a predicate.

@EvertonSilv
Copy link

👋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants