It's the data, stupid !
Remi Forax
forax at univ-mlv.fr
Mon May 30 12:33:51 UTC 2022
Hi all,
i think the recent discussions about the pattern matching are too much about details of implementation and i fear we are losing the big picture, so let me explain why i (we ?) want to add pattern matching to Java.
Java roots is OOP, encapsulation serves us well for the last 25+ years, it emphasis API above everything else, data are not important because it's just a possible implementation of the API.
But OOP / encapsulation is really important for libraries, less for applications. For an application, data are more important, or at least as important as API.
The goal of pattern matching is make data the center of the universe. Data are more important than code, if the data change because the business requirements change, the code should be updated accordingly. Pattern matching allows to write code depending on the data and it will fail to compile if the data change, indicating every places in the code where the code needs to be updated to take care of the new data shape.
The data can change in different ways,
1) a new kind of a type (a subtype of an interface) can be introduced, we have added sealed types and make switch on type exhaustive so if a developer add a new subtype of an interface, the compiler will refuse to compile all patterns that are not exhaustive anymore, indicating that the code must be updated.
2) a data can have a new field/component, we have introduced record pattern that match the exact shape of a record, so if a developer add a new component, the compiler will refuse to compile the record pattern with a wrong shape indicating that the code must be updated.
So experts, do you agree that this is what we want or did i miss something ?
Rémi
PS: the title is a nod to James Carville.
More information about the amber-spec-experts
mailing list