-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No reason to avoid single-segment namespaces. #100
Conversation
Clojure namespaces with `gen-class` map to classes with the same full name as the namespace. This produced some concern about single-segment namespaces being equivalent to Java package-less classes and a cargo-culting avoidance of single-segment namespaces. In practice non-`gen-class` single-segment namespaces do not appear to cause any known problems, and have begun to appear in libraries by well-respected Clojure community members, such as Brandom Bloom’s backtick [1]. [1] https://github.com/brandonbloom/backtick
Yeah, this is why we introduced this rule in the first place. What you're saying sounds reasonable, but I'd like to do some digging first (and perhaps hear more comments). Btw, probably it still makes some sense to suggest that projects should use multi-segment namespaces when they have more than a single namespace. I also have a feeling people are abusing the |
I have no particular objection to single segment namespaces. |
Namespaces exist to disambiguate names. Using a single segment namespace puts you in direct conflict with everyone else using single segment namespaces, thus making it more likely you will conflict with another code base. So, for libs, I think it's a very good idea to use a first segment for context vs every other lib you might include. Within your own private app of course, you can do whatever you like. :) |
For what it is or isn't worth, Android doesn't support single-level packages, probably for good reasons. Besides, dot in a package name is a useful telltale sign for different tools (like clojure-mode) to know something is a package/namespace or a class. |
Single segment namespaces have problems in ClojureScript as well.
You'll get warnings in ClojureScript by default when compiling single segment namespaces. IMO everything in the design of Clojure, the JVM, and ClojureScript seems to be pushing away from single segment namespaces. The only benefit from single segment namespaces (I think?) is a slightly more elegant ns declaration. While that's nothing to be sniffed at, IMO it's not a big enough gain. People can do whatever they want in their own code, but in the de facto style guide for Clojure, I think single segment namespaces should be avoided. |
I guess the best we can do is to extend the rationale behind the existing rule then. In general a lot of rules in the guide could benefit from extended rationale, but I've been pretty short on time lately. |
Should this PR be closed now given the above discussion? Maybe just have the default be something like |
I didn't close it simply because for me it served as a reminder to move some of this conversation to the style guide. Alas, I never got to doing this. :-) |
And I finally converted this reminder to improvements in the guide. Thanks to everyone who participated in the conversation! |
Clojure namespaces with
gen-class
map to classes with the same full name as the namespace. This produced some concern about single-segment namespaces being equivalent to Java package-less classes and a cargo-culting avoidance of single-segment namespaces. In practice non-gen-class
single-segment namespaces do not appear to cause any known problems, and have begun to appear in libraries by well-respected Clojure community members, such as Brandom Bloom’s backtick [1].[1] https://github.com/brandonbloom/backtick