File tree Expand file tree Collapse file tree 1 file changed +72
-0
lines changed Expand file tree Collapse file tree 1 file changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -611,6 +611,78 @@ In the `ns` form, sort your requirements and imports. This facilitates readabili
611
611
[clojure.java.shell :as sh]))
612
612
----
613
613
614
+ === Use Idiomatic Namespace Aliases
615
+
616
+ Many core Clojure namespaces have idiomatic aliases that you're
617
+ encouraged to use within your projects - e.g. the most common way to
618
+ require `clojure.string` is: `[clojure.string :as str]`.
619
+
620
+ NOTE: This may appear to mask
621
+ `clojure.core.str`, but it doesn't. It's expected that
622
+ `clojure.core/str` and `clojure.string/*` to be used in a namespace as
623
+ `str` and `str/whatever` without conflict.
624
+
625
+ [source,clojure]
626
+ ----
627
+ ;; good
628
+ (ns ... (:require [clojure.string :as str] ...)
629
+
630
+ (str/join ...)
631
+
632
+ ;; not as good - just be idiomatic and use as `str/`
633
+ (ns ... (:require [clojure.string :as string] ...)
634
+
635
+ (string/join ...)
636
+ ----
637
+
638
+ Bellow are some common idiomatic aliases:
639
+
640
+ |===
641
+ | Namespace | Idiomatic Alias
642
+ | io
643
+ | clojure.java.io
644
+ | set
645
+ | clojure.set
646
+ | str
647
+ | clojure.string
648
+ | walk
649
+ | clojure.walk
650
+ | zip
651
+ | clojure.zip
652
+ | xml
653
+ | clojure.data.xml
654
+ | as
655
+ | clojure.core.async
656
+ | mat
657
+ | clojure.core.matrix
658
+ | edn
659
+ | clojure.edn
660
+ | pp
661
+ | clojure.pprint
662
+ | spec
663
+ | clojure.spec.alpha
664
+ | csv
665
+ | clojure.data.csv
666
+ | json
667
+ | cheshire.core
668
+ | time
669
+ | java-time
670
+ | http
671
+ | clj-http.client
672
+ | log
673
+ | clojure.tools.logging
674
+ | sql
675
+ | hugsql.core
676
+ | yaml
677
+ | clj-yaml.core
678
+ | sh
679
+ | clojure.java.shell
680
+ |===
681
+
682
+ === Use Consistent Namespace Aliases
683
+
684
+ Across a project, it's good to be consistent with namespace aliases; e.g., don't require `clojure.string` as `str` in one namespace but `string` in another.
685
+
614
686
== Functions
615
687
616
688
=== Optional New Line After Function Name [[optional-new-line-after-fn-name]]
You can’t perform that action at this time.
0 commit comments