Sun's crappy generic implementation

Good going Sun.
Personally I’ve heard people jabber on about this before but I’ve never confirmed it with a reliable source.

Now that I have confirmed this I will take a swipe at Sun at such a stupid implementation of generics.

What kind of hack job is this? Why couldn’t Sun delay Java 5 for a little bit longer so they can get a real implementation of generics.

C# is looking to be a better language than Java in the next release.

I use C# a lot, as do I use Java a lot. There are some things I like in Java over C# and vice versa.
In .NET 2.0 one of those things I will like more in C# over Java is generics.

http://www.artima.com/intv/generics2.html

Issue number 3: for the first time in java’s existence, bar primitives Object is not the all-encompassing root type; some Objects are more Objecty than others.

It is not possible to have arrays of generic types. Up until Java 5, apart from primitives, anything could go anywhere (and, in all critical cases, primitives could too)

What planet do the people behind this crap live on? Planet “I’m too stupid to know what an array is, so I don’t care about not using them”? Or just “java was doing too well in the markeplace - let’s screw it up, refuse to be runtime backwards compatible, and hopefully everyone will go use C# instead”?

Shrug. Since I’m still waiting for an answer to “what happened to the documentation for NIO?” I guess it’s going to be at least another 5 years before we get any explanation for the mindless stupidity that went into deciding what would go into Java 5.

[quote]Up until Java 5, apart from primitives, anything could go anywhere (and, in all critical cases, primitives could too)
[/quote]
You can still NOT use generics with Java 5.

[quote]I guess it’s going to be at least another 5 years before we get any explanation for the mindless stupidity that went into deciding what would go into Java 5.
[/quote]
I, for one, don’t blame Sun for the current implementation. I’m sure that, like now that everyone is bitching about it, a few years back when the decision was being made the same people were pushing hard for not breaking anything in the VM and keeping strict backwards compatibility.

And that’s why C# is probably going to take over everything. Because, well, it’s Microsoft’s pet and they’re not afraid to move forward. I won’t be surprised when I see C# running on a non-Microsoft console, long before Java does.

I’ll be surprised if you see C# on a non-Microsoft console. But I won’t be surprised when it appears on an Xbox.

By the way, blahblah, you probably don’t have to wait 5 years to find out. Bruce Eckels wrote a series of articles “Puzzling through Erasure” discussing some of the issues with Java generics.

I -think- this is the one where he had some feedback from someone at Sun:

http://mindview.net/WebLog/log-0060
and:

This is why I started writing an article on it. People who believe this are kidding themselves, and due for a nasty shock the first time they try to use an API that uses generics in signatures.

You don’t get a choice: if your API’s require a certain platform version, you have to upgrade to it, and use whatever new features they’re using. Up until now, that hasn’t been an issue in any case I can remember, except for a SLIGHT upset at being forced to use Collections.

However, the reasons to object to using collections are miniscule compared with the problems of generics, IMHO.

No.

Sun refused to let us have any of the critically important language features (like regexps) for no other reason than that excuse.

Now they’ve not only broken with their own stricutres that held back java for many years, but done so in spectacular style, admitting something ugly, practically useless, and damaging to the language.

What really takes the piss is that they decided to make java 5 NOT RUNTIME BACKWARDS COMPATIBLE, even though - as Toby has proved - their excuses for not doing so were pretty hollow.

What is the ****ing point of including type erasure “so that java 5 code will run on old JVM’s” (paraphrase), when the java 5 compiler is deliberately written to make it impossible to run java 5 code on old JVM’s?

[quote]What is the ****ing point of including type erasure “so that java 5 code will run on old JVM’s” (paraphrase), when the java 5 compiler is deliberately written to make it impossible to run java 5 code on old JVM’s?
[/quote]
I don’t think that’s erasure’s point. The point is that pre-5 code and post-5 code can work together on a Java 5.0 virtual machine (edit: even without re-compilation).

This of course implies that there’s no reason anyone wouldn’t want to move to a 5.0 VM (I mean runtime execution only, not compilation). And I don’t think there is one, I hope we agree on this.

[quote]Sun refused to let us have any of the critically important language features (like regexps) for no other reason than that excuse.
[/quote]


"Hello World!".matches("Hello*");
"Hello World!".replaceFirst("Hello", "Goodbye");
"a,csv,\"file\"".split(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");

I don’t know about you, but I was quite happy with the RegEX support. shrug :slight_smile:

[quote]Now they’ve not only broken with their own stricutres that held back java for many years, but done so in spectacular style, admitting something ugly, practically useless, and damaging to the language.
[/quote]
Perhaps that because the only way those features could be added was in an ugly and practically useless way? I was one of the many who lobbied against Generics, Autoboxing, and several other features that various OO dweebs “just couldn’t live without”. As if it was so hard to write some bloody damn code instead of using syntatic sugar. >:(

Java was popular because it was simple. The only thing it ever needed were libraries to cover holes and continually build up the platform. But people couldn’t leave well enough alone, and now we’ve got Java 5. Thanks guys.

[quote]What is the ****ing point of including type erasure “so that java 5 code will run on old JVM’s” (paraphrase), when the java 5 compiler is deliberately written to make it impossible to run java 5 code on old JVM’s?
[/quote]
As I understand it, it was originally Sun’s intention to make the code fully backward compatible. However, they were told by the community at large that backward compatibility is not a big deal, so just get it in there. Sun listened, and now we’re where we’re at.

[quote]What is the ****ing point of including type erasure “so that java 5 code will run on old JVM’s” (paraphrase), when the java 5 compiler is deliberately written to make it impossible to run java 5 code on old JVM’s?
[/quote]
I’ve been wondering about that too - for a veeery loong time!

[quote]As I understand it, it was originally Sun’s intention to make the code fully backward compatible. However, they were told by the community at large that backward compatibility is not a big deal, so just get it in there. Sun listened, and now we’re where we’re at.
[/quote]
Right, but why the hell didn’t they fix the generic bugs then??? and speed up the implementation.

[quote]Right, but why the hell didn’t they fix the generic bugs then??? and speed up the implementation.
[/quote]
I haven’t had a chance to use Generics, so I can’t really comment on the bugs. What I can comment on is that things were plenty fast enough without generics. Prior to generics, the HotSpot VM would take note of collections that only had one type of Object in them. As long as there was only one type of object, hotspot optimized away the cast. Once you added in some other type, the optimization was undone. My guess is that the addition of Generics destabilized that feature.

Everyone should really keep in mind that the JVM is a tremendously complex piece of software, and that Sun has limited resources. It’s doubtful that any of us could do better without something nearing Sun’s resources. Nonsense demands like generics and auto-boxing are not helping anything, but Sun is making the effort none the less.

So it would be nice if people would stop being so critical. Either deal with what exists, join a project like Blackdown to help improve the code, or tone down their complaints to helpful suggestions.

Perhaps it wasn’t obvious, even with the original context: I was referring to the many years where Sun refused to allow regexps into the language. I was using them for years via 3rd party libs that there was seemingly no good reason not to have in the language - no syntax changes required, no mangling involved, a pretty standard expected feature of any programming language, and commonly used all over the place in programming.

Then they go and put in trash that mangles the syntax, makes a mess of the language itself (c.f. arrays), has practically no use at all, has no basis for its existence in tried and tested langauges elsewhere, and is deeply unpopular.

We’re not talking about a minor change of direction here, but a full-on turn-around-and-spit-in-your-face revolution.

You’re being incredibly biased towards Sun here, conveniently ignoring the one major factor that is the cause of so much ire: Sun owns Java, and we are forced to suffer if they do not take their ownership seriously, or exercise it in stupid ways.

Don’t give me the “take it or leave it” talk; I’ve had enough of that to last me a lifetime from open-source developers using it as a justification for making their software crap (fx: whiny voice: “No-one’s going to shoot you if don’t use it. You don’t HAVE to use it. I don’t care about you. Go away”). Responsibility is not something you get to take or leave at your leisure: once gained, it’s there whether you like it or not. Sun has a huge responsibility towards java, and java 5 gives the worrying impression that, deep down, they couldn’t give a rats’s arse - they will do whatever the hell they feel like, despite the obvious and inherent wrongness of it.

I know Sun is legendary for ignoring both it’s customers and the market (c.f. the Solarisx86 fiasco. Yes, I’m still waiting (4 years and counting) for my copy of Solarisx86), but I really thought that things were different with java. I believe they were, but it looks like the last vestiges of those with some sense and care in managing java have vested their options and retired / moved on to more lucrative jobs elsewhere. It’s the classic pattern of paradigm-shifting software: the inventors get rich, and sooner or later hand over to a bunch of *-nuts who don’t quite knwo what to do with it, and it degenerates into a total mess.

For people with long enough memories, the big question now is: is it even worth the risk of using java any more, given the near certainty that this is the end? The same patten happens again and again, and each time you hang on in there saying to yourself “maybe this time a company will pull out” you simply set yourself up to be thoroughly buggered in a few years time, when you’re locked-in to a platofmr that has no escape path and is self destructing.

I’ve joined the crowd who are investigating the cost and side-effects of retraining into C# - even though it’s something I never expected to do (why would I want that? - I used to say - it’s got nothing significantly improved enough over java to justify switching).

[quote]Perhaps it wasn’t obvious, even with the original context: I was referring to the many years where Sun refused to allow regexps into the language. I was using them for years via 3rd party libs that there was seemingly no good reason not to have in the language - no syntax changes required, no mangling involved, a pretty standard expected feature of any programming language, and commonly used all over the place in programming.
[/quote]
Quite a few people were doing the same. I actually was forced to use a piss poor excuse for a RegEx library (coughBlue Martinicough) around that time, but it worked. I can’t say Sun was really ignoring people as much as didn’t get around to adding it. Their release of Java 2 made a mess of Java, and they had to focus heavily on 1.3 to clean it up. The result was that regexs ended up getting slated for 1.4.

[quote]Then they go and put in trash that mangles the syntax, makes a mess of the language itself (c.f. arrays), has practically no use at all, has no basis for its existence in tried and tested langauges elsewhere, and is deeply unpopular.
[/quote]
??? What’s wrong with the current RegEx libs? You have the choice of using the String methods I demonstrated, or you can use the java.util.regex package. AFAIK, the regex lib follows the “spec” as close as possible. Most of the things it doesn’t implement are very PERL specific code constructs.

Just don’t use generics. They’re a move toward bad programming anyway :slight_smile:

Kev

Misunderstanding :).

In the last para, I was referring to generics :).

I rather like java.util.regex.*. I suspect I have found one bug once in it, which is good going considering how much I’ve used the package, and even that one bug I couldn’t be absolutely sure of (it was in a long string with 40+ special chars in, so just trying to calculate the state engine required lots of pen and paper work) and didn’t bother trying to narrow down,since it was probably just user error anyway.

I especially like the documentation for Pattern. Although it could certainly be significantly better (that would make it “excellent”) - several conditions are left undefined, I think because the author ran out of energy and/or wasn’t aggresive enough in their use of regex and didn’t realise some of the questions that come up often (um, stuff like… how to OR groups of chars as opposed to individual chars isn’t explained ever, IIRC). But at least 90% of cases are covered in more than sufficient detail.

[quote]What kind of hack job is this? Why couldn’t Sun delay Java 5 for a little bit longer so they can get a real implementation of generics.
[/quote]
No amount of delay could provide the implementation you would prefer. What that would require is a change in the requirements set out when JSR-14 was first created. So where were you then?
Did you respond to the public review of JSR-14?
Do you know about the attempts to extend generics to work fully with arrays (and why that didn’t appear in the final version)?

So if you didn’t respond to JSR-14 you’re not allowed to complain ?
What if I started with Java 3 months ago ?

Just because there is an option to comment on some proceedings, doesn’t mean that they should do a piss poor job, and rely on people to tell them when they’re doing something foolish.

Whoops. I forgot about that.

It still doesn’t change the fact that if Java continues it’s current path it will be replaced by languages like C#.

Aye, as soon as I’ve finished Quix I’m going to take a while and check out the alternatives. Currently on my list are: D, Nice, Blitz and C#.

[quote]So if you didn’t respond to JSR-14 you’re not allowed to complain ?
What if I started with Java 3 months ago ?

Just because there is an option to comment on some proceedings, doesn’t mean that they should do a piss poor job, and rely on people to tell them when they’re doing something foolish.
[/quote]
That’s not what happened. No one did a piss poor job. It was done this way because the Java community specifically asked for it. If we are to blame Sun for generics, we should be blaming all these too:

http://www.jcp.org/en/jsr/detail?id=014

Have a look at the two ballots and who voted what.

[quote]or tone down their complaints to helpful suggestions
[/quote]
Yes, that’s what we should be doing. I like the feature as it is now (blah^3: generics are not completely practically useless), but we know it could be improved in the future (dump erasure? does anyone know if that’s a viable possibility?).