News for hackers. Stuff that matters.
Re:Why nullable types? by rokob on Tuesday December 08, 2020 @12:41AM (#25342296)
Yes Dart has generics which is how you would implement optional types yourself. The type of type system doesn't play a role here you are right. I was thinking of the really good pattern matching I have experienced usually being present with structural subtyping.

Dart is considering adding pattern matching (and real tuples!) and I think they will eventually get there. I just think that would have had to come first to make the case of optionals over nullable types more compelling.

I would call that example destructing in the normal sense and it is basically a form of pattern matching. To do that in an imperative language without pattern matching (i.e. what I am calling imperative destructuring), you end up with code like

  if (maybeFoo.isSome) {
    final foo = maybeFoo.asValue;
    ...
  }
when you really want

  if let Some(foo) = maybeFoo {...}
Re:Why nullable types? by codebje on Tuesday December 08, 2020 @02:05AM (#25342693)
You may prefer

    for foo in maybeFoo { ... }
This (AIUI) isn't valid Dart code though, but this would be:

    maybeFoo.forEach((foo) { ... })