Welcome! Please see the About page for a little more info on how this works.

+3 votes
in Syntax and reader by

It's common to require "deep" namespaces and alias them to something shorter. Example:

(require '[my.deep.namespace.db.utils :as utils])

Sometimes though you want a little bit more context in the alias:

(require '[my.deep.namespace.db.utils :as db.utils])

This seems to work but the reference for the Reader says:

'.' has special meaning - it can be used one or more times in the middle of a symbol to designate a fully-qualified class name, e.g. java.util.BitSet, or in namespace names. Symbols beginning or ending with '.' are reserved by Clojure. Symbols containing / or . are said to be 'qualified'.

Emphasis: or in namespace names -- does this include the case of namespace aliases, or should it be avoided because it works only because of backwards compatibility?

The alternative could be something like:

(require '[my.deep.namespace.db.utils :as db-utils])

2 Answers

+4 votes

That said, because this is uncommon

At the company that I work, is a good pattern:

[com.company.project.lib.entity :as lib.entity]

If that's a known convention in context, then seems fine.
+1 vote

Aliases are only used as namespace names in symbols (never by themselves), so I would interpret this as being covered under "in namespace names".

That said, because this is uncommon, I think there is a risk for human readers of the code to mistake a dotted alias as a fq namespace name so consider that re readability.