News for hackers. Stuff that matters.
Re:Java's records, Lombok's data, and Kotlin's data classes by AtNightWeCode on Friday May 07, 2021 @01:17PM (#27078340)
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.
Re:Java's records, Lombok's data, and Kotlin's data classes by ramblerman on Friday May 07, 2021 @01:24PM (#27078417)
> 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.

Re:Java's records, Lombok's data, and Kotlin's data classes by AtNightWeCode on Friday May 07, 2021 @02:04PM (#27078837)
Good code don't have this issue.
Re:Java's records, Lombok's data, and Kotlin's data classes by slver on Friday May 07, 2021 @02:15PM (#27078975)
Good code doesn’t have concepts like “typically doesn’t mutate”. It’s either mutable or immutable.
Re:Java's records, Lombok's data, and Kotlin's data classes by AtNightWeCode on Friday May 07, 2021 @02:33PM (#27079214)
The standard way to do it is to mutate clones as always in Java. Typically by use of libraries that provide this. You really need very bad code to have to think about if objects are mutable.
Re:Java's records, Lombok's data, and Kotlin's data classes by slver on Friday May 07, 2021 @02:38PM (#27079273)
Apparently you don’t know most immutable structures are optimized for modified cloning in ways mutables aren’t.
Re:Java's records, Lombok's data, and Kotlin's data classes by AtNightWeCode on Friday May 07, 2021 @05:53PM (#27081283)
This is Java.
Re:Java's records, Lombok's data, and Kotlin's data classes by slver on Saturday May 08, 2021 @02:38AM (#27084539)
And?
Re:Java's records, Lombok's data, and Kotlin's data classes by marcodave on Saturday May 08, 2021 @10:22AM (#27087374)
good code shouldn't need to be debugged either ;)
Re:Java's records, Lombok's data, and Kotlin's data classes by the_af on Friday May 07, 2021 @01:30PM (#27078485)
"Typically" this means you can never be sure, which is a problem.
Re:Java's records, Lombok's data, and Kotlin's data classes by AtNightWeCode on Friday May 07, 2021 @02:06PM (#27078862)
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 by slver on Friday May 07, 2021 @02:17PM (#27078995)
It takes two seconds in a hello world demo. It takes probably more in a millions of lines project.
Re:Java's records, Lombok's data, and Kotlin's data classes by AtNightWeCode on Friday May 07, 2021 @02:49PM (#27079431)
Fields of an object should typically not change. But yes, I had to make a field of a class immutable some time ago. There was a bug and I could not read the code to figure out were the object was changed. Still, caused by bad code. Same object sent around pretty much everywhere.
Re:Java's records, Lombok's data, and Kotlin's data classes by slver on Friday May 07, 2021 @02:56PM (#27079531)
So even you, the master of great code, wrote bad code. I guess immutability is worth something then.
Re:Java's records, Lombok's data, and Kotlin's data classes by AtNightWeCode on Friday May 07, 2021 @03:09PM (#27079712)
I did not write the original solution...
Re:Java's records, Lombok's data, and Kotlin's data classes by the_af on Friday May 07, 2021 @03:44PM (#27080109)
Precisely: you did not write the original solution, which is where immutability shines. It's a code comprehension tool; it gives you guarantees about code you didn't write. That's a huge boon!
Re:Java's records, Lombok's data, and Kotlin's data classes by AtNightWeCode on Friday May 07, 2021 @04:09PM (#27080334)
There are no guarantees that it is the same object you get so it is pointless.
Re:Java's records, Lombok's data, and Kotlin's data classes by slver on Saturday May 08, 2021 @07:48AM (#27086259)
No one uses immutables to make sure they “get the same object”. What does that even mean?
Re:Java's records, Lombok's data, and Kotlin's data classes by slver on Friday May 07, 2021 @03:25PM (#27079911)
So you reckon we only need immutability if two or more people have to work on code. Ok.
Re:Java's records, Lombok's data, and Kotlin's data classes by AtNightWeCode on Friday May 07, 2021 @06:13PM (#27081440)
You are just too stupid. I hope you are not immutable.
Re:Java's records, Lombok's data, and Kotlin's data classes by razzm256 on Friday May 07, 2021 @01:26PM (#27078429)
There are many good things enabled by immutability, like safer/easier multithreading, value-like semantics for objects. It is definitely not only of academic value.
Re:Java's records, Lombok's data, and Kotlin's data classes by AtNightWeCode on Friday May 07, 2021 @03:59PM (#27080245)
Typically you use values and not objects for these kind of things so not that much gained.
Re:Java's records, Lombok's data, and Kotlin's data classes by kaba0 on Saturday May 08, 2021 @03:14AM (#27084718)
Values require copying, so depending on the problem it can be worse from a perspective point of view.
Re:Java's records, Lombok's data, and Kotlin's data classes by reom_tobit on Friday May 07, 2021 @01:39PM (#27078589)
Keyword being “may”.

Guarantees are nice. Especially if objects are going to be passed around every which way from Sunday. It allows you to better reason about what could happen, and where.

Java has taken a while to get there, but I’m glad that they have finally.

Re:Java's records, Lombok's data, and Kotlin's data classes by AtNightWeCode on Friday May 07, 2021 @02:17PM (#27078994)
Well, if you pass around objects and change their state records will not help. People who does this are already using immutable frameworks in Java to clone and change some field and then pass it along.
Re:Java's records, Lombok's data, and Kotlin's data classes by reom_tobit on Friday May 07, 2021 @05:03PM (#27080844)
Sure, things have been bolted on top of Java to allow this to happen. People have made use of them.

Java now has built in support for these things, so no longer will developers rely on third-party solutions.

This is great for the Java world, and for any languages that are being built on top of the JVM by extension.

I would politely disagree with your characterisation of it being just academic, as an engineer I find it incredibly exciting. Admittedly, my bar is pretty low for excitement these days.

Re:Java's records, Lombok's data, and Kotlin's data classes by AtNightWeCode on Friday May 07, 2021 @06:17PM (#27081467)
I have done Java for 25 years and never felt any need for records. There are so many issues...