|
|
|
|
|
by brabel
994 days ago
|
|
> We recently added pattern matching to Dart [1] I've been using that and I love it, in general... but can I ask you why do we need to name a variable in a pattern like this: switch (p) {
Person(name: var name) => ...
}
That's the only thing that feels a bit annoying as you have to rename the variable...
In Java, this would be something like: Person(var name) -> ...
EDIT: I guess it's to support `Person(name: 'literal')` matches.> Dart doesn't have symbols That's weird, as I actually use sometimes `#sym` (which has type `Symbol`)?? print((#sym).runtimeType);
This prints `Symbol` :)I know you know Dart in and out, but could you explain why this is not actually a symbol in the way Ruby symbols are? |
|
Swift's pattern syntax works pretty much the same way.
> > Dart doesn't have symbols
> That's weird, as I actually use sometimes `#sym` (which has type `Symbol`)??
Oh, right. I always forget about those. Yes, technically we have symbols, but they are virtually unused and are a mostly pointless wart on the language. It's not idiomatic to use them like it is in Ruby.