ormolu
ormolu copied to clipboard
Whitespace in tuple sections
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)
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.
I am actually very surprised that (, ,)
works at all. I assumed only (,,)
, (,,,)
, etc worked. So I want to special-case those.
(, ,)
looks rather weird to me.
I wanted to implement this but gave up. How do you format this for example?
(3,,,,,)
(, ,)
looks rather weird to me.I wanted to implement this but gave up. How do you format this for example?
(3,,,,,)
easy! :-)
(3, , , , ,)
I think the rule set is:
- if you see
,)
in a tuple section, leave it as is. if there is whitespace between,
and)
, remove it - other than that, there is exactly one space after every comma, and no (extra) space before.
I don't know... (3, , , , ,)
looks much less pleasing (and more space consuming) than (3,,,,,)
. Granted, it is just my personal opinion.
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:
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.
(I'm trying to say: I won't be disappointed if this is labelled as wontfix and closed.)