Hi Larry,
I admit that this flag is not too interesting, but I believe it still has
its own merit. I can imagine that the flag could play well with property
accessors as well, however,
in my opinion, the main use-case of final properties generally doesn't
involve setters/set accessors.
> In that case, "final" or "lazy" or "locked" would be reasonable names;
read-only and immutable are misleading, as it's really write-once, not
read-only, not truly immutable.
In the meanwhile, I realized that
- "immutable" is simply not true in case of resource and (non-immutable)
object properties
- "readonly" is probably somewhat better, but still not always true in case
of lazy initialization
- "final" seems ok, but it would probably be a better fit for a feature
that would prevent a property to be overwritten (similarly to "final" for
methods)
So I think "final" should only be chosen if we don't want to restrict
property overwriting later. Otherwise, we could use also "locked" or
"sealed" (inspiring from C#).
> As for references and untyped final properties... Just don't go there.
Require a final property to be non-reference and typed.
So it's essentially what Marco also suggested... Unfortunately, I didn't
exactly get the idea first (I focused too much on the mixed type), but
restricting final to typed properties now
seems reasonable. :) But let me collect the possibilities that I've thought
about so far:
- do not implicitly initialize untyped final properties: although I liked
this idea first, now it feels a bit unintuitive
- add support for mixed, and implicitly convert untyped final properties to
this type: unintuitive
- require final properties to be explicitly initialized before object
instantiation finishes: complicated, makes lazy initalization/proxying
difficult/impossible
- require final properties to be typed: looks straightforward
> I do not foresee untyped properties ever going away
Although I tend to declare types everywhere I can, I also believe we should
leave gradual typing intact.
Thank you very much for the feedback!
Máté Kocsis
Larry Garfield <larry@garfieldtech.com> ezt írta (időpont: 2020. febr. 15.,
Szo, 9:18):