tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
958 stars 83 forks source link

Whitespace in tuple sections #595

Open fisx opened 4 years ago

fisx commented 4 years ago

I would like to propose to change style slightly for -XTupleSections to make things more consistent (and more to my taste :)):

x = (1, 2) -- no change
y = (4,) -- no change
z = (, 3) -- whitespace after comma; current behavior: (,3)
fisx commented 4 years ago

Also: (, ,), (a, b,), (, a, b), (a, , b) (thanks @mheinzel for thinking of the corner cases)

These arguably look a little odd, but I feel this is the best compromise between lack of surprise and readability.

neongreen commented 4 years ago

I am actually very surprised that (, ,) works at all. I assumed only (,,), (,,,), etc worked. So I want to special-case those.

mrkkrp commented 4 years ago

(, ,) looks rather weird to me.

I wanted to implement this but gave up. How do you format this for example?

(3,,,,,)
fisx commented 4 years ago

(, ,) looks rather weird to me.

I wanted to implement this but gave up. How do you format this for example?

(3,,,,,)

easy! :-)

(3, , , , ,)
fisx commented 4 years ago

I think the rule set is:

  1. if you see ,) in a tuple section, leave it as is. if there is whitespace between , and ), remove it
  2. other than that, there is exactly one space after every comma, and no (extra) space before.
mrkkrp commented 4 years ago

I don't know... (3, , , , ,) looks much less pleasing (and more space consuming) than (3,,,,,). Granted, it is just my personal opinion.

mheinzel commented 4 years ago

Yeah, I'm also not sure anymore if this is better than the current behaviour in general. I feel like on one hand it's making things worse if there are few fields set (the extreme being (, , ,)), but on the other it looks better in more complicated examples:

-- current behaviour, looks weird and is hard to parse for me
(foo,some long expression,stuff (`with` parentheses),,and <$> operators)

-- proposed, slightly better
(foo, some long expression, stuff (`with` parentheses), , and <$> operators)

The solution to that (and good advice in general) might be to not use tuple sections with complicated expressions, instead binding things to short names. But even then, it feels like a small improvement:

-- current behaviour
(foo,exp,stuff',,bar)

-- proposed, still slightly better
(foo, exp, stuff', , bar)

Not sure which side matters more to me. :shrug:

fisx commented 4 years ago

It's a matter of taste, but I like the spaces more, even in the contrived examples where I seem to be alone with that judgment. :)

This is one of the few situations where i have a very clear position: ormolu as it works today, with all its bugs and choices I disagree with, is awesome and has made my life so much better; and with the proposed change, it would make things slightly better yet.

fisx commented 4 years ago

(I'm trying to say: I won't be disappointed if this is labelled as wontfix and closed.)