3 ms·
> As it is, the 'module' concept is strictly tied to a file, which feels unnecessary. In the case of Clojure specifically; I'm not sure I've ever seen a concep
by roenxi 7y ago
> As it is, the 'module' concept is strictly tied to a file, which feels unnecessary.
In the case of Clojure specifically; I'm not sure I've ever seen a concept of a 'module'. Clojure has a concept of a 'lib' [0] which is an artifact left over from being implemented on Java. The internal concept to Clojure for dividing up code is the namespace [1] which has no concept or link to files at all.
There are two things going on here. First is the text files of source code on your computer that the build systems or what have you are interacting with. They are organised into files because storing code on a filesystem demands it. The second is once the code is parsed and moves into RAM those concepts fall away fairly quickly and you should be left mainly manipulating namespaces which are only linked to files if programmers want them to be.
If you develop a build system that loads code from a database of some sort then it probably wouldn't have a concept of files, but I don't think anyone has come up with an impressive model for what the advantage is to that. You'd have to reimplement Git and create an Emacs extension to interface with the database; so there would need to be a big benefit to justify the cost.
> My mental model of top-level execution is an implicit `(do ...)` block. In rest of clojure code the `do` is a special form that is frowned upon because it is used only when side-effects are necessary.
Clojure isn't about ideological purity. If it seems that way it is only because Rich Hickey believes strongly that ideologically disciplined code is easier to debug. (do [...]) clauses are only a problem if they are being used in preference to an alternate way that is easier to test and debug.
[0] https://clojure.org/reference/libs https://clojure.org/reference/libs
[1] https://clojure.org/reference/namespaces https://clojure.org/reference/namespaces
- jmiskovic 7y agoThank you for this wonderful explanation. Here are benefits that I think might justify the cost. - Easier code browsing: What is the body of this function? What are some optional arguments not used here? Where else is this function called from? - When teaching, ability to chose depth of visible code means more focused learning. For example, start from overview algorithm with function code collapsed, and then expand one by one to dive into each. - Reduced mental overhead due by eliminating concept of 'physical' location of code. No refactoring to extract common code into separate module, just reference same subtree from multiple locations. - Persistent code structures would allow for specializing a function to work differently in one place, while other callers still point to older implementation (until you decide that new implementation is superior). - A more strict tree-based approach to code would bring in many more visualization and manipulation techniques. It would be sort of seamless blend between text-based and visual programming. Regarding Git capabilities, I feel that Datomic model would provide much of same benefits. It would even allow for complete history of development without manual effort of checking in. Of course, talk is cheap and these are just random ideas. I'm not really complaining about Clojure. Its success is mostly due to pragmatic choices. I'm more curious has anyone put serious thought into purely tree-based lisp, and decided that it is somehow worse than top-level + s-expressions?
- stonemetal12 7y agoAre you suggesting an image based model like smalltalk? >Easier code browsing At the cost of throwing away all the standard tools and starting from scratch. No files means no grep, no emacs, no nothing until a replacement, plugin, or work alike is built.