4 ms·
That's an interesting counter point, though another comment in a different post for this same article[1] pointed out that Dart is considering adding pattern mat
by bern4444 6y ago
That's an interesting counter point, though another comment in a different post for this same article[1] pointed out that Dart is considering adding pattern matching too.
Though I have trouble understanding how a nominal type system affects this? Does dart not have generics? That's all you need to support these patterns? I'm having trouble understanding how the type of type system plays a role here.
Also, what's 'imperative destructing'? Haven't heard that term before, is that just pulling out a property from an object like this from JS?
const { foo } = objectWithPropertyFoo;
[1]https://news.ycombinator.com/item?id=25334283 https://news.ycombinator.com/item?id=25334283
- rokob 6y agoYes 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 {...}
- codebje 6y agoYou may prefer for foo in maybeFoo { ... } This (AIUI) isn't valid Dart code though, but this would be: maybeFoo.forEach((foo) { ... })