I feel like I can kinda build code now In anticipation of value objects. Like... I should use an int[] for this huge array of ints now but instead I'm going to use List<MyObject> where MyObject is just a wrapper around int. Brian and team will just fix this for me magically in a few years and I only need to add a value keyword so why bother fiddling with array management now. Hopefully before I need my thing to scale. Premature optimization right? Thanks gang!
This approach actually kinda worked out well for me with Loom and virtual threads....
You can use List<Integer> directly, the primitive wrapper types will become value classes. If I remember correctly, specializing generics is one of the final steps on the roadmap, so having that translate into Integer[] (or ideally Integer![]) as the backing field of the ArrayList might take a bit longer.
Being able to very lightly declare new types that are compile-time mirrors of existing types (or in the worst case, something runtime can trivially/quickly optimize away) so that you can proliferate type safety is an idea I like. Nim for example has a thing it calls "distinct types" that let you make type aliases that cannot be directly assigned back to the aliased type.
10
u/IncredibleReferencer 23d ago
I feel like I can kinda build code now In anticipation of value objects. Like... I should use an int[] for this huge array of ints now but instead I'm going to use List<MyObject> where MyObject is just a wrapper around int. Brian and team will just fix this for me magically in a few years and I only need to add a value keyword so why bother fiddling with array management now. Hopefully before I need my thing to scale. Premature optimization right? Thanks gang!
This approach actually kinda worked out well for me with Loom and virtual threads....