Hi guys : In java we've all had the experience of using our ide to "traverse" down the depths of a complex data type :
dog.getCollar().getCollarTag().getName();
However, in Clojure, this becomes non trivial, due to the lack of static typing. How do we "defend" or Clojure against complexites that might arrive from nested data structures?
1) An advisable "limit" to the depth of clojure data structures ?
and
2) A common idiom for dealing with abritrarily deeply nested data structures, which prevents errors such as mistaking a list for map, or failing to correctly lower/upper case a variable name ?
Forgive me if I'm sounding a little off paradigm here ... It might be the case that such errors are efficiently curbed by continually testing in the REPL .. However, I was wondering if there are any other methods for making sure, at compile time, that code is as correct as possible (i.e. unit tests, IDE / emacs plugins, etc...)
Testing the correctness of your functions in the REPL is a good start. A good way to improve on that are unit tests and perhaps usage of pre- and postconditions (http://objectcommando.com/blog/2010/03/07/design-by-contract-with-clojure/).
When using keywords your example can be turned into
(get-in dog [:collar :tag :name])
. And "modifications" withassoc-in
orupdate-in
.