Skip to content
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

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
6 participants
@llasram
Copy link
Contributor

llasram commented Dec 20, 2014

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

No reason to avoid single-segment namespaces.
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
@bbatsov

This comment has been minimized.

Copy link
Owner

bbatsov commented Dec 20, 2014

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.

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 xxx.core namespace, but we have lein to blame for that. :-)

@arrdem

This comment has been minimized.

Copy link
Contributor

arrdem commented Jan 21, 2016

I have no particular objection to single segment namespaces. gen-class is a feature I almost never reach for, and I've found it expedient in the past, and for small namespaces.

@puredanger

This comment has been minimized.

Copy link

puredanger commented Jan 21, 2016

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. :)

@alexander-yakushev

This comment has been minimized.

Copy link

alexander-yakushev commented Jan 21, 2016

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.

@danielcompton

This comment has been minimized.

Copy link
Contributor

danielcompton commented Jan 21, 2016

Single segment namespaces have problems in ClojureScript as well.

[David Nolen] Compiler support for single segment namespaces has always been spotty and there's no intention to improve it. There are fundamental semantic issues - for example if you have a DOM element with a CSS id and you haven't supplied a namespace but you goog.require one with that name it will return the DOM element. Good luck debugging that.

Single segment namespaces are nearly alway representative of a problem waiting to manifest. If you want to use them then you can suppress the warning in your build options.

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.

@bbatsov

This comment has been minimized.

Copy link
Owner

bbatsov commented Jan 24, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.