3 ms·
I think the reality is that the vast majority of programmers don't find themselves in situations where the boxing of values causes obvious performance penalties
by taeric 13y ago
I think the reality is that the vast majority of programmers don't find themselves in situations where the boxing of values causes obvious performance penalties. At least, not at the scale that shows up.
So, in general, most libraries just ignore collections of primitive types.
- bhouston 13y agoIt is hugely significant when doing 3D coding if you want to use the convenience of vector and matrix types (and you really do because doing operations on raw floats it not scalable and it is bug prone.) Background: I did a lot of 3D app dev in Java in the 1998-2001 time frame and then switched over to C#. C# was a huge improvement because it had value types. When you have 5M vectors, you really do not want each to be its own allocation.
- taeric 13y agoOh, I did not mean to imply it is not a huge factor where it matters. Probably makes a bigger difference in standard CRUD fair apps than people realize. My assertion is simply that compared to the cost of serializing to/from database/user, it is probably not the pain point of many programmers. Hence, most programmers probably don't think about it. Just ask a few developers about the ridiculous overhead of HashSet<Integer>. And then see how many places people still use it.
- acqq 13y agoBut what will happen once there are "value objects" in the language? Will the new libraries be needed? Will the existing ones get some new genericity?
- taeric 13y agoHmm.... good point. I would assume that would be a different initiative. Though, my initial thought of "value types" getting boxed doesn't really make sense. What would they even be boxed as?
- acqq 13y agoThe article writes: "Wrapping. Just as the eight primitive types have wrapper types that extend Object, value types should always have both an unboxed and a boxed representation. The unboxed representation should be used where practical; the boxed representation may be required for interoperability with APIs that require reference types. Unlike the existing primitive wrappers, the boxed representation should be automatically generated from the description of the value type." So there is some boxing planned. What does it mean for the programmers, the users of existing libraries? Ah, I believe gordaco hints to that in his comment.
- taeric 13y agoRight, but does that mean I'll have to write the boxed and unboxed representation? If not, how do you distinguish between boxed and not? edit: And yes, I see it says they will be auto generated. It is the "how to distinguish" question that is non-obvious to me.
- moomin 13y agoI think you're dealing with an selling ice cream in winter problem here. There's a significant number of programmers who need this behaviour, but you don't hear from them because they have no interest in Java, because it doesn't even have rudimentary support for their use cases.
- Pxtl 13y agoThe problem is that the reason people need value types is often for performance - once you've busted out value types for performance, you expect to be able to keep it with generics, and that's where boxing/unboxing becomes apparent. Unboxing can also produce counter-intuitive typecast behavior. If I want to cast an object-boxed int into a short Object myBoxedInt = GetInt(); short myShort = (short)(int)myIntObj; because casting directly to short is a run-time exception. I've run into this problem in C#, but my understanding is that Java shares it.
- bradleyjg 13y agoThe java boxed Integer class has you covered: Integer boxed = ...; short myShort = boxed.shortValue();