Reputation: 693
Can anyone explain or point me to where I can find clojure's naming conventions for:
Upvotes: 58
Views: 22405
Reputation: 106351
You might want to look at the Clojure library coding standards on the developer Wiki - this is probably the most comprehensive list that I've seen.
Update: link above seems to be dead, consider instead: https://clojure.org/dev/contrib_howto#_coding_guidelines
To your specific points:
Upvotes: 54
Reputation: 10264
There is an interesting set of naming conventions documented in a comment by Taoensso in his Encore library.
He proposes names using !
for side-effects, ?
for booleans,
$
for expensive operations, _
as dereffable,
*
for macros; plus a few other combos.
Upvotes: 3
Reputation: 958
There are some interesting guidelines on naming written by Stuart Sierra which suggest that:
age
instead of calculate-age
)create-
for constructing and get-
for retrieving), reserving the bang swap!
changes to mutable references.send-message
instead of message
)connection
instead of ->connection
) except when the input type must be explicit (input-type->output-type
)products/price
instead of products/product-price
) and prevent local clashes in let bindings-fn
suffixUpvotes: 12
Reputation: 4233
Even though you didn't ask for it explicitly, I'll explain what I've seen for protocol naming conventions.
Typically, the name starts with an uppercase "I" and then the rest is camel case, where the first letter of each word is capitalized, and the rest is lower case. For example, I want to define a protocol for rocket ships, I'd use the name IRocketShip
I've also seen 'A' instead of 'I' used, probably to represent the word 'abstract'.
Upvotes: 0