Flag-style arguments for Boolean parameters
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
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 `True`s 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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.