@@ -768,40 +768,64 @@ NOTE: This may appear to mask
768768(string/join ...)
769769----
770770
771- Some common, idiomatic aliases are shown below:
771+ As noted in the next section, it's generally considered idiomatic to use
772+ an alias that is the last segment of the namespace, if that makes it unique,
773+ or else the two segments, typically dropping redundant parts like `clj` or `core`.
774+
775+ Amongst Clojure's core and Contrib namespaces, the following namespaces have
776+ idiomatic aliases following that pattern:
772777
773778|===
774779| Namespace | Idiomatic Alias
780+ | clojure.datafy
781+ | datafy
775782| clojure.edn
776783| edn
777784| clojure.java.io
778785| io
779- | clojure.java.shell
780- | sh
781786| clojure.math
782787| math
783- | clojure.pprint
784- | pp
785788| clojure.set
786789| set
787- | clojure.spec.alpha
788- | spec
789- | clojure.string
790- | str
791790| clojure.walk
792791| walk
793792| clojure.zip
794793| zip
795794| clojure.core.async
796- | as
797- | clojure.core.matrix
798- | mat
795+ | async
799796| clojure.data.csv
800797| csv
801798| clojure.data.xml
802799| xml
800+ | clojure.tools.cli
801+ | cli
802+ |===
803+
804+ Then there are some core and Contrib namespaces that have shorter idiomatic aliases:
805+
806+ |===
807+ | Namespace | Idiomatic Alias
808+ | clojure.java.shell
809+ | sh
810+ | clojure.pprint
811+ | pp
812+ | clojure.spec.alpha
813+ | s
814+ | clojure.string
815+ | str
816+ | clojure.core.matrix
817+ | mat
803818| clojure.tools.logging
804819| log
820+ | clojure.core.reducers
821+ | r
822+ |===
823+
824+ And amongst commonly used community libraries, there are also many that have
825+ widely-used, idiomatic aliases for several namespaces:
826+
827+ |===
828+ | Namespace | Idiomatic Alias
805829| cheshire.core
806830| json
807831| clj-yaml.core
@@ -812,6 +836,8 @@ Some common, idiomatic aliases are shown below:
812836| sql
813837| java-time
814838| time
839+ | next.jdbc
840+ | jdbc
815841|===
816842
817843=== A Recipe for Good Namespace Aliases
@@ -822,7 +848,7 @@ You might have noticed that those are a bit inconsistent:
822848* `clojure.string` becomes `str`
823849* `clojure.pprint` becomes `pp`
824850* `clojure.walk` becomes `walk`
825- * `clojure.spec.alpha` becomes `spec `
851+ * `clojure.spec.alpha` becomes `s `
826852
827853It's clear that the one thing they have in common is that they aim to be concise, but still carry some meaning (aliasing `clojure.walk` to `w` would
828854be concise, but won't carry much meaning).
@@ -837,7 +863,7 @@ otherwise the people working on a shared Clojure codebase are going to experienc
837863(ns com.example.application
838864 (:require
839865 [clojure.java.io :as io]
840- [clojure.string :as string ]))
866+ [clojure.reflect :as reflect ]))
841867----
842868
8438692. Keep enough trailing parts to make each alias unique.
@@ -854,7 +880,6 @@ TIP: Yes, namespace aliases can have dots in them. Make good use of them.
854880
855881[source,clojure]
856882----
857- [clj-http :as http]
858883[clj-time.core :as time]
859884[clj-time.format :as time.format]
860885----
0 commit comments