gbracha / nullAwareOperators

Proposal for null-aware operators in Dart
Apache License 2.0
12 stars 2 forks source link

Single operator (a??b) covers all cases, and more #5

Closed tatumizer closed 9 years ago

tatumizer commented 9 years ago

I think instead of several ad-hoc cases (which don't cover all wishes anyway), we can use just a single one: (a??b) Make ?? low precedence operator. My claim is that all proposed constructs can be expressed much cleaner via (a??b) E.g. (x??y).foo=1; (x??y)[42]=5 (x??y)=42 // for this, you can allow it to be lvalue, but syntactically it's the same) z=(x??y)+42;

Note that we can use ?? like this even according to current proposal anyway. Which, together with other methods, leads to the same thing being expressible in different ways. (In another thread, Gilad said he wants to avoid such thing)

gbracha commented 9 years ago

Actually, ?? does not cover all the cases. If I want a?.b to be null if a is null, what value of x do you use in (a??x).b to get that result. Besides, this is all sugar - if it isn't concise, there's no point.

tatumizer commented 9 years ago

Sorry, my bad, I close the issue

tatumizer commented 9 years ago

Speaking purely theoretically (a??b) is enough in dart (not in other languages!) - we discussed in half-jokingly in the mailing list last year. class Antinull { noSuchMethod() => null; } var A=new Antinull(); Now (x??A).foo is null if x is null :-)