practicalli / practicalli/clojure

Clojure namespaces

Open
#44 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

clojure cli
Dominant language
Makefile
Stars
117
Forks
36
PR merge metrics
No merged PRs in 30d

Description

So what's the story on the 'project-name' subfolder under src/ in the standard Leiningen template? Is there a reason you don't want your source files to live directly under src/? Is there a situation where you'd want that subdir to be named something else, or to have multiple ones?
alexmiller 22:25
that ends up being the first segment of your project namespaces (edited)
generally, you're going to be mixing your code with other libraries, etc so it is a good and common practice to prefix all of the namespaces in your project with a common namespace prefix, ideally something that you "own" (reverse domain name, company name, trademark, etc)
so Clojure's own namespaces are things like clojure.string (where "clojure" is the common root)
if you just called it string, you'd be fighting with every other library and project that had a string namespace
hiredman 22:28
namespace names and file nesting in directories correspond to each other, and it is impolite to use a short non-segmented name (segments are separated by '.', each namespace segment corresponds to a nested directory) because of the possibility of collisions. the compilation model, how clojure generates bytecode in classes and names those classes is also effected by this, in that a non-segmented namespacee names result in classes in the global package (or whatever java calls it) and that is mostly considered poor practice to do on the java side of things
different tools handle the new project names differently, but with lein if you say lein new foo you get a foo.core namespace to start, but if you say lein new foo.bar/baz you get a foo.bar.baz namespace to start
seancorfield 22:39
The clj-new tool (for the new CLI/deps.edn tooling) won't let you specify a single segment project name. If you want foo.core, you must explicitly ask for it, but the readme explains that you should generally use project names like username/myproject to ensure that your namespaces follow good practices (username.project as the entry point). Where username would be your GitHub user name, for example, or your company's name or reverse domain name etc.
(unfortunately, not all project templates accept the username/project format, so you sometime have to use username.project instead, although some templates don't even accept that format either 😞 )

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the standard Leiningen template and the documentation around the src/project-name subfolder and namespace naming. Done means the rationale for namespace prefixes, directory nesting, and alternate or multiple subdirectories is documented, but this issue names no target file or test.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.