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

Clarify constructors #21362

Closed
nojaf opened this issue Nov 6, 2020 · 6 comments · Fixed by #21578
Closed

Clarify constructors #21362

nojaf opened this issue Nov 6, 2020 · 6 comments · Fixed by #21578

Comments

@nojaf
Copy link
Contributor

nojaf commented Nov 6, 2020

Hello @cartermp,

I'm wondering what the style guide says about constructors and long ones in particular.

For example:

let thing = new Foobar(a, b)

let otherThing =
    new Foobar(
        longname1,
        longname2
    )

let m = new Meh(a)

let otherThing =
    new Foobar(
        longname1,
        longname2,
        longname3,
        longname4,
        longname5,
        longname6,
        longname7
    )

When to use multiple lines? Where to align in the indentation?

Fantomas today would format this as:

let thing = new Foobar(a, b)

let otherThing =
    new Foobar(longname1, longname2)

let m = new Meh(a)

let otherThing =
    new Foobar(longname1,
               longname2,
               longname3,
               longname4,
               longname5,
               longname6,
               longname7)

I'm asking this question in order to see if the Microsoft style guide will deviate from what the G-Research guide has in mind.


Document Details

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

@cartermp
Copy link
Contributor

Hmm, I suppose this one feels the best to me:

let otherThing =
    new Foobar(
        longname1,
        longname2,
        longname3,
        longname4,
        longname5,
        longname6,
        longname7
    )

Happy to adjust it to be more along those lines. I've found that I'll do similar formatting in the F# codebase for some or our longer calls.

@cartermp
Copy link
Contributor

Same goes for method calls / static members. Thoughts?

@cartermp cartermp removed the ⌚ Not Triaged Not triaged label Nov 11, 2020
@nojaf
Copy link
Contributor Author

nojaf commented Nov 14, 2020

Do you mean things like

let myValue =
    Regex.Match(
        "my longer input string with some interesting content in it",
        "myRegexPattern"
    )

let untypedRes = 
    checker.ParseFile(
        fileName, 
        sourceText,
        parsingOptionsWithDefines
    )

That could work.

@cartermp
Copy link
Contributor

Yep!

@nojaf
Copy link
Contributor Author

nojaf commented Nov 15, 2020

Great, this feels very consistent with the second sample of https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting#formatting-discriminated-unions.

Would you accept a PR here?

@cartermp
Copy link
Contributor

Yep!

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

Successfully merging a pull request may close this issue.

5 participants