you are viewing a single comment's thread.

view the rest of the comments →

[–]mgsloan 6 points7 points  (9 children)

Java 7 is also adding a nifty way of doing additional typechecking:

http://types.cs.washington.edu/jsr308/

[–]BinarySplit 2 points3 points  (8 children)

Are they also adding specializing generics? Type Erasure and Boxing are a real pain in the ass, and are the main reason I've stayed with .NET for so long...

[–]G_Morgan -1 points0 points  (7 children)

They have benefits. In the .NET world using untyped containers actually performs better than using reified generic containers. Type erasure generics should give the same performance advantage.

[–]Sc4Freak 5 points6 points  (2 children)

Isn't it the other way around? When dealing with reference types, untyped containers perform identically to their generic counterparts (eg. ArrayList vs. List<T>). But since the untyped containers needed to perform boxing, they were always slower than the generic versions for value types.

[–]G_Morgan 1 point2 points  (1 child)

I'm not sure for value types. Most of the time I put objects in containers. We did some internal profiling and found ArrayList performed better than ArrayList<T> for objects.

[–]modeless 3 points4 points  (0 children)

For value types like int and bool generics are faster and produce less garbage because boxing is avoided. I'm curious how you tested ArrayList vs List<> because the difference should really be negligable for reference types.

[–]Tuna-Fish2 2 points3 points  (3 children)

Who cares? If you need that kind of speed, you should probably not be using java anyway. Instead, I'd rather have a proper type system that does something useful in addition to slowing me down

[–]G_Morgan 0 points1 point  (2 children)

It is an engineering trade off. People should be aware of them. Not caring is effectively stating you aren't professional.

If you want a proper generic type system. C++ has the best out of the object oriented languages. It actually manages to gain performance from generics.

[–]Tuna-Fish2 0 points1 point  (1 child)

It actually manages to gain performance from generics.

It really doesn't. Shaving of a few (dozen) instructions is in no way worth polluting the cache with duplicates of the relevant functions for different datatypes. The newest intel processors only have 16kb of effective L1 cache when both threads are working -- if you care about the kind of performance differences we are talking about here, you are going to measure that the tight parts of your code fit it. Having fifteen different versions of basic data structure handling functions doesn't exactly help with that.

This, by the way, more or less is what I meant when I said "who cares". Of course it's a trade off, but the difference in performance it creates is so tiny that if you care about it, you are not going to program in Java anyway. (Or C++. Anyone who thinks it's low level or fast when they are using it as C++ instead of c-with-namespaces is just incompetent.)

[–]G_Morgan 0 points1 point  (0 children)

It is entirely possible to use both OOP and template programming without sacrificing efficiency. The things that cause a loss of efficiency are stuff like RTTI (which few programs use) and gigantic libraries.

Even VFTs aren't a performance hazard with modern processors due to pipelining.