JEP 405 Record Patterns and Backwards Compatible Changes
Brian Goetz
brian.goetz at oracle.com
Mon Jun 13 23:04:13 UTC 2022
> I agree, but i think this duality is restricted to the canonical
> constructor and the (canonical) deconstructor, as we can see with "with".
No, there's a story for how overload selection will be done on ctor/dtor
pairs from `with`. Until then, records can prefer the canonical pair;
it so happens to turn out that the story will be compatible with this
selection. We'll get there in steps.
> Constructors get overloading for free from being methods even if
> usually what the user want is just default values.
> Deconstructors can not re-use the same overloading algorithm as
> methods (cf refining overloading of
> reconstruction-records-and-classes.md), so the duality breaks here.
They will have a different set of overload rules, which basically come
from "reversing the arrows" in the constructor overload restrictions /
selection. So they're different in exactly the way you'd expect a dual
to be different.
> Also i think that named pattern methods are a better mechanism than
> deconstructors overloading because a pattern methods is not
> unconditional while a deconstructor is,
Remember, this is not the list for language design discussions.
But the two are not inconsistent; just as users can choose between
constructors or factories, they can choose between deconstruction and
named patterns. Hopefully they will choose consistently; ctors+dtors,
or factories+named patterns. But again, not the place to have the "I
think it should work differently" discussion.
More information about the amber-dev
mailing list