fslang-design icon indicating copy to clipboard operation
fslang-design copied to clipboard

[style-guide] do! indents

Open palsskv opened this issue 11 months ago • 2 comments

I suggest to remove the line-break after do! for multi-line expressions when using 4-space indents. do! is 4 characters long and fits into the current alignment scheme.

Some sample code using the current style guide:

do!
    writeRelated<TType1, TType3>
        httpClient
        host

do!
    writeRelated<TType1, TType2>
        httpClient
        host

if someRelatedDataVals.Length > 0 then
    do!
        writeRelated<TType1, TType2>
            httpClient
            host
            someRelatedDataVals

Suggested fix:

do! writeRelated<TType1, TType3>
        httpClient
        host

do! writeRelated<TType1, TType2>
        httpClient
        host

if someRelatedDataVals.Length > 0 then
    do! writeRelated<TType1, TType2>
            httpClient
            host
            someRelatedDataVals

Single-line expressions should not be affected, as there is no forced line break. I.e. do! writeRelated<TType1, TType3> httpClient host is already fine.

I originally filed this under .NET docs: https://github.com/dotnet/docs/issues/39302

palsskv avatar Jan 23 '25 16:01 palsskv

One problem I can already see is that this doesn't work when the indentation would be 2 spaces.

do! writeRelated<TType1, TType3>
    httpClient
    host

This is no longer an application but a sequence of expressions.

I also question how well this would behave with different types of expressions. (again with indent_size = 2)

// This is already invalid code
do! try
  foo()
  with ex ->
    bar()

nojaf avatar Jan 27 '25 08:01 nojaf

@nojaf The original suggestion was for the case of 4-spaces only. Obviously this is not a good idea for two-space code.

For your try block, in 4-space code it looks reasonable to me:

do! try
        foo()
    with ex ->
        bar()

JustinWick avatar Mar 16 '25 15:03 JustinWick