Hi Larry,

niedz., 17 lis 2024 o 08:24 Larry Garfield <la...@garfieldtech.com>
napisał(a):

> ...
> I can see the benefit of an inline constructor.  Kotlin has something
> similar.  But I can see the benefit of it for all classes, even service
> classes, not just records.  (In Kotlin, it's used for service classes all
> the time.)
>

What visibility would you expect for inline constructor properties in
service classes?
For records it is clearly a public fields declaration, while for service
classes I'd expect private|protected - adding visibility increases the
boilerplate back to normal classes.


> The alternate creation syntax... OK, this one I can't really see a benefit
> to, and Ilija already noted it may cause conflicts.
>

I agree, personally I'd see "new" keyword used like for normal classes
still feasible.


> I would far prefer assembling record-ish behavior myself, using the
> smaller parts above.  Eg:
>
> final readonly data class Point(int $x, int $y);
>
> "final" prevents extension.  "readonly" makes it immutable.  "data" gives
> it value-passing semantics.  Any class can use an inline constructor.
> "with" is designed to work automatically on all objects.  Boom, I've just
> assembled a Record out of its constituent parts, which also makes it easier
> for others to learn what I'm doing, because the features opted-in to are
> explicit, not implicit.
>

It opens a bunch of concerns, questions like why would you use "data"
keyword without having "final"?
Although I like the "data" keyword very much.

Kind regards,
--
Michał Marcin Brzuchalski

Reply via email to