@@ -768,40 +768,66 @@ NOTE: This may appear to mask
768
768
(string/join ...)
769
769
----
770
770
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:
772
777
773
778
|===
774
779
| Namespace | Idiomatic Alias
780
+ | clojure.datafy
781
+ | datafy
775
782
| clojure.edn
776
783
| edn
777
784
| clojure.java.io
778
785
| io
779
- | clojure.java.shell
780
- | sh
781
786
| clojure.math
782
787
| math
783
- | clojure.pprint
784
- | pp
785
788
| clojure.set
786
789
| set
787
- | clojure.spec.alpha
788
- | spec
789
- | clojure.string
790
- | str
791
790
| clojure.walk
792
791
| walk
793
792
| clojure.zip
794
793
| zip
795
794
| clojure.core.async
796
- | as
797
- | clojure.core.matrix
798
- | mat
795
+ | async
799
796
| clojure.data.csv
800
797
| csv
801
798
| clojure.data.xml
802
799
| 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
803
818
| clojure.tools.logging
804
819
| 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
805
831
| cheshire.core
806
832
| json
807
833
| clj-yaml.core
@@ -812,6 +838,8 @@ Some common, idiomatic aliases are shown below:
812
838
| sql
813
839
| java-time
814
840
| time
841
+ | next.jdbc
842
+ | jdbc
815
843
|===
816
844
817
845
=== A Recipe for Good Namespace Aliases
@@ -822,7 +850,7 @@ You might have noticed that those are a bit inconsistent:
822
850
* `clojure.string` becomes `str`
823
851
* `clojure.pprint` becomes `pp`
824
852
* `clojure.walk` becomes `walk`
825
- * `clojure.spec.alpha` becomes `spec `
853
+ * `clojure.spec.alpha` becomes `s `
826
854
827
855
It'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
828
856
be concise, but won't carry much meaning).
@@ -837,7 +865,7 @@ otherwise the people working on a shared Clojure codebase are going to experienc
837
865
(ns com.example.application
838
866
(:require
839
867
[clojure.java.io :as io]
840
- [clojure.string :as string ]))
868
+ [clojure.reflect :as reflect ]))
841
869
----
842
870
843
871
2. 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.
854
882
855
883
[source,clojure]
856
884
----
857
- [clj-http :as http]
858
885
[clj-time.core :as time]
859
886
[clj-time.format :as time.format]
860
887
----
0 commit comments