Skip to content

Formatting of long parameter lists #657

Closed
@cmeeren

Description

@cmeeren

Online here

Input:

type RequestParser<'ctx, 'a> = internal {
  consumedFields: Set<ConsumedFieldName>
  parse: 'ctx -> Request ->  Async<Result<'a, Error list>>
  prohibited: ProhibitedRequestGetter list
} with

  static member internal Create(consumedFields, parse: 'ctx -> Request -> Async<Result<'a, Error list>>) : RequestParser<'ctx, 'a> =
    {
      consumedFields = consumedFields
      parse = parse
      prohibited = []
    }

Output:

type RequestParser<'ctx, 'a> =
  internal { consumedFields: Set<ConsumedFieldName>
             parse: 'ctx -> Request -> Async<Result<'a, Error list>>
             prohibited: ProhibitedRequestGetter list }

  static member internal Create(consumedFields,
                                parse: 'ctx -> Request -> Async<Result<'a, Error list>>): RequestParser<'ctx, 'a> =
    { consumedFields = consumedFields
      parse = parse
      prohibited = [] }

I strongly dislike code that is indented far to the right to "match up", for the following reasons

  • Important code moved far to the right
  • There is little space left for the actual code
  • There is an unseemly gap

I usually format it like this:

  static member internal Create
      ( consumedFields
      ,  parse: 'ctx -> Request -> Async<Result<'a, Error list>>)
      : RequestParser<'ctx, 'a> =
    {
      consumedFields = consumedFields
      parse = parse
      prohibited = []
    }
  • Every parameter on its own line
  • Commas after each parameter (could also be placed first as suggested in Long C#-like arguments list  #232 - looks weird to me, but could probably get used to it if necessary)
  • The last line has the colon and return type

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions