4 ms·
> Nobody needs or wants the mess of Java-style initialization Ceylon tries to replicate. Initialization in Ceylon is nothing like initialization in Java: - Fo
by gavinking 11y ago
> Nobody needs or wants the mess of Java-style initialization Ceylon tries to replicate.
Initialization in Ceylon is nothing like initialization in Java:
- For the simple (common) case where there is exactly one initialization path, Ceylon is far less verbose.
- In Ceylon, the compiler guarantees that ever field not marked variable is assigned exactly once.
> Yet another static thing in class declarations?
Not really, just a constructor with no parameters.
Constructors are not "static". Constructors access the members of the class.
> Constructors in Scala are intended to directly initialize fields.
But it seems to me that they can't. Isn't it correct that only the primary constructor can initialize vals?
> Constructors in Scala are intended to directly initialize fields. They shouldn't be called directly, and are often private.
AFAICT it is not a limitation of the Scala language that constructors shouldn't be called directly. If it's indeed a practice that constructors aren't called directly, then it's interesting to enquire why that might be. And indeed an answer presents itself: because they don't have names.
> Factory methods provide everything else, and are declared in objects, instead of being static like in Ceylon.
Wait: a factory method declared on a "companion object" is not like static?! Really?
And it seems to me that people probably hide constructors behind factory methods precisely because constructors in Scala don't have names. I mean AFAICT, the syntax for calling a factory method of a companion object in scala is exactly the same as the syntax for calling a constructor in Ceylon! You just have to go through a whole lot more ceremony in Scala.
> Scala did away with 90% of the mess associated with constructors
And, AFAICT, also lost like 75% of their capabilities. Unless my evaluation above is wrong, and I'm missing something. But so far no-one has spoken up to correct me.
> therefore have a nice day! :-)
You too!
- justthistime_ 11y agoConstructors are not "static". Constructors access the members of the class. That doesn't mean that they are not "static". Yes, they sit in a weird middle-ground, but fact is that constructors are called on the class/type, and not on the instance. Color foo = ...; new foo; // doesn't make any sense. If it's indeed a practice that constructors aren't called directly, then it's interesting to enquire why that might be. And indeed an answer presents itself: because they don't have names. No, because it is good design to have one entry-point to create an instance, not 5. It is hard enough with reflection, sun.misc.Unsafe and serialization as-is. Wait: a factory method declared on a "companion object" is not like static?! Really? In Scala you have one place for "static" things. In Ceylon, static is all over the place: - Static members inside objects - Static methods inside classes (with new x() {...}) - Static fields inside classes (with new x {... } I mean AFAICT, the syntax for calling a factory method of a companion object in scala is exactly the same as the syntax for calling a constructor in Ceylon! Yes. Ceylon wasted the "good" syntax on the wrong construct. Most of the patterns leveraged in factory methods are just not available in Ceylon, because the best syntax was directly married to the class. And, AFAICT, also lost like 75% of their capabilities. Which has not been a issue in the last 10 years of Scala. Everything Ceylon has built into "constructors" are just standard methods with no magic required in Scala. Unless my evaluation above is wrong, and I'm missing something. But so far no-one has spoken up to correct me. Yes, you are focusing on the power of constructors. Yes, constructors are not extremely powerful – because they don't need to be in Scala. You are missing that Scala provides that power without turning constructors into such a mess.
- gavinking 11y ago> fact is that constructors are called on the class/type, and not on the instance. But this is the case in Scala too. So I really don't understand the distinction you're trying to make. > No, because it is good design to have one entry-point to create an instance, not 5. I don't understand how having a factory method on a Scala companion object that calls an overloaded constructor of a Scala class is not a separate "entry-point". I count each of those factory-method-constructor bundles as one entry-point. And even if these factory methods all call the same constructor, they still seem like separate "entry-point"s. And apart from your assertion that a single "entry-point" is good design, I don't quite see any particular reason to believe it. You've offered no arguments for this assertion. > In Scala you have one place for "static" things. In Ceylon, static is all over the place: Scala has members of objects and constructors of classes. Ceylon has members of objects and constructors of classes. Where is the difference? OK, so in Ceylon I can have a constructor which does not declare any parameters. How does that amount to being "all over the place" compared to Scala. > Yes. Ceylon wasted the "good" syntax on the wrong construct. Most of the patterns leveraged in factory methods are just not available in Ceylon, because the best syntax was directly married to the class. Well you see this is where Scala starts to look really bad. The problem is that Scala has no plain functions. Scala forces you to write methods of objects. In Ceylon we have toplevel functions, so we just don't need to go around sticking functions on the side of classes like you do in Scala. > Everything Ceylon has built into "constructors" are just standard methods with no magic required in Scala. This is simply false. You can't emulate constructors with plain methods in a language which enforces immutability / single-assignment. If you could, we would have done it that way. > Yes, constructors are not extremely powerful – because they don't need to be in Scala. Well, I never claimed that Scala needed constructors. Indeed I never mentioned Scala until people started trying to say—incorrectly to the point of absurdity, as it turns out—that Ceylon had copied its system of constructors from Scala. Indeed you were one of those people. You entered this discussion with the following attack on me: > A language designer which doesn't want to give credit where credit is due I'm still waiting for you to retract that, now that I've conclusively demonstrated that Ceylon's constructors are totally different to—and more powerful than—Scala's.
- justthistime_ 11y ago