3 ms·
(One such corner is that — — a and --a are both valid but mean different things.) I'm not familiar with Dart but I believe the same applies to all the C-derive
by userbinator 7y ago
(One such corner is that — — a and --a are both valid but mean different things.)
I'm not familiar with Dart but I believe the same applies to all the C-derived syntax languages; predecrement vs subtraction of negation. If I remember correctly, the C standard even has "a+++++b" as an example (which is a syntax error, since it parses as "a++ ++ +b", but "a++ + ++b" would not be.)
As a "completely uninformed outside" opinion, how about not adding another operator, but automatically choosing based on whether the type on the left is nullable? I feel like there's already a lot of "implicit nullness" going around with this sort of language design, such that these operators are redundancy overhead --- and according to the article, the declaration of the type already tells you whether it's nullable.
- munificent 7y ago> I'm not familiar with Dart but I believe the same applies to all the C-derived syntax languages Yes, you're correct. It's not a unique property of Dart, but it's an example of a case where the whitespace in your source code is important, even if you just use it as an input to the automated formatter. > how about not adding another operator, but automatically choosing based on whether the type on the left is nullable? We could do that, but that just kicks the problem down the road. It means the type of the surrounding expression would itself become nullable (because a null-safe subscript operator can always evaluate to null). So the user still has to handle it at some point. It's better to make them handle it at the first place that null can appear so that they know where it's sneaking into their code.