Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrow or wide formatting? #161

Open
nickcernis opened this issue Nov 18, 2017 · 2 comments
Open

Narrow or wide formatting? #161

nickcernis opened this issue Nov 18, 2017 · 2 comments

Comments

@nickcernis
Copy link

Should Clojurists favour narrow formatting with top-level forms on new lines, like this:

(def asym-hobbit-body-parts
  [{:name "head" :size 3}
   {:name "left-eye" :size 1}
   {:name "left-ear" :size 1}
   {:name "mouth" :size 1}
   {:name "nose" :size 1}
   {:name "neck" :size 2}
   {:name "left-shoulder" :size 3}
   {:name "left-upper-arm" :size 3}
   {:name "chest" :size 10}
   {:name "back" :size 10}
   {:name "left-forearm" :size 3}
   {:name "abdomen" :size 6}
   {:name "left-kidney" :size 1}
   {:name "left-hand" :size 2}
   {:name "left-knee" :size 2}
   {:name "left-thigh" :size 4}
   {:name "left-lower-leg" :size 3}
   {:name "left-achilles" :size 1}
   {:name "left-foot" :size 2}])

Or wider formatting that avoids splitting forms with line breaks unless they extend beyond 80 characters, like this?

(def asym-hobbit-body-parts [{:name "head" :size 3}
                             {:name "left-eye" :size 1}
                             {:name "left-ear" :size 1}
                             {:name "mouth" :size 1}
                             {:name "nose" :size 1}
                             {:name "neck" :size 2}
                             {:name "left-shoulder" :size 3}
                             {:name "left-upper-arm" :size 3}
                             {:name "chest" :size 10}
                             {:name "back" :size 10}
                             {:name "left-forearm" :size 3}
                             {:name "abdomen" :size 6}
                             {:name "left-kidney" :size 1}
                             {:name "left-hand" :size 2}
                             {:name "left-knee" :size 2}
                             {:name "left-thigh" :size 4}
                             {:name "left-lower-leg" :size 3}
                             {:name "left-achilles" :size 1}
                             {:name "left-foot" :size 2}])

I find the first version easier to scan but don't see any general advice in the guide about this.

@vemv
Copy link

vemv commented Nov 23, 2017

Funny, I just raised this issue independently:

#162

Mine is concerned with fn calls though. I'd say for calls, the generally better choice is quite clear. For data/defs (such as your example) there's more room for subjectivity.

In your example, I'd prefer the former as:

  • it frees up more horizontal space to be used (one may use e.g. 80 characters max)
  • it's data. I'd say it's great to have different styles for code and data. Once one follows this consistently, visual scanning of codebases becomes a pleasure

@bbatsov
Copy link
Owner

bbatsov commented Aug 27, 2018

I think I've seen way more usages of the first style in the wild. Someone has to check this, though. Generally I don't have any issues with recommending this in the guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants