clojure-style-guide icon indicating copy to clipboard operation
clojure-style-guide copied to clipboard

Multi-line namespaced maps

Open Looveh opened this issue 8 years ago • 3 comments

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}

Looveh avatar Dec 14 '16 14:12 Looveh

Someone else should answer this. I've never seen such map in my life. :-)

bbatsov avatar Jan 05 '17 09:01 bbatsov

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}

skadinyo avatar Jan 08 '17 09:01 skadinyo

For those like myself who were previously unaware of namespaced maps, see http://dev.clojure.org/jira/browse/CLJ-1910

kgann avatar Jan 10 '17 20:01 kgann