Anders Holmgren
2015-08-23 00:21:10 UTC
I use the Option class (from the option pub package) a lot.
On the one hand I like that it makes optionality explicit (as long as I enforce that all my properties are not null - i.e. either Optional<Foo> or Foo).
On the other it is quite verbose.
class A {
final Optional<B> b;
}
main() {
a.b.map((b) => b.foo);
if (a.b is None) {...}
}
etc
I really like the NNBD proposal and new null operators in 1.12. It makes handling of optionality much more terse and clean.
However, it is still treating null as a value rather than as a type (as it is in Option).
I can't help feeling it would be cool to have NNBD as sugar over Option and removing null entirely.
e.g.
String? foo; => sugar for Option<String> foo;
foo ?? 'a default'; => sugar for foo.getOrDefault('a default');
a?.foo => sugar for foo.map((f) => ...)
etc
Anyway, not an actual proposal, but I'm curious on peoples thoughts on this
On the one hand I like that it makes optionality explicit (as long as I enforce that all my properties are not null - i.e. either Optional<Foo> or Foo).
On the other it is quite verbose.
class A {
final Optional<B> b;
}
main() {
a.b.map((b) => b.foo);
if (a.b is None) {...}
}
etc
I really like the NNBD proposal and new null operators in 1.12. It makes handling of optionality much more terse and clean.
However, it is still treating null as a value rather than as a type (as it is in Option).
I can't help feeling it would be cool to have NNBD as sugar over Option and removing null entirely.
e.g.
String? foo; => sugar for Option<String> foo;
foo ?? 'a default'; => sugar for foo.getOrDefault('a default');
a?.foo => sugar for foo.map((f) => ...)
etc
Anyway, not an actual proposal, but I'm curious on peoples thoughts on this
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.