Skip to content

Allow = as separator for named parameter default value. #27559

Closed
@floitschG

Description

@floitschG

We have foo([x = 42]) and foo({x: 42}) as the ways to specify default values for parameters.

That means that changing your function from a positional parameter to a named parameter is not just changing the [] to {}, you also have to change = to : - but it still means exactly the same thing (default value). This breaks the rule about similar things having similar syntax.

Even without changing from one type of parameter to another, I still regularly write = for named parameters. There is simply nothing to remind me that it's not =.

It might be cute that it 1) looks like a map or 2) looks like how the function is called, but the former is only true in trivial cases and the latter isn't helping anyway - it's not like positional parameter default values looks like arguments in a function call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions