Clojure namespace conventions

206 views
Skip to first unread message

Paul Richards

unread,
Feb 23, 2011, 3:19:29 PM2/23/11
to clo...@googlegroups.com
Hi,
Is there a guide to the conventions for naming and structuring
namespaces in a Clojure project?

I see for example that the ".core" namespace is fairly common in
different projects. Is this also where the "-main" entry point should
live?

Also is it typical to have code living in "someproject" as well as
"someproject.tools", or should the former be promoted to
"someproject.core"?


--
Paul Richards
@pauldoo

Mark Rathwell

unread,
Feb 23, 2011, 3:35:19 PM2/23/11
to clo...@googlegroups.com

This discussion has been had multiple times on this list, not sure how much new information you will get.  See the following for a couple examples:

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Paul Richards

unread,
Feb 24, 2011, 5:48:44 AM2/24/11
to clo...@googlegroups.com, Mark Rathwell
My goodness.. Seems like a can of worms. :p

I think I'll pick something at least two levels deep like
"pauldoo.someproject", complete with ".core" and ".tools" as sub
namespaces..

--
Paul Richards
@pauldoo

Chas Emerick

unread,
Feb 24, 2011, 3:47:25 PM2/24/11
to clo...@googlegroups.com
FWIW, I've settled on cemerick.project-name as my default. I think the project-name.core convention cropped up because of hesitancy of some to use their name at the top level.

- Chas

Phil Hagelberg

unread,
Feb 24, 2011, 7:07:09 PM2/24/11
to Clojure
On Feb 24, 2:48 am, Paul Richards <paul.richa...@gmail.com> wrote:
> My goodness..  Seems like a can of worms.  :p
>
> I think I'll pick something at least two levels deep like
> "pauldoo.someproject", complete with ".core" and ".tools" as sub
> namespaces..

IMO adding ".core" indicates it's a "filler" segment that's only there
to get around the fact that you shouldn't have single-segment
namespaces. If you've already got two levels, there's no need for
a .core segment.

-Phil

Laurent PETIT

unread,
Feb 25, 2011, 1:06:54 AM2/25/11
to clo...@googlegroups.com, Phil Hagelberg
2011/2/25 Phil Hagelberg <ph...@hagelb.org>

One element to take into consideration : if you want your library to sometimes play well with e.g. OSGi, it would be better to have all of it into its own java package, since OSGi places "visibility directives" at the package level.

Indeed, imagine that in the future you have created 2 useful libraries : pauldoo.project1, and pauldoo.project2.

If both are independently released in their artifact (which would also happen to be OSGi bundle), there are 2 possibilities :

if pauldoo.project1 is a namespace, and pauldoo.project2 is a namespace, then both artifacts will have content in the package pauldoo, and thus both artifacts will be seen by OSGi as (potentially) "exporting" the package pauldoo. I'm not an OSGi expert, but this may or may not be embarrassing.

To the contrary, if you take care of having each library to not share content in a same package, eg. pauldoo.project1.core et al, then their (potential) export directive will not conflict with each other.

Cheers,

--
Laurent


Reply all
Reply to author
Forward
0 new messages