Search code examples
clojure

Naming convention for simbol of clojure.core/atom, like !foo in Clojure


I found a naming !video on Reagent docs.

(let [!video (clojure.core/atom nil)]
...)

https://github.com/reagent-project/reagent/blob/master/doc/FAQ/UsingRefs.md

I liked this rule of prefixing ! to signify mutation, but I couldn't find any information suggesting that it's a widely recognized convention within the Clojure community. Do you have any information on whether such a convention exists? Alternatively, are there any other naming conventions for representing atom variables?


Solution

  • I liked this rule of prefixing ! to signify mutation

    This does not signify a "mutation", it signifies a reference type. As in something that holds a value, which may change over time.

    As for your question, you can probably ask 10 people and get 10 different answers. This is extremely subjective. In the end does it matter whether this is "widely recognized" anywhere? If it makes sense to you, or your team, then by all means use it. Conventions are only useful if you think they are useful. As long as you are consistent, it really doesn't matter what you do. IMHO.

    This particular ! prefix I personally don't like because I find @!video visually "noisy". Yet, I agree that it is absolutely useful to "mark" names, to signify what they represent. I tend to use a -ref suffix instead, so video-ref instead of !video. I have never seen anyone else do that, but I still like it.