On Feb 10, 2009, at 12:32 PM, Greg Harman wrote:
Let me offer a perspective coming from a Java background: I know that there are subtle differences between a namespace and a Java package, but I still tend to subconsciously consider them analogous: they are container structures for organizing code. The code itself (Java classes, or Clojure files with similarly-grouped functions in a namespace) gets organized into these containers. With this mindset, I've always found it a little counter-intuitive that all .clj files belonging to a particular namespace aren't stored in the same directory*. (This also helps a bit with organization at the file level).
There was a time when the layout was all in one directory:For ns a.b.c, there was a root directory a/b/c/ within which we had c.clj and at which any paths "relative to the namespace root directory" used by :load were rooted.
Currently in Clojure, all files associated with namespace a.b.c are (in the simplest case) in the directory "a/b", so they are all in the same directory, though not the one where a Java package of the same name would keep them.
It was with ahead-of-time compilation that this directory layout changed. Java packages are logically most analogous to Clojure namespaces, but where it's natural to break java packages down into one file per class, it was not natural to break Clojure namespaces into one file per function--even though that's how the mapping works under the covers.
Java, Package, group of Classes around a common theme, typically one file per Class Clojure, Namespace, group of Functions around a common theme, typically one file per Namespace
I think the biggest pragmatic difference boils down to the package/ namespace "bootstrapping." In Clojure, there is one file that "owns" the lib and declares the namespace with (ns) and manually loads the others, which include themselves in the namespace with (in-ns). In Java, every class declares the package, and any can stand alone to "bootstrap" the package (and Java itself loads the classes in). Now I'm not necessarily advocating to change Clojure namespaces to follow Java packages, but it is a subtle paradigm shift for people coming from Java that seems to regularly pop up as a point of confusion.
That's good to keep in mind. Do you have any suggestions for the docs around this that would have been helpful to you or might be to others from a Java background?
--Steve
smime.p7s
Description: S/MIME cryptographic signature