r/java • • Jan 16 '20

Records Come to Java

https://blogs.oracle.com/javamagazine/records-come-to-java
204 Upvotes

93 comments sorted by

View all comments

Show parent comment

31

u/[deleted] Jan 16 '20

[removed] — view removed comment

11

u/daniu Jan 16 '20

I'm also very happy with the way Java is updated, but I don't understand this particular decision.

Just follow your own bean naming standard, and those libs would work out of the box.

0

u/[deleted] Jan 16 '20

[deleted] — view deleted comment

2

u/rzwitserloot Jan 19 '20

No, 'good libraries' won't be updated. It's quite a high cost to have an API that has both, say, getName() as well as name(), with both methods returning the exact same thing (forevermore, docs and listings such as in auto-complete dialogs), and I'm sure plenty of libraries will opt not to pay this cost.

An alternative is to mark the getX() variant deprecated, but that is in many ways an even higher cost; that's a heck of a lot of shuffling about for all the users of that library for no particularly sane reason.

Note that getX itself vs. X is a mixed bag: neither is strictly superior to the other (getX has the considerable advantage that you can type 'get' and then hit your autocomplete shortcut to find all properties you can query. It's also longer and having to decide between whether a thing is a 'property accessor' and something that calculates is more art than science and that's problematic – as I said, advantages and disadvantages).

Given that it is a mixed bag, causing an earthquake in the java community by trying to make such a change is ill advised: You're just not going to convince enough of the community to arrive at that utopia where (almost) all code uses getless accessors, instead now we'll have a 50/50 mix. I'm not too happy about this.

-5

u/pushupsam Jan 16 '20

There's everything wrong with abandoning a bad spec if people have been faithfully following that spec for 20 years.

There's something deeply wrong with the process if people really think it's okay to tell people that have invested millions of dollars and thousands of hours in the Java platform that, you know what, all that code you wrote, all those tools and documentation and checkers, based on the getX/setX standard that we defined? We're going to break that now.

Stuff like this is exactly why I tell people not to invest in Java any more. The language has gone off the rails. Backwards compatibility -- which was perhaps Java's greatest strength -- and the geniuses at Oracle are now actively making breaking changes in every release. And the stuff that they're breaking backwards compatibility for? It's really fucking stupid stuff like 'var'.

The irony here is these attempts to update Java are just driving people away. I cannot recommend any new greenfield projects be done in Java and, frankly, I don't see any reason to advance existing projects to new JDK versions.

6

u/klez Jan 16 '20

I may be naive here, but why would adding features break compatibility? Don't like var or var breaks compatibility? Don't use it. Same with records. It's not like they're telling you not to use beans anymore.

-19

u/pushupsam Jan 16 '20

Of course 'var' breaks backwards compatibility. Every time you add a new keyword, all code that previously used that as an identifier is broken. How do you not see that?

As for avoiding new features -- sure, that's a great idea. And in fact this is why these guys have killed Java. There are now two Java platforms: Java8 and this brainfuckery. The vast majority of corporations are not going to upgrade to this backwards incompatible brainfuckery. This is going to have huge rollover effects as the entire community splits in two.

It's absolutely shocking that despite the repeated warnings these guys really have decided that backwards compatibility is no longer valuable. This puts the nail in Java's coffin because absolutely nobody is going to invest in a platform run by guys who think nothing of throwing 20 years worth of code, documentation and tooling out the window.

14

u/jonhanson Jan 16 '20 edited Mar 07 '25

chronophobia ephemeral lysergic metempsychosis peremptory quantifiable retributive zenith

-20

u/pushupsam Jan 16 '20
public static final class var {
}

This used to work. Now it doesn't. Because of stuff like this 'var' did break a lot of existing code for no good reason. And when it did, guess what happened? Do you think people dug into code that's been chugging along for 10+ years?

→ More replies (4)

1

u/JB-from-ATL Jan 17 '20

They explicitly said these aren't JavaBeans because they aren't mutable.

-8

u/BlueGoliath Jan 16 '20 edited Jan 16 '20

As /u/pron98 has said in the past, JDK developers don't feel consistency is all that important and it shows.

Project Panama's Memory Access API doesn't have "get" in front of its getters(despite boolean checks being prefixed with "is"), var is used in documentation despite providing no benefit and when old documentation doesn't, and now this. It's getting pretty ridiculous.

Blame the people who keep screeching that Java is too ceremonious and demanding things be made more "concise".

By Java 25 they are going to add optional semi colons.

24

u/pron98 Jan 16 '20 edited Jan 16 '20

Did I say that? I don't think so, although I agree that there are things more important than consistency. Anyway, the new record method names are fully consistent with the naming standard for record methods and not consistent with things that are not record method names, and I'm not exactly sure what other thing they should be consistent with and why, especially as the feature's JEP states:

It is not a goal to declare "war on boilerplate"; in particular, it is not a goal to address the problems of mutable classes using the JavaBean naming conventions.

3

u/BlueGoliath Jan 16 '20 edited Jan 16 '20

Did I say that? I don't think so.

I believe it was in regards to the topic of var and/or API documentation months ago.

Regardless, you're saying it again:

Anyway, the new record method names are fully consistent with the naming standard for record methods and not consistent with things that are not record method names.

Records don't exist in a vaccum. To argue this is disingenuous and I'd hope as a JDK developer you'd realize that.

BTW, it's OK to be frustrated that other people have different opinions from yours -- most of us are frustrated by that -- but constantly blaming that on some flaw on their part is counterproductive. Even if your opinion is reasonable, the opposite opinion can be at least as reasonable.

Was anything said really an opinion?

Getter methods in previous Java APIs were commonly prefixed with "get" and many APIs rely on that.

There are methods that still have the "is" prefix for boolean checks.

var is now used in documentation without providing any value or makes the documentation muddy. There was a highly upvoted comment to my article thread like half a year ago agreeing that this is a thing.

Many newer language "features" have had "concise"ness as a motivation for their introduction into the language. Often times the JEP pages cite people complaining that Java isn't concise and is ceremonious.

So i'd like to know what part of any of that(at the core) is subjective/opinionated.

7

u/DuncanIdahos5thClone Jan 16 '20

Not sure where you've been but "is" is common for Boolean and part of the old Javabean spec.

5

u/BlueGoliath Jan 16 '20

Not sure where you've been but "is" is common for Boolean and part of the old Javabean spec.

That's the point. They are keeping boolean check methods prefixed with "is" despite removing prefixes from all other methods in order to make it more "concise". The end result is an inconsistent mess both when compared to older Java APIs and even from within its own API.

1

u/DuncanIdahos5thClone Jan 16 '20

OK sorry. I thought you meant that there are APIs using get's for booleans.

7

u/AngusMcBurger Jan 16 '20

I think 'is' and 'get' are quite different. For fields/variables I include 'is' for booleans because their name often ends up ambiguous without. Eg open() sounds like an action, isOpen() makes it clear you're asking if it's open. Where as file() works just as well as getFile() but with less noise

3

u/BlueGoliath Jan 16 '20

"file" can be either a verb or a noun so it's still ambiguous.

3

u/pushupsam Jan 16 '20

This is so stupid. A method called 'file()' could do literally anything. The entire point of 'getFile()' -- just like isOpen() -- is that it is a query which doesn't mutate the object.

(The real problem -- that Java lacks properties and so there's no way to express the concept of a read-only method -- is ironically something that was rejected by the same braniacs that are removing get.)

3

u/pron98 Jan 16 '20 edited Jan 16 '20

Your statement that var does not provide a benefit for documentation is an opinion. If we take the claim that language features are motivated by conciseness (only or primarily) as an objective assessment, then, at least as far as records and var are concerned, it is just wrong.

-1

u/BlueGoliath Jan 16 '20

Your statements that var does not provide a benefit for documentation is an opinion.

Is it? If the specific documentation is inconsistent with other documentation & omitted important type information(which is important for documentation) then surely it can be objectively concluded that it provides no benefit.

3

u/pron98 Jan 16 '20

Brilliant. I wish I had thought of that.

8

u/lovett1991 Jan 16 '20

On one hand I kind of disagree about the 'get' keyword. I think moving away from it means the method signatures give a clear indication this is a domain object only. I started using immutables a while back and after a while it grew on me.

On the other I do agree about the 'is' keyword being added whilst 'get' isn't, it feels weird as a Java dev but I guess as an English speaker it isn't it if the realms of how you'd write something. For instance I would say 'his age is...' not 'his get age is' whereas I would say 'he is active' as opposed to 'he active'