@@ -768,40 +768,64 @@ 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.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
805
829
| cheshire.core
806
830
| json
807
831
| clj-yaml.core
@@ -812,6 +836,8 @@ Some common, idiomatic aliases are shown below:
812
836
| sql
813
837
| java-time
814
838
| time
839
+ | next.jdbc
840
+ | jdbc
815
841
|===
816
842
817
843
=== A Recipe for Good Namespace Aliases
@@ -822,7 +848,7 @@ You might have noticed that those are a bit inconsistent:
822
848
* `clojure.string` becomes `str`
823
849
* `clojure.pprint` becomes `pp`
824
850
* `clojure.walk` becomes `walk`
825
- * `clojure.spec.alpha` becomes `spec `
851
+ * `clojure.spec.alpha` becomes `s `
826
852
827
853
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
854
be concise, but won't carry much meaning).
@@ -837,7 +863,7 @@ otherwise the people working on a shared Clojure codebase are going to experienc
837
863
(ns com.example.application
838
864
(:require
839
865
[clojure.java.io :as io]
840
- [clojure.string :as string ]))
866
+ [clojure.reflect :as reflect ]))
841
867
----
842
868
843
869
2. 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.
854
880
855
881
[source,clojure]
856
882
----
857
- [clj-http :as http]
858
883
[clj-time.core :as time]
859
884
[clj-time.format :as time.format]
860
885
----
0 commit comments