3 ms·
Well I guess it's not extremely clear to me how a "record literal with open recursion" isn't essentially the same thing as a "class".
by gavinking 11y ago
Well I guess it's not extremely clear to me how a "record literal with open recursion" isn't essentially the same thing as a "class".
- jules 11y agoA record literal is an expression that creates a value. A class would then be a function, as chriswarbo suggests.
- gavinking 11y agoI understand, but once you start taking into account other requirements, like the ability to functionally decompose construction of this record, you will wind up with something that looks painfully similar to a class in Ceylon.
- jules 11y agoCan you elaborate on that? Since in this model constructors are just functions you can of course define multiple constructors that may or may not call each other.
- gavinking 11y agoWell the issue in my mind is how to functionally decompose construction of a record. You have to come up with some way to express a "partial" record, and then "augment" it with new members. I'm trying to say this without using the word "inheritance" ;-)
- jules 11y agoYes, sure, you need a construct to extend a record. All but the simplest record systems have this though.
- gavinking 11y agoRight, so at that point, as I say, there's really not much daylight between "class" and "record". The difference being that a class protects its initialization logic (favoring modularity), whereas a record opens it up (favoring flexibility). Ultimately I see them as much more similar than they are different.
- jules 11y agoThe difference is that a class combines several things into one construct (initialization, type definition, naming) that are separate with records. This is also what causes you to need such an elaborate design for constructors.
- gavinking 11y agoWhat I'm trying to say is that I don't think that the total complexity or total expressiveness is ultimately much different. You trade class types + interface types for record types + named structural types. You trade class inheritance for record extension. You gain a tiny little bit of flexibility via structural typing - but in my opinion much less than is often claimed, since in all these languages so-called structural types are only partially structural - and you lose some power at the tooling level (refactorings are no longer guaranteed to work). You gain a bit of flexibility by decoupling initialization into a function, but you also gain a bit of verbosity and lose a little bit of modularity. Ultimately it's a bit of a wash and honestly I would probably be almost as happy with OCaml or Rust or something like that as I am with Ceylon. I think both systems work well and are intellectually consistent. I don't think either is clearly superior to the other.
- jules 11y agoIt's highly dependent on coding style. If you program in a mostly ML-like style then I think that design has its advantages because only only need record of functions + open recursion + named + always constructed via some constructor in 1% of cases. In such a style you view that combination as just one combination in a whole spectrum of data types that you can express. However if you want to make a language for object oriented programming it makes sense to build that combination into the language rather than supplying each part as a separate building block that you compose in exactly the same way all the time.