Decrease syntax noise by changing if-then-else 2-level layout to 1-level#457
Decrease syntax noise by changing if-then-else 2-level layout to 1-level#457cblp wants to merge 1 commit intotweag:masterfrom
Conversation
Motivation
----------
Before:
if condition
then do
2nd level of indentation
else do
2nd level of indentation
-- 5 lines
After:
if condition then do
1st level of indentation
else do
1st level of indentation
-- 4 lines
1. Less levels of indentation.
2. Closer to if-statement layout in other languages.
Drawbacks (not problems in my opinions)
---------------------------------------
1. In Haskell98 mode, usage in do-blocks needs NonDecreasingIndentation extension.
Usage in pure expressions works out of the box.
In Haskell2010 mode, it works out of the box.
2. Longer lines in some cases due to ` then` ending.
3. More lines in short cases:
-- 3 lines before
if condition
then x
else y
vs.
-- 4 lines after
if condition then
x
else
y
Compensated by the decrease in longer cases, see example in Motivation section.
|
Hm, CI found a bug in case -- comment
else dobut this bug is in master, is not introduced by my patch. |
|
Another subjective issue. Personally, I'd be very uncomfortable with this. I don't think we need to go out of our way to save a level of indentation. Also, I have never seen this formatting in Haskell code. Maybe in JavaScript or C++. With current layout you have a condition, then you have clearly two branches formatted quite symmetrically which makes sense to me. In general now that we released the initial version we're going to need very good reasons to change any part of formatting. Those should better be technical and non-subjective. |
|
@cblp Please make sure to first open an issue for changes like this so we could discuss before you spend time implementing something. |
|
The issue is #299. |
What is your way? |
I have no data, but I think this style is so common, that an extension was created for it, and is has been made default in Haskell2010. |
|
The technical reason is decreasing syntactical noise. |
That issue resulted in bumping indentation of
"Go out of your way" is an idiom.
Syntactical noise is hard to define precisely, so it's hardly a technical reason. I perceive your layout as more noisy, and this is just my opinion. Given two conflicting opinions on a subjective issue such as this I see no reason to change the status quo. I do not want to discourage you from contributing, but if we start accepting changes that tweak existing formatting just because of taste preferences, the style will never get fixed as there are so many opinions as there are people. It's not a very productive use of our time, too. |
No, I really hope this can help people. When I look to I see 5 syntax nodes: a fork, two branch selectors, two branch bodies. And in I see only 3 syntax nodes: a fork and two branch bodies. Well, it comes I'm the only one. |
|
I see 4 syntax nodes: a fork, one branch selector, and two branch nodes. |
|
Well, it seems to be purely subjective. |
|
The only metric applicable is the indentation depth but is it good or bad is unclear. |
|
As discussed, it is not obvious that this change is in fact an improvement. The current Ormolu policy regarding formatting is that we're going to keep the style we have right now unless there is a good objective reason to change it, so that the style doesn't change a lot between releases for people who already started using the tool. |
Port of tweag/ormolu#457 Original issue tweag/ormolu#299 Closes fourmolu#80
Port of tweag/ormolu#457 Original issue tweag/ormolu#299 Closes fourmolu#80
Port of tweag/ormolu#457 Original issue tweag/ormolu#299 Closes fourmolu#80
Port of tweag/ormolu#457 Original issue tweag/ormolu#299 Closes fourmolu#80
Port of tweag/ormolu#457 Original issue tweag/ormolu#299 Closes fourmolu#80
Port of tweag/ormolu#457 Original issue tweag/ormolu#299 Closes fourmolu#80
Port of tweag/ormolu#457 Original issue tweag/ormolu#299 Closes fourmolu#80
Port of tweag/ormolu#457 Original issue tweag/ormolu#299 Closes fourmolu#80
Port of tweag/ormolu#457 Original issue tweag/ormolu#299 Closes fourmolu#80
Port of tweag/ormolu#457 Original issue tweag/ormolu#299 Closes fourmolu#80
Port of tweag/ormolu#457 Original issue tweag/ormolu#299 Closes fourmolu#80
* Add option for if-then-else 1-level layout Port of tweag/ormolu#457 Original issue tweag/ormolu#299 Closes #80 * Add tests for indent=2,4 * fixup! Add tests for indent=2,4 * Use `locatedToken` instead of `txt` * Solve tall conditions * fixup! Solve tall conditions * fixup! fixup! Solve tall conditions * fixup! fixup! fixup! Solve tall conditions * fixup! fixup! fixup! fixup! Solve tall conditions * Style * Rename one-level-ifs -> shifted-ifs * Reformat closer to upstream Ormolu, by @brandonchinn178 * Add if-else-if chains to tests and docs * Change test file name encoding --------- Co-authored-by: wldhx <wldhx@wldhx.me>
Motivation
Before:
After:
Drawbacks (not problems in my opinion)
In Haskell98 mode, usage in do-blocks needs NonDecreasingIndentation extension.
Usage in pure expressions works out of the box.
In Haskell2010 mode, it works out of the box.
Longer lines in some cases due to
thenending.More lines in short cases:
vs.
Reformatting code formatted with ormolu 0.0.1.0. This is not a problem since 0.0.1.0 doesn't commit being stable.
Compensated by the decrease in longer cases, see example in Motivation section.