3 ms·
Why should compiler optimize obviously dumb code? If developer wants to create billions of heap objects, compiler should respect him. Optimizing dumb code is wh
by vbezhenar 7mo ago
Why should compiler optimize obviously dumb code? If developer wants to create billions of heap objects, compiler should respect him. Optimizing dumb code is what made C++ unbearable. When you write one code and compilers generates completely different code.
- carlmr 7mo agoThe problem is rather that Java doesn't have generics and structs, so you're kind of forced to box things or can't use collections.
- vbezhenar 7mo agoNo, in the example they provided, programmer wrote obviously stupid code. It has nothing to do with necessity: Long sum = 0L; for (Long value : values) { sum += value; } I also want to highlight that there are plenty of collections utilizing primitive types. They're not generic but they do the job, so if you have a bottleneck, you can solve it. That said, TBH I think that adding autoboxing to the language was an error. It makes bad code look too innocent. Without autoboxing, this code would look like a mess and probably would have been caught earlier.
- carlmr 7mo ago>They're not generic but they do the job, so if you have a bottleneck, you can solve it. But that's the thing, in other languages you don't need a workaround to work on primitives directly.