ormolu icon indicating copy to clipboard operation
ormolu copied to clipboard

Whitespace in tuple sections

Open fisx opened this issue 4 years ago • 9 comments

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 avatar May 20 '20 11:05 fisx

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.

fisx avatar May 22 '20 09:05 fisx

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

neongreen avatar Jun 15 '20 10:06 neongreen

(, ,) looks rather weird to me.

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

(3,,,,,)

mrkkrp avatar Jun 15 '20 12:06 mrkkrp

(, ,) looks rather weird to me.

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

(3,,,,,)

easy! :-)

(3, , , , ,)

fisx avatar Jun 15 '20 14:06 fisx

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.

fisx avatar Jun 15 '20 14:06 fisx

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

mrkkrp avatar Jun 15 '20 15:06 mrkkrp

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:

mheinzel avatar Jun 15 '20 18:06 mheinzel

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 avatar Jun 15 '20 21:06 fisx

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

fisx avatar Jun 15 '20 21:06 fisx