Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with single segment namespaces?

Tags:

I have read in several places that single segment namespaces are discouraged in clojure.

Indeed almost every library I've seen has (require 'lib.core) instead of (require 'lib).

Why?


Edit: I am a bit stupid. Extra credit will be given for a concise example of how a single segment namespace might be a bad thing.

like image 336
John Lawrence Aspden Avatar asked Nov 26 '12 14:11

John Lawrence Aspden


2 Answers

Java discourages the use of the default package because you can't refer to anything in it from any other package. If you pre-compile a one-segment Clojure namespace, you'll get a Java class in the default package. If anyone at any time wants to use your library from Java, he will be stopped dead by this triviality. As there is no good reason in favor of using a single-segment namespace, and there is this one well-defined reason not to, it is fair to say that single-segment namespaces should be a discouraged practice in Clojure.

like image 54
Marko Topolnik Avatar answered Oct 04 '22 15:10

Marko Topolnik


Single segment namespaces have issues with Java interop. Some things may break in unexpected ways. See also https://groups.google.com/forum/?fromgroups=#!topic/clojure/gOffhotk25Y

like image 38
Joost Diepenmaat Avatar answered Oct 04 '22 14:10

Joost Diepenmaat