Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax some of the indentation rules #470

Open
cloudRoutine opened this issue Oct 12, 2016 · 0 comments
Open

Relax some of the indentation rules #470

cloudRoutine opened this issue Oct 12, 2016 · 0 comments

Comments

@cloudRoutine
Copy link
Owner

Idea 9156844: Relax some of the indentation rules

Status : open
Submitted by Tomas Petricek on 8/3/2015 12:00:00 AM
54 votes

Currently, the general rules for indentation in F# is that the code on the next line should be indented further than the thing that determines its starting point on the previous line.
There are a number of cases where this quite annoyingly means that you have to indent things very far (or, to avoid that, add lots of unnecessary line breaks). One example is when you have nesting in a method call. For example:
Chart.Geo(growth)
|> Chart.WithOptions(Options(colorAxis=ColorAxis(values=[| -100;0;100;200;1000 |], colors=[| "#77D53D";"#D1C855";"#E8A958";"#EA4C41";"#930700" |])))
Now, there is almost no way to make this code snippet look decent. I would want to write something like this:
Chart.Geo(growth)
|> Chart.WithOptions(Options(colorAxis=ColorAxis(values=[| -100;0;100;200;1000 |],
colors=[| "#77D53D";"#D1C855";"#E8A958";"#EA4C41";"#930700" |])))
But this is not allowed, because "colors" should start after the opening parenthesis of ColorAxis, so I would need 50 spaces! To make the number of spaces smaller, you can add additional newline (to get the "ColorAxis" more to the left), but this looks pretty bad:
Chart.Geo(growth)
|> Chart.WithOptions
(Options
(colorAxis =
ColorAxis
(values=[| -100;0;100;200;1000 |],
colors=[| "#77D53D";"#D1C855";"#E8A958";"#EA4C41";"#930700" |])))
Another example is very similar, but with list expressions. I want to write:
let pop2010 = series [ for c in wb.Countries ->
c.Name => c.Indicators.CO2 emissions (kt).[2010]]
This actually works, but it gives warning. Again, it wants me to indent the second line so that it is after "for", but then I'm not saving pretty much anything by the newline. Or, I can introduce lots of additional newlines and write:
let pop2010 =
series
[ for c in wb.Countries ->
c.Name => c.Indicators.CO2 emissions (kt).[2010]]
I think that in situations like these, the rules should be relaxed. In particular, we should not require new line to be intended further than the "starting thing" on the previous line. Just further than the previous line.

Archived Uservoice Comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant