Properties

Ron Pressler ron.pressler at oracle.com
Wed Apr 24 12:44:21 UTC 2024



> On 24 Apr 2024, at 13:22, ІП-24 Олександр Ротань <rotan.olexandr at gmail.com> wrote:
> 
> I am not fully getting it. So things like foo.prop = val is antipattern while foo.setProp(val) is not? What about objects like entities, where constant data mutations are inevitable and classes are mutable by spec?
> 

The more code does the better way, the less of a problem setters become, and so the motivation for making writing them easier with properties is reduced (not to mention that making writing setters easier would only encourage their use and achieve the opposite of the effect we want). 

While some programmers like having lots of features, each addressing a specific problem — and some programming languages choose to accommodate them — we believe that most programmers prefer languages with fewer features, and so the trick is finding ways to *avoid* adding language features. The way to do that is to find a smaller number of powerful features that address multiple problems — even if not perfectly — rather than add a language feature for every problem. For example, records help make serialization safer, they help with deconstruction (through pattern matching), and at the same time they also *reduce* — even if not eliminate — the need for setters, making them a smaller problem. Not every problem merits a language feature (which complicates the language and thus creates a new problem).

— Ron



More information about the compiler-dev mailing list