Skip to content

Make All Parameters Named and Required by Default #30255

Closed
@fniemann

Description

@fniemann

The current pattern of having unnamed-positional-required and named-optional parameters is not very flexible and has a few shortcomings.

Other languages such as Python or C# allow all parameters to be named and optional. There are just rules around when they become optional or how to use them as positional or named parameters.

Here are some ideas on how this could look like:

  • All parameters are required by default
  • Parameters can be made optional by providing a default value
  • Optional parameters come last (not sure if this has to be a requirement, but seems sensible)
  • All parameters can be used as positional parameters, but have to be in the order they appear in the method declaration
  • All parameters can be used as named parameters
  • Positional parameters can also be used with their name for documentation purposes (not sure if this is possible or if named parameters have to come last, but seems like a nice feature to be able to use the name for documentation when passing in bools, numbers or string literals)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).closed-not-plannedClosed as we don't intend to take action on the reported issuetype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions