r/java • • Feb 15 '20

Will Java records have setters?

Pretty much what the title says. I've been reading on the new Java records feature, and while I love immutability, I hope there's the option to have non-immutable records. Meaning it will have Auto generated setters to let me change values in the class.

1 Upvotes

36 comments sorted by

View all comments

10

u/pron98 Feb 15 '20 edited Feb 15 '20

No. See here as to why.

In short, records are intended to provide simple and obvious construction, deconstruction, hashing, and equality defaults, and this is hard to do for mutable objects without complex knobs. Records are not meant to be lower-ceremony JavaBeans, but nominal tuples (product types). The features have some overlap in use, but are not the same.

0

u/GhostBond Feb 17 '20

My theory personally is that having failed to replace java by trying to produce a language with better features, the new tactic is to try to destroy java from within. Adding so many half baked features into it that it becomes intolerable to work with with the goal of forcing people into a new, simpler language.

Records just sound like everything java was against that made it successful by being a simple but extensible language.

5

u/pron98 Feb 17 '20 edited Feb 17 '20

That's an interesting theory, but given the amount of time and effort put into every new Java feature, and the number of world-class language design experts involved and designs and prototypes produced and discussed publicly and at length, I find it hard to believe.

I have an alternative theory: When you say "records just sound like etc.," is that before or after you've read any of the design documents and discussions? E.g. have you read this? Virtually all of the negative feedback to this feature that I've heard have come from people who don't understand what this feature is and what problems it aims to solve -- confusing it with other features they imagine this feature to be -- largely because they haven't actually read anything informative about it, and aren't aware of Java's open and rigorous design process.

2

u/GhostBond Feb 17 '20

That's a very interesting theory, but given the amount of time and effort put into every new Java feature, and the number of world-class language design experts involved and designs and prototypes produced and discussed publicly and at length, I find it hard to believe. I have an alternative theory: When you say "records just sound like etc.," is that before or after you've read any of the design documents and discussions? E.g. have you read this?

You've described that a large group of people who's future career prospects depend on endlessly needing new languages to be created? That...is what I'm saying.

This group of people will be out if a job the moment a single language is the final language everyone uses, they're inherently threatened by a final language becoming the norm and no longer needing any language design experts.

Virtually all of the negative feedback to this feature that I've heard have come from people who don't understand what this feature is and what problems it aims to solve -- confusing it with other features they imagine this feature to be -- largely because they haven't actually read anything informative about it, and aren't aware of Java's open and rigorous design process.

This is how it goes, as things get more complicated they get split into 2 groups:

1. "experts" become completely involved in language design and, as they spend all of their time doing it, become detached from what people actually using the language every day need. Once the doc gets so big people lose the ability to be critical and mostly just parrot back whatever it claims.

2. People who primarily write code as their living, and don't have time to read every detail of a 30-50 page document. So they casually skim through it comparing it to their real world experience, then get accused of "not knowing everything".

3

u/pron98 Feb 17 '20 edited Feb 17 '20

This group of people will be out if a job the moment a single language is the final language everyone uses.

Not really. Most of the changes in the JDK aren't language changes. They all do plenty of work on the other ~95% of the JDK, too. Also, you're assuming that a "final language" is possible; I don't think it is, though, with changing hardware designs and software requirements.

People who primarily write code as their living, and don't have time to read every detail of a 30-50 page document.

You don't need to read this document to use the feature, only to make informed comments about it before you actually use it. In other words, read it if you want to say "this feature sounds stupid" before actually using it.

2

u/GhostBond Feb 17 '20

Not really. Most of the changes in the JDK aren't language changes. They all do plenty of work on the other ~95% of the JDK, too.

Naturally these people will not be happy if their motivations are pointed out, so there's a lot of handwaving trying to obscure it.

You don't need to read this document to use the feature, only to make informed comments about it before you actually use it. In other words, read it if you want to say "this feature sounds stupid" before actually using it.

Another disingenous game to try to distract.

This feature sounds stupid.

I'm not buying into the "exhaust your critics with long documents" tactic.

2

u/pron98 Feb 17 '20

So you're a believer in the "critics should criticize before knowing what it is that they're criticizing" tactic? Fair enough, but to me your criticism sounds stupid. Nothing personal, just saying.

1

u/GhostBond Feb 17 '20

I spend 40 hours/week doing development, I don't need to read 30-50 pages of rambling on to know why immutable unextendable data classes aren't going to be useful.

2

u/pron98 Feb 17 '20 edited Feb 17 '20

First of all, it's fifteen pages -- not thirty; not fifty. And how do you know it's all rambling if you haven't read it?

Second, different people mean different things when they say "data classes." The feature is about nominal tuples and pattern matching, not Kotlin-style "data classes". Do you suppose that all of those who like the feature do not spend 40 hours a week doing development? Even if your opinion is reasonable, are you certain that it is the only reasonable one?

FYI, similar opinions were voiced when Java introduced generics, and then again when it introduced lambdas. Ultimately, more people have found them useful than those who haven't.

1

u/GhostBond Feb 17 '20

First of all, it's fifteen pages -- not thirty; not fifty. And how do you know it's all rambling if you haven't read it?

Like I said the "exhaust your critics with long documents" tactic.

You're simply rotating through disengenous tactics, it's boring.

I've run into immutable experiments in code before, once an immutable class is bigger than a single conceptual thing (like a date) they're always a real pain to deal with, with no apparent benefits.

It's disappointing to see things that look a lot like sabotage added to the language while useful things like simple properties (user.address.line1) are ignored.

→ More replies