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

Proposal: Forbid Java-style lone parens

Open aengelberg opened this issue 9 years ago • 5 comments

As far as I know, this shouldn't be allowed:

(def my-collection [
  x
  y])

but there is not a specific rule anywhere that addresses this style.

aengelberg avatar Jun 18 '15 17:06 aengelberg

Hum... Can you clarify exactly what your issue is here?

Would this be OK? I've seen this done before to allow comments textually on fields.

(def my-collection
  [x
   y])

Is this OK?

(def my-collection
  [x y])

Or is this what you want to prohibit?

(def my-collection
  [x 
   y
  ])

arrdem avatar Jun 18 '15 17:06 arrdem

The first two are okay to me, the last one is another one I'd like to prohibit. Essentially, the style of "lone parens", either open ones with no text after them, or closed ones with no text before them. Of course, only if others express a similar concern.

aengelberg avatar Jun 18 '15 17:06 aengelberg

Hum. Agreed, the Clojure style seems to have opens on the same line as the first term, and closes on the same line as the last term. For that reason I find the first two of my examples acceptable but would be annoyed by your case and my last case. I think this is a fair style guide point, but may be something it already covers, see the paren alignment stuff.

arrdem avatar Jun 18 '15 18:06 arrdem

So actually there is a legitimate case for the "trailing delimiter" style. Consider the following edit:

Initially:

{:foo :bar}

After:

{:foo :bar
 :baz :qux}

In the proposed "same line" style, a diff of these two will show both lines modified. Were the delimiters on their own lines, instead the diff would simply reflect the insertion since it doesn't also demand syntax changes.

If we had a diff engine that was form driven rather than line driven this obviously wouldn't be a problem, however we're working with Unix tools :cry:

arrdem avatar Jun 18 '15 19:06 arrdem

I just now found the section about trailing parens, so the only thing it's missing is the part about opening parens followed by newlines. I agree with your point about the diffs, and for that reason, trailing close parens can occasionally be found in my code.

aengelberg avatar Jun 18 '15 19:06 aengelberg