What does the Clojure Naming Convention mean?

Can someone explain or point me where I can find clojure naming conventions for:

  • File names
  • Functions (from what I understand, function names are just symbol-separated values)
  • Variables
+47
naming-conventions clojure
Jul 15 2018-11-15T00:
source share
4 answers

Perhaps you should take a look at the Clojure library coding standards on the Wiki developer - this is probably the most comprehensive list we have seen.

To your specific points:

  • The file names are lowercase and stored in a directory structure to match the namespace and end in .clj, for example. "My / special / namespace.clj
  • Functions are low-case-separated words that are ideally tentatively chosen so that your code is clear and self-documenting. Don't be afraid to reuse good function names in different namespaces (this is the namespace for!).
  • Variables (by which I assume that you mean parameters, related variables, etc.) are also usually separated by dashes. Since code-data-data, I think it is appropriate that functions and data have the same naming convention :-)
+41
Jul 15 2018-11-15T00:
source share
β€” -

You might want to take a look at this unofficial style guide .

+7
Dec 01 '13 at 0:21
source share

There are some interesting naming guidelines written by Stuart Sierra that suggest that:

  • pure functions should be nouns describing the return value ( age instead of calculate-age )
  • side effects should be verbs that describe the action ( create- to build and get- to extract), while maintaining the swap! binding swap! to mutable links.
  • verbs that may also be nouns should be distinguished as verb phrases ( send-message instead of message )
  • coercion must specify the type of output without the arrow prefix ( connection instead of ->connection ), unless the input type must be explicit ( input-type->output-type )
  • namespace aliases can save on repetition ( products/price instead of products/product-price ) and prevent local conflicts in binding bindings
  • function return functions must have the suffix -fn
+5
Mar 16 '16 at 14:25
source share

Even if you did not explicitly ask for this, I will explain what I saw for protocol naming conventions.

Typically, a name begins with an uppercase letter β€œI,” and then the rest is a camel case, where the first letter of each word is capitalized, and the rest is lowercase. For example, I want to define a protocol for rocket ships, I would use the name IRocketShip

I also saw "A" instead of "I," perhaps to represent the word "abstract."

0
Jul 15 '11 at 17:27
source share



All Articles