-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Remove the ?check operator #9097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Added Area-Language, Triaged labels. |
Issue #9098 has been merged into this issue. |
This comment was originally written by [email protected] Agreed, this brings back dark memories of null and undefined in JavaScript, we should only support 1 notion of emptiness or non-existence and force API developers to develop their APIs around this and not distinguish between null and "not called with". |
I'm strongly in favor of this. There are several people (both on the Dart team and off) whose current best practice is "do not use ?". I've been tempted on multiple occasions to even put that in the style guide, but haven't. With the "?" operator, Dart has both null and undefined, and all of the complexity that that entails. At the same time, it does not make undefined first-class, which brings in all of the limitations of having a second-class piece of state in the system. In return for this complexity, we get the ability to distinguish "explicitly passed null" from "did not pass an optional argument". I haven't seen evidence that that trade-off is worthwhile. |
I also think that the ?-operator is cruft trying to fix a very specific problem, and doing it only half-way. As Bob says: we have undefined, but it's a half-assed feature, as opposed to a first-class value, so we now need to add more cruft to make the old cruft work. |
This issue was originally filed by [email protected]
I propose to remove ?check operator (I believe it's called "argument existence test" or something like that in the spec).
Reason: in a sense, it allows optional parameters to have two observable values at the same time. If used, this affects API a lot, but there's no way for the API user to know. And there's no way to opt out. I personally believe that any function using this operator forms an ill-designed API.
Also, it breaks the way people were forwarding parameters to other functions for decades -- and there's even a proposal to add special syntax for that. Having to use special syntax just to forward parameters is highly error-prone and is likely to lead to style rules like "always use this forwarding syntax, 'cause you can't never know".
If this is deemed absolutely necessary (I've heard that maybe the DOM requires it), then I'd propose removing the possibility of optional parameters having two simultaneous values, and instead adding a possibility for optional parameters having no value. I believe this concept is much easier to grasp, and it would have to be visible on the API level (so that possible issues can be detected early).
The text was updated successfully, but these errors were encountered: