Discussion:
[dart-misc] NNBD and Option
Anders Holmgren
2015-08-23 00:21:10 UTC
Permalink
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
--
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.
Filipe Morgado
2015-08-23 01:23:07 UTC
Permalink
IMO, union types are the way to go! They're more terse and more expressive than anything else.

Option<A> would become A|Null with the added advantage that we can express A|B|Null (A, B or Null) or just A|B.

In Ceylon, A? is sugar for A|Null and it works pretty well, IMO.
--
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.
Cristian Garcia
2015-08-23 13:13:29 UTC
Permalink
Agree with Filipe, Union types are more general, and depend on NNBD to make
sense.
Post by Filipe Morgado
IMO, union types are the way to go! They're more terse and more expressive
than anything else.
Option<A> would become A|Null with the added advantage that we can express
A|B|Null (A, B or Null) or just A|B.
In Ceylon, A? is sugar for A|Null and it works pretty well, IMO.
--
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
--
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.
David Morgan ☯
2015-08-26 14:03:52 UTC
Permalink
This is the first I've heard of Option ... I added Optional to quiver:

https://github.com/google/quiver-dart/blob/master/lib/src/core/optional.dart

Looks like I neglected to search for "Option" when looking for existing
implementations, as Option was created ~6 months before Optional. (Both in
2013). Oh well.

I too am hoping for language improvements that make Option/Optional
obsolete.
Post by Anders Holmgren
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
--
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.
Loading...