-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
This issue was originally filed by eiger...@gmail.com
It would behoove Dart to adopt a cleaner syntax for null checking than the existing...
if (exampleVar != null) {
exampleVar.doStuff();
}
Having PHP-like functionality would require altering the language spec on boolean values to null equating to false. This would allow the following:
if (exampleVar) {
exampleVar.doStuff();
}
Another option that would not require adjusting the boolean value language spec is adding a groovy-like null-safe operator to the syntax:
exampleVar?.doStuff();
This is handy, but it would not allow making logically different decisions based on null status - something that may or may not be necessary.
Another option would be implementing the ? operator as a null-check in the parent Object class. Then, we could do...
if (exampleVar?) {
exampleVar.doStuff();
}
There are other options, too - any of them that would reduce the syntax weight would be helpful.