dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.24k stars 5.89k forks source link

F# style guidelines: no advice given for reverse pipeline operator #21459

Open knocte opened 3 years ago

knocte commented 3 years ago

Issue description

Advice is given about how to use forward pipeline operators |> (chaining them by putting an EOL character next to them on the left side), e.g.

someElement
|> someFunc
|> otherFunc

However, what to do with reverse pipeline operators? Splitting them in the same way looks odd, e.g.:

failwith <| sprintf "foo: %s - bar: %s" foo bar

failwith
<| sprintf "foobar: %s - foobarbaz: %s" foobar foobarbaz

So I recommend that an example is given which looks like the following:

failwith <| sprintf "foo: %s - bar: %s" foo bar

failwith <| sprintf "foobar: %s - foobarbaz: %s"
                    foobar
                    foobarbaz

Document details added by adegeo


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

nojaf commented 3 years ago

I would like to point out that the recommendation has a 'vanity' indentation problem I believe. foobar and foorbarbaz are indented with 20 spaces in the example and I think that is determined by the length of the word failwith.

If it were failwithSuperLongBananas, the indentation would increase because of the function name.

failwithSuperLongBananas <| sprintf "foobar: %s - foobarbaz: %s"
                                foobar
                                foobarbaz

where

failwithSuperLongBananas 
<| sprintf "foobar: %s - foobarbaz: %s" foobar foobarbaz

does not have this problem.

@cmeeren, @pragmatrix, @lydell this is the place do discuss these things ;)

lydell commented 3 years ago

For reference, the Fantomas issue mentioning vanity indentation: https://github.com/fsprojects/fantomas/issues/659

cmeeren commented 3 years ago

@nojaf What do you mean by

this is the place do discuss these things ;)

Are you saying that the Fantomas repo is not the place to discuss the issue @lydell linked to above, and that unless this is rectified in the official style guidelines, vanity indentation won't be changed in Fantomas?

If so, remember, the guidelines are just that, guidelines :)

(Mandatory Captain Barbossa meme)

In any case, I think the linked issue pretty much sums up why vanity indentation might not be a good idea.

cartermp commented 3 years ago
failwithSuperLongBananas 
<| sprintf "foobar: %s - foobarbaz: %s" foobar foobarbaz

Makes me giggle but I suppose it's the least friction. Happy to accept a PR!

nojaf commented 3 years ago

@cmeeren, style needs to discussed over here and what gets in this style guide gets in Fantomas. Sorry for the burden Phillip ;)