Skip to content

Flag-style arguments for Boolean parameters #362

Open
@bandleader

Description

@bandleader

Looking to hear what people think of this feature and if it would help them. Many of my methods have optional Boolean parameters to set certain flags. Consider reading the following code:

Foo(, True, , , True)

But what do those Trues mean? You would have to look up Foo and check the signature. Turns out there are 5 optional Boolean parameters, and we are setting the 2nd and 5th to True.

We can already improve the legibility using named arguments:

Foo(ShowPreview := True, CrunchNumbers := True)

But it's verbose. I propose to simplify this into 'flag syntax:'

Foo(ShowPreview, CrunchNumbers)

(If there is a local symbol in scope called ShowPreview, that should be used first, to preserve backward compatibility. I think this a better solution than enforcing a hanging suffix after the flag name, i.e. ShowPreview :=.)

(I did not think of a good syntax for unsetting a flag that otherwise defaults to True, so the existing. FlagName := False would have to be used. !FlagName comes to mind, but it's not BASIC-like.)

Comments welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions