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.
[ Parent
| on HN ]
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.