clojure-style-guide
clojure-style-guide copied to clipboard
Multi-line namespaced maps
What is the suggested level of indentation of multi-line namespaced maps?
;; no indentation
#:my-ns
{:k :v}
;; one space
#:my-ns
{:k :v}
;; two spaces
#:my-ns
{:k :v}
Someone else should answer this. I've never seen such map in my life. :-)
Personally when using namespaced maps i avoid giving a newline after the namespace. I want put the namespace before the maps explicitly and my cider repl print it without giving newline.
experiment> (identity
#:my-ns{:k :v})
#:my-ns{:k :v}
experiment> (identity
#:my-ns {:k :v})
#:my-ns{:k :v}
But i still confused whether giving space between the namespace and maps or not.
;; no newline
#:my-ns{:k :v}
;; no newline with space
#:my-ns {:k :v}
I think it's like putting metadata notation from the guide.
;; good (from the guides)
(def ^:private a 5)
;; bad (just examples, not from the guide)
(def ^:private
a 5)
(def ^:private
a 5)
(def ^:private
a 5)
(def ^:private
a 5)
Maybe it need to be added to the guides after discussing it first of course. It will be a rule about using namespaced maps. The possibilities are
;;from Looveh
#:user
{:username "foo"
:role :bar}
#:user
{:username "foo"
:role :bar}
#:user
{:username "foo"
:role :bar}
;; without newline
#:user{:username "foo"
:role :bar}
;; without newline but with space
#:user {:username "foo"
:role :bar}
;; sometimes i use this to if the maps are small
{:user/username "foo"
:user/role :bar}
For those like myself who were previously unaware of namespaced maps, see http://dev.clojure.org/jira/browse/CLJ-1910