3 ms·
Right, exactly. So there's two very distinct cases here: - the simple and overwhelmingly common case where there is only one way to instantiate a class, and th
by gavinking 11y ago
Right, exactly. So there's two very distinct cases here:
- the simple and overwhelmingly common case where there is only one way to instantiate a class, and therefore there is no reason to decouple the body of the class from the parameter list, and
- the occasional but also important case where there are multiple ways to instantiate the class, each with different parameter list signatures, where we need to decouple the body of the class from the parameter list signatures.
"Constructors" as supported in Java, C++, C#, and now also in Ceylon, are optimized for the "occasional" case. And I'm convinced that they're useful enough that we need them. But in the "overwhelmingly common" case they get in the way, and that's why they're not the usual thing you reach for first when writing a class in Ceylon.
- mborch 11y agoDart uses the following sugar for a "simple" constructor: Color(this.rgba); That is, it directly assigns the argument to the slot (which must be defined at class-level.) Of course, it's still repeating the class name but that's solvable.