Earlier quoted context omitted.
In the works: https://github.com/openjdk/amber-docs/blob/master/eg-drafts/...
I hope they will find a better solution, as this proposal will break encapsulation. Let’s say you model allowed transitions via business methods and thus restrict certain state changes. You can either serialize or deserialize state or perform an allowed transition. If wither becomes a language feature, it will allow forbidden state changes that cannot be caught by validation in constructor, which will allow deseriali…
Making Lenses Practical in Java
51–60 of 108 posts
Re: Making Lenses Practical in Java
#52Earlier quoted context omitted.
But they require a new JDK version, and a surprisingly high amount of Java projects are still stuck on JDK8.
JDK 8 is now a minority, and if we count only projects that are still undergoing significant development it's a significantly smaller minority. The main reason some projects are still stuck on 8 is because they use old libraries that have made breaking changes, and don't have resources to adapt their use, let alone take on new ones.
Re: Making Lenses Practical in Java
#53Earlier quoted context omitted.
> (e.g., "given a DOM node, traverse all of its children") you can use a library of transformations ... and write queries and transformations over arbitrary structures in a very compact way. But in Java you'd do that with reflection. So the question remains, how many such different queries/transformations you actually have (in the source code, where type checking is available, rather than user input) to make the effo…
Maybe you would rather do that with reflection, but I'd rather do something that isn't fundamentally the same tools that create security vulnerabilities. Every time you can not-use reflection is a win.
Re: Making Lenses Practical in Java
#54Earlier quoted context omitted.
I hope they will find a better solution, as this proposal will break encapsulation. Let’s say you model allowed transitions via business methods and thus restrict certain state changes. You can either serialize or deserialize state or perform an allowed transition. If wither becomes a language feature, it will allow forbidden state changes that cannot be caught by validation in constructor, which will allow deseriali…
The proposal is meant for records, and records are used for "plain old data", explicitly without any encapsulation.
Re: Making Lenses Practical in Java
#55Earlier quoted context omitted.
Or they develop for Android. Not a minority.
Are most android devs still working with Java or Kotlin?
Re: Making Lenses Practical in Java
#56I don't agree on the fact that lombok has brought us out of the dark ages. We used to use it, but it has some drawbacks. One of them, it's an additional dependency. This, for a simple thing such as pojo, seems a bit overkill to me. The additional amount of time used to write some cose isn't worth the risk of additional bugs hidden in having one more dependency.
Re: Making Lenses Practical in Java
#57Earlier quoted context omitted.
JDK 8 is now a minority, and if we count only projects that are still undergoing significant development it's a significantly smaller minority. The main reason some projects are still stuck on 8 is because they use old libraries that have made breaking changes, and don't have resources to adapt their use, let alone take on new ones.
Or they develop for Android. Not a minority.
Re: Making Lenses Practical in Java
#58Earlier quoted context omitted.
The proposal is meant for records, and records are used for "plain old data", explicitly without any encapsulation.
Nope. If records were structures, they would not be allowed to have methods or overloaded constructors or even default constructor. The most obvious example of encapsulation in records is validation of state.
Withers will likely go through the same default constructor so constraints can be upheld, though.
Re: Making Lenses Practical in Java
#59Earlier quoted context omitted.
Nope. If records were structures, they would not be allowed to have methods or overloaded constructors or even default constructor. The most obvious example of encapsulation in records is validation of state.
They still don’t have encapsulation, all members are readable on purpose. Withers will likely go through the same default constructor so constraints can be upheld, though.
Public state does not mean no encapsulation. The purpose of encapsulation is to bundle state and behavior and hide them both behind an interface, but that interface can offer read access to state. The key here is behavior.
>constraints can be upheld
My example above demonstrates a constraint that cannot be implemented in a constructor.
Re: Making Lenses Practical in Java
#60I just use Kotlin. Never looked back.
Kotlin alone won't implement these features for you. You'd end up with something like this: val order = loadOrder() val approved = order.copy( approval = order.approval.copy( confirmation = order.approval.confirmation.copy(updatedOn = Instant.now()), status = ApprovalStatus.Approved ) I think I prefer this explicit deep cloning over the automagically generated lenses in standard code, but I can see the appeal. The pr…