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 ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.