@@ -768,40 +768,66 @@ 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.protocols
821+ | p
822+ | clojure.core.reducers
823+ | r
824+ |===
825+
826+ And amongst commonly used community libraries, there are also many that have
827+ widely-used, idiomatic aliases for several namespaces:
828+
829+ |===
830+ | Namespace | Idiomatic Alias
805831| cheshire.core
806832| json
807833| clj-yaml.core
@@ -812,6 +838,8 @@ Some common, idiomatic aliases are shown below:
812838| sql
813839| java-time
814840| time
841+ | next.jdbc
842+ | jdbc
815843|===
816844
817845=== A Recipe for Good Namespace Aliases
@@ -822,7 +850,7 @@ You might have noticed that those are a bit inconsistent:
822850* `clojure.string` becomes `str`
823851* `clojure.pprint` becomes `pp`
824852* `clojure.walk` becomes `walk`
825- * `clojure.spec.alpha` becomes `spec `
853+ * `clojure.spec.alpha` becomes `s `
826854
827855It'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
828856be concise, but won't carry much meaning).
@@ -837,7 +865,7 @@ otherwise the people working on a shared Clojure codebase are going to experienc
837865(ns com.example.application
838866 (:require
839867 [clojure.java.io :as io]
840- [clojure.string :as string ]))
868+ [clojure.reflect :as reflect ]))
841869----
842870
8438712. Keep enough trailing parts to make each alias unique.
@@ -854,7 +882,6 @@ TIP: Yes, namespace aliases can have dots in them. Make good use of them.
854882
855883[source,clojure]
856884----
857- [clj-http :as http]
858885[clj-time.core :as time]
859886[clj-time.format :as time.format]
860887----
0 commit comments