7 ms·
> it would therefore be really nice to have a constructor syntax that does this implicitly. Agreed. I'm on the Dart team at work, and in Dart you'd do: cl
by munificent 12y ago
> it would therefore be really nice to have a constructor syntax that does this implicitly.
Agreed. I'm on the Dart team at work, and in Dart you'd do:
class Customer {
int customerNumber;
String name;
String address;
Customer(this.customerNumber, this.name, this.address);
}
You do still have to declare them. I've thought about adding something similar to Wren. Since fields are already syntactically distinguished, it could be as simple as:
class Customer {
new(_customerNumber, _name, _address) {}
}
I've hesitated because I want to see how much this is really needed in real-world code. I'm trying to keep things as simple as possible at least as first.
> There's another bit of Scala sugar that is nice here - an automatic copy method which takes keyword arguments to override particular fields.
I'm not opposed to the idea, but it probably doesn't carry its weight. Wren is incredibly minimal. I like immutability a lot, but for scripting language where program size is relatively small anyway, I don't think it's quite as high a priority.