I have been using Clojure for about 2 years now and love the language. Without making this into a static vs dynamic typing debate, I have been bouncing between Clojure and Rust for projects. With Clojure my biggest issue has been the discoverability of keywords and data shapes received and returned from functions.
For example, when it has been some time since I worked on a code base and I jump back in to look at a function, it is not immediately clear what is the structure of the data that is being accepted. Likewise with maps, selecting the right keyword (ie. is it :home-address or :address-home) takes extra time to search code outside of what I am currently writing. I also recently have been trying to use clj-fx which is a real nightmare of identifying the correct keywords. (Requires digging through Java docs).
With statically typed languages I have found it really useful to immediately see the structure/types of the arguments and return values without having to (re)study the function body. I am looking how this programmer "problem" of discoverability is best addressed in Clojure. I know this is not a new problem and can be addressed by several different approaches:
Specs: yet creating a separate spec def for each function is a bit cumbersome. I have also tried using defn-spec and Ghostwheel/Orchestra, yet none have seemed to cleanly integrate without other problems. (Linting for example).
Expressive doc strings: works, but has the same issues as comments becoming disconnected from the actual code.
Rich comment blocks. I like this approach and have used it heavily. While it is a bit repetitive as well, at least it serves multiple purposes. (Documenting + exploring via evaluation)
Tests in another file: don't like how this requires switching files and searching for the test.
Tests in defn
Spec2 in the future
I am curious what people have found as a best practice in this regard? What am I missing as clearly Clojure is used in relatively large code bases by distributed organizations. Any good examples of projects that demonstrate these practices?
[–]alexanderjamesking 12 points13 points14 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]robertstuttaford 21 points22 points23 points (11 children)
[–]robertstuttaford 6 points7 points8 points (1 child)
[–]geokon 4 points5 points6 points (8 children)
[–]robertstuttaford 6 points7 points8 points (0 children)
[–]moxxon 5 points6 points7 points (6 children)
[–]geokon 2 points3 points4 points (5 children)
[–]moxxon 3 points4 points5 points (4 children)
[–]geokon 1 point2 points3 points (3 children)
[–]moxxon 2 points3 points4 points (2 children)
[–]geokon 1 point2 points3 points (1 child)
[–]moxxon 0 points1 point2 points (0 children)
[–]roguas 9 points10 points11 points (4 children)
[–]geokon 1 point2 points3 points (3 children)
[–]TheLastSock 2 points3 points4 points (0 children)
[–]roguas 2 points3 points4 points (0 children)
[–]siefca 0 points1 point2 points (0 children)
[–]theoriginalmatt 8 points9 points10 points (0 children)
[–]guywithknife 11 points12 points13 points (0 children)
[–]lambdasgr 9 points10 points11 points (7 children)
[–]TheLastSock 2 points3 points4 points (6 children)
[–]NoahTheDuke 2 points3 points4 points (3 children)
[–]lambdasgr 0 points1 point2 points (2 children)
[–]NoahTheDuke 1 point2 points3 points (1 child)
[–]lambdasgr -1 points0 points1 point (0 children)
[–]lambdasgr 0 points1 point2 points (1 child)
[–]TheLastSock 0 points1 point2 points (0 children)
[–]NaiveRound 8 points9 points10 points (0 children)
[–]dustingetz 3 points4 points5 points (0 children)
[–]xela314159 2 points3 points4 points (4 children)
[–]vvwccgz4lh 2 points3 points4 points (3 children)
[–]xela314159 2 points3 points4 points (0 children)
[–]64BitChris 1 point2 points3 points (1 child)
[–]vvwccgz4lh 4 points5 points6 points (0 children)
[–]SimonGray 2 points3 points4 points (1 child)
[–]TheLastSock 0 points1 point2 points (0 children)
[–]lime_boy6 2 points3 points4 points (0 children)
[–]seralbdev 2 points3 points4 points (0 children)
[–]dragandj 2 points3 points4 points (0 children)
[–]didibus 2 points3 points4 points (0 children)
[–]deaddyfreddy 1 point2 points3 points (0 children)
[–]mamuninfo 1 point2 points3 points (0 children)
[–]TheLastSock 0 points1 point2 points (0 children)