emacs-lisp-style-guide icon indicating copy to clipboard operation
emacs-lisp-style-guide copied to clipboard

Naming function arguments

Open ghost opened this issue 8 years ago • 5 comments

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

ghost avatar Oct 21 '15 09:10 ghost

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

dgutov avatar Oct 21 '15 09:10 dgutov

pred and predicate are also common

Malabarba avatar Oct 21 '15 10:10 Malabarba

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

dgutov avatar Oct 21 '15 11:10 dgutov

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

ghost avatar Oct 21 '15 13:10 ghost

👋

EvertonSilv avatar Nov 25 '22 03:11 EvertonSilv