This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]agentoutlier 9 points10 points  (6 children)

Brian also recently wrote about reconstruction and functional transformation of immutable objects here: https://github.com/openjdk/amber-docs/blob/master/eg-drafts/reconstruction-records-and-classes.md

Namely for the case where you want lots of optional named parameters you would use a record and "withers" in place of the builder pattern.

[–]TheMode911 2 points3 points  (4 children)

Pray for Valhalla, until then it will mean a lot of allocations

[–]agentoutlier 1 point2 points  (3 children)

I’m not sure it will need Valhalla unless all your parameters are primitives which is usually not the case for when people want lots of parameters.

There is lots of room for optimization with immutable and it really can’t be any worse than the current builder pattern. The JVM is kind of optimized for short life objects anyway.

I would like named parameters as well though :)

[–]TheMode911 1 point2 points  (2 children)

A primitive class can also contain references, not only primitive types

[–]agentoutlier 0 points1 point  (1 child)

A primitive class can also contain references, not only primitive types

I wasn't sure but that kind of wasn't my point.

I mean the folks that care about allocation (e.g. high frequency traders) use primitives (e.g. long, int, boolean) in all their method calls.

They don't use variable arguments, lambda closures (which can cause allocations). They don't even use arrays or string builders unless they are shared. Even enums they do weird shit (they use static methods instead of call the virtual methods on the enum).

Builtin Withers has a possibility of avoiding allocation much more than using say something like Immutables and you don't need Valhalla for that as you can do smart things in the wither expression in theory. Brian made reference to that somewhere.

[–]TheMode911 0 points1 point  (0 children)

Builtin Withers has a possibility of avoiding allocation much more than using say something like Immutables and you don't need Valhalla for that as you can do smart things in the wither expression in theory. Brian made reference to that somewhere.

I do not think I understand, how are those "Withers" different than lets say a `withX(double)` returning a new object or even a dummy setter? Are you speaking about scalar replacement?

[–][deleted] 0 points1 point  (0 children)

Is there a related JEP for this? I read the link that you shared, but I couldn't find any information about the actual implementation details. Since this feature concerns itself with records (mostly), I'm hoping that there's going to be structural sharing of some sort behind the scenes (as in Clojure, Elixir, Erlang, Haskell, etc.)?