Live data from Hacker News

Java's records, Lombok's data, and Kotlin's data classes

nipafx.dev

111–120 of 294 posts

Re: Java's records, Lombok's data, and Kotlin's data classes

#111

Scala's case classes are missing in the comparison (only mentioned briefly at the very end). They offer everything that records do and more. Good to see that Java finally catches up a bit.

Scala is usually omitted for one reason or another when Kotlin is compared against Java as a better alternative, which is a shame.

Lombok and Kotlin are both much easier to integrate into existing Java applications and libraries than Scala.

Re: Java's records, Lombok's data, and Kotlin's data classes

#112
post #87
post #51

Earlier quoted context omitted.

1 million is not a lot. I'd begin by asking myselves "can I afford to chase those pointers?", because maybe you can.

That's a good question to ask when faced with a problem that could be solved that way, but a real answer to the question would be useful too.

[deleted]

Re: Java's records, Lombok's data, and Kotlin's data classes

#113

I'm not sure what it's taking about for the "with" feature: https://nipafx.dev/java-record-semantics/#with-blocks In Kotlin data classes, it's already implemented (just called copy) https://kotlinlang.org/docs/data-classes.html#copying

It was included because changing data using records (copying it except changing the fields you need to change) is a shitty experience, so rather than showing the code you have to write, they showed you code you may or may not in the future be able to write.

Seems like an odd thing to mention. They are arguing that records are better than data classes, but part of their argument is "maybe, in the future, at some point, I don't know, it will be as easy to do this thing with records as it already is with data classes, we'll only need to add new syntax and a new keyword to the language".

Re: Java's records, Lombok's data, and Kotlin's data classes

#114

Not sure why immutable data structures have surfaced as something important. Typically you never change fields so it is kind of only of academic value if a field in a POD, POJO, POCO or whatever it is called in the specific language actually may change.

> so it is kind of only of academic value if a field in a POD, POJO, POCO or whatever it is called in the specific language actually may change. I'm not sure if you've debugged much, or inherited any large legacy projects, but knowing it is immutable vs "typically it isn't" is a pretty big distinction in that moment.

Good code don't have this issue.

Re: Java's records, Lombok's data, and Kotlin's data classes

#115

This might qualify as low-grade threadjacking, so I apologize if this is off topic, but who's actually using Java these days? Most devs I know avoid it like the plague, and only use it to maintain legacy codebases or get CS qualifications. Are there any real advantages to using Java in 2021, besides it's mature community/ecosystem/tooling?

Java has the nice advantage that it works.

Re: Java's records, Lombok's data, and Kotlin's data classes

#116
post #84

Not sure why immutable data structures have surfaced as something important. Typically you never change fields so it is kind of only of academic value if a field in a POD, POJO, POCO or whatever it is called in the specific language actually may change.

"Typically" this means you can never be sure, which is a problem.

Sure of what? If your code is not garbage it takes two seconds to see where things change. It should be very places in the code.

Re: Java's records, Lombok's data, and Kotlin's data classes

#117
post #59

Earlier quoted context omitted.

Instead of changing few bytes, now I have to copy hundreds of bytes around and add more stuff for GC to collect. Well, they have to obey Wirth's law, I guess.

Or you know, the JIT will trivially optimize away the old class if it is reassigned to the same variable, as you would use it inside a loop. How do you think the litany of FP languages work? Like Haskell, Scala, Clojure?

It can be done in theory, but the JVM does nothing of the sort right now.

Re: Java's records, Lombok's data, and Kotlin's data classes

#118
post #51

Earlier quoted context omitted.

1 million is not a lot. I'd begin by asking myselves "can I afford to chase those pointers?", because maybe you can.

No, because my competitors who are attempting to fill the same orders I am attempting to fill are not chasing pointers.

are your competitors using java?

Re: Java's records, Lombok's data, and Kotlin's data classes

#119
post #89
post #79

Earlier quoted context omitted.

If C# didn't exist, we would certainly be a Java shop. Not only because of the ecosystem & tooling, but also because it is a language that has historically proven its ability to model incredibly complex business domains as well as support mission critical workloads without falling over on itself.

How's your experience with C#/.NET been? Does it have an analogous offering to Java's JFR[0] for always-on profiling? [0] https://blogs.oracle.com/javamagazine/java-flight-recorder-a...

Seems like EventPipe is the C# equivalent? https://docs.microsoft.com/en-us/dotnet/core/diagnostics/eve...

Re: Java's records, Lombok's data, and Kotlin's data classes

#120

Earlier quoted context omitted.

In languages without property support, reflexively writing getters and setters is the only way to make it possible to go back later and add logic to getting and setting without changing the callsites. Is this a workaround for the combined shackles of mismanaged enterprise environments where changing callsites is impossible for some reason, and legacy language environments where you have to use Java for some reason? Y…

> go back later and add logic to getting and setting Which, realistically, you're virtually never going to do - at least not often enough to justify the boilerplate and especially in the case of things like "records" which were probably auto-generated from a schema (with obligatory getters and setters) anyway. If you did , you'd end up confusing all of your callers who probably wrote client code presuming that what t…

This is true, until you're writing a library that's pulled from a repository and used in several projects.

If you can't guarantee you're not going to break someone else's code by changing:

foo.x to foo.getX();

then you should stick with properties. Now, for staying inside a single package, or a single compiled unit, then what you say is reasonable enough. I'd still prefer to write the getters and setters, though, especially in cases where it's free, like Kotlin.

Post reply on HN