Staying Out of Trouble
Perhaps the biggest danger vars pose to the new Clojure programmer grows out of the fact that vars look a lot like the familiar variables that we find in traditional programming languages. And the name var doesn’t help.
Don’t try to use vars as variables. In particular, don’t rely on changing the value of a var to model the changing state of the outside world. Clojure has other, more appropriate tools for modeling the changing state of the world, tools that we’ll look at in Chapter 18, State.
Do use vars to weave the parts of your program together with intention-revealing names. For the most part you want to def your values, defn your functions, and then leave them alone. Yes, you can bind a symbol to a value with ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access