Why clojure libraries do not try to use unique names for common function names

Why are clojure libraries reusing common function names, making you a namespace suitable for them? For example, clojure.zip uses the following, replaces and removes which already exist in the clojure kernel and "replace" already exists in clojure.string.

Now the developer will probably use some abbreviation for the clojure.zip namespace so in one clojure.zip/next developer code there will be a namespace qualified as z / next, in the code of the other person as w / next, etc. This will force you to look back to see that the abbreviation for the namespace is actually that the developer could create his own library, which also uses the "next" function

Why not zip-next, zip-replace and zip-remove, str-replace? Or something like that

Then there will be a consistent “namespace qualification” in the people’s code, and it will be clear what these functions refer to.

It does not seem that there are conflicts between the libraries between the names. Usually I see only two or three. Is it difficult to explicitly identify these names in the library?

+8
clojure space
source share
2 answers

In general, using use to include libraries is less popular than using require in a normal clojure image, so using longer unique names is less useful when the namespace already conveys the same value , so clojure programmers tend to consider brevity unique.

instead:

 (use 'liba 'libb) (liba-foo 1 2 3) (libb-foo 1 2 2) 

people could write:

 (require ['liba :as 'a] [libb :as 'b] ) (a/liba-foo 1 2 3) (b/libb-foo 1 2 3) 

which makes liba seem dumb therefore:

 (a/foo 1 2 3) (b/foo 1 2 3) 
+20
source share

If you want names to be globally unique, why do namespaces exist at all? If I define an icecream library and prefix each function name with icecream, no one will be able to collide.

But this is terribly inconvenient for both sides - we all have to keep typing this stupid prefix over and over again. If, instead of icecream-scoop, I simply call my scoop function inside the icecream namespace, you have a choice how to access it: you can call it scoop if it is cleared from the context and does not interfere with your namespace, or icecream / scoop or desserts / scoop, whatever you do so that it reads well.

+9
source share

All Articles