Sun's crappy generic implementation

[quote]G5) The Principle of Least Astonishment. Don’t surprise the user
[/quote]

[quote]c) Reflection should recognize generic type definitions, and provide accurate information about formal type parameters in classes, interfaces and methods
[/quote]
obviously they strayed from their own specs ?

[quote]The system also has additional goals. Goals are different from constraints. Whereas all constraints must be met, it may not be possible to meet all the goals. Goals may be traded off against each other, or may be abandoned because they contradict constraints. No priority is implied by the ordering of the goals.
[/quote]
Too bad.

[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 ?
[/quote]
No you can complain, but you need to understand where your complaint should be directed. It should not be directed at people like Neal Gafter who have done a very good job of implementing generics subject to the constraints and goals they were given. In essence the “Java Community” has got what they asked for.

I do not believe that Sun could realistically introduced generics in the way that Microsoft has done for C#. That is the constraints in JSR-14 reflect what the “Java community” (i.e. IBM, Apple, etc as well as Sun) was willing to accept in terms of compatibility with existing code.

Yes, Microsoft does make changes that do not provide “migration compatibility”, and much cursed they are for doing so. Yet they know they will not lose too many developers as a result. This is a strength that Sun does not have (in my opinion).

EDIT: I happily accept that my view on this topic is, perhaps, reactionary, and that other people have quite different views on Generics. The only concerns I have are that many people don’t yet appreciate what a blow to the head G is, and that I can’t seem to find a way to use java 5 without exposing myself to G madness as soon as someone else decides to give in and use Gs in their supporting code for anything I work on.

…and that it’s a very very bad sign for the future of Java. If Sun takes their responsibilities this lightly…

If, for instance, Sun does a volte-face and actually removes or replaces G completely in the near future with something that is NOT runtime compatible (might be compile-time compatible) and actually provides generic types in java (which G definitely does not do), then I’ll be first in line to congratulate and cry “catastrophe averted”. Microsoft does exactly this kind of thing: recognizes the really big mistakes, and no matter the cost, attempts to turn everything around - sometimes even the entire company - just to fix them. Obviously they don’t do it all the time, or people wouldn’t complain about windows so much :), but at the moment I’m wondering whetehr Sun even has that mindset. They didn’t used to, but in recent yeasr appear to have started dabbling in this approach (once again, c.f. Solaris x86. That’s a pretty mega U-turn)

I appreciate your point, but still disagree. It is about responsibility and “group think”. NO-ONE gets to absolve themself of responsbility for their own mistakes “because everyone else in the group went for it”. This is the classic excuse used in the public sector to justify the horrendous stupidity and/or cowardice on catastrophe projects; if someone took responsbility, they would have kicked up a huge fuss, saying “this is ridiculous; we cannot possibly take this **** to market”.

Fair enough. There’s a lot of people listed that - from personal experience of their organizations - I wouldn’t trust in a million years to make decisions about the future of a programming language.

EDIT: next sentence doesn’t read as intended. What I meant was that to date the AF has nothing to be proud of. Many of their projects (maybe most - I haven’t tried them all) are going in very good directions for the future. Perhaps, one day, they will finish something, in which case it will be good. They have an awful lot of projects that “could be excellent if anyone ever finishes them”, but somewhat make fools of themselves by “constantly re-inventing from scratch” and avoiding re-using existing stuff that would save them time when they have this history of not completing.

Why the hell is anyone, for instance, saying that a vote from the Apache Foundation (makes free software historically of extremely poor quality historically re-inventing the wheel over and over again, often badly, and famous for ownership of the world’s slowest web-server) should even be listened to when deciding the future direction of something like java? I use a lot of AF projects, and none of them are complete, none of them work properly (even the simplest of those I use have had hiatuses of more than a year where no-one released anything even though they knew the things didn’t work).

Shrug. Just looks to me excatly like another pattern thats common in the IT industry: at some point, the large corporate who owns a tech gives up control to the whims of customers / vendors, and the product sinks into depravity. Look at all the designed-by-committee howlers of the 1990’s.

I’ve still not found anyone who has a cogent argument that they are anything more than a fix for a problem with Collections that made them look stupid to advanced programmers with wide experience of mainstream languages.

This was Eckel’s conclusion, eventually: that most of his frustration came from erroneously thinking it was meant to be any more than that. (although, given how fluid his opinions seem to be, he’s probably changed his mind again by now :))

If you look at what works and what doesn’t, and weigh the pros and cons and costs, I honestly can’t see how you’re going to gain benefit from then other than “seeming visually to fix Collections” and/or “reduce the number of typecasts you type in your source code”.

Please fill me in.

[quote]if someone took responsbility, they would have kicked up a huge fuss, saying “this is ridiculous; we cannot possibly take this **** to market”.
[/quote]
I would have certainly loved that, but wouldn’t that make Sun a Microsoft then? People in this forum are developing games, they could have easily moved to a non-erasure implementation, but what about all the big companies? I can’t imagine the mess it would produce.

Don’t get me wrong, I don’t like what happened, I just can say that I understand it. And I still admire the Java platform and hope that generics will be “fixed” in a future version of the Java language (when everyone will be using them), or at least wait for another language to take its place (that runs on the platform - not C#).

[quote]I honestly can’t see how you’re going to gain benefit from then other than “seeming visually to fix Collections” and/or “reduce the number of typecasts you type in your source code”.
[/quote]
Well, I happen to be a clean code freak! And from what I’m seeing every day, our code is considerably cleaner with 5.0. Generics and stuff like the Iterable interface (one of the best API additions) are making a huge difference. I also happen to dislike Collections (e.g., too many object creation all over the place), I’m using my own implementations.

The code clean-up alone is a big plus. More readability, less typing, less bugs, less time. People are saying that Java became too complex with generics, but I’m seeing the exactly opposite. OK, it’s specification may be more complex (more difficult for new people), but the Java code is simpler than it ever was.

The other important feature is, of course, reinforced compile time type checking. Especially with type constraints you can do many interesting things.

My biggest gripe is not being able to use primitive types. As for arrays, I’ve never needed that feature so far.

[quote]I can’t seem to find a way to use java 5 without exposing myself to G madness as soon as someone else decides to give in and use Gs in their supporting code for anything I work on.
[/quote]
But that’s exactly why erasure was chosen. For situations like this. You could move to generics, a library’s implementor could move to generics, both of you could move to generics, but no matter what, the result would compile and run.

Howabout doing one of the first JGF opinion pieces on it :)? You would need to go into considerable detail of what, precisely, you were seeing as differences, with before/after code snippets from real code, but as an opinion piece could have considerable leeway in being less-than-diligent. I guess as long as you don’t try and conclude anything, it would be fine - people will get the implications of whatever conclusions you have, but it should not be written as a research-towards-making-a-conclusion piece.

Unless you have the time and energy to do a diligent detailed article on it instead.

PS: I’d be interested to see how G has any effect on amount of object creation from Collections

PPS: why do you care about object creation? Isn’t it almost impossible to make it a bottleneck, unless you’re doing something very unusual.

[quote]Howabout doing one of the first JGF opinion pieces on it :)?
[/quote]
Sure, but I can’t guarantee time of delivery ;). Send me the details (just generics or for other code-cleaning 5.0 features too?, etc) and I’ll see what I can do. (spasi at zdimensions.gr)

[quote]PS: I’d be interested to see how G has any effect on amount of object creation from Collections
[/quote]
I don’t think generics affect object creation in any way.

[quote]PPS: why do you care about object creation? Isn’t it almost impossible to make it a bottleneck, unless you’re doing something very unusual.
[/quote]
Well, I’ve had some nasty experiences with garbage collection in the past and I want to be sure that I’ll not have again. I know of the better gcing in recent VMs, but I’m too used to my stuff right now ;).

Anyway, the implementations I use are “optimized” for game developing (always single-threaded), which means no synchronization and no things like creating a new iterator object each time.

[quote]Just don’t use generics. They’re a move toward bad programming anyway :slight_smile:
[/quote]
Could you please elaborate on that? If you are at least slightly serious, I am curious as to what you mean.

Sorry for my ignorance, but again I am curious - what were the attempts, and why didn’t that appear in the final version?

Thanks,
Digitprop

Well, finally we found the ultimate reason why there are just a fistful of Java games. (I knew there had to be one.)
It’s all so simple. If somethings doesn’t fit my fisheye perspective, it’s bad.
I think we’re so smart. Too smart to be smart. :wink:

For a while the prototype generics compiler implemented this: http://www.daimi.au.dk/~plesner/variance/
This extended generics to arrays (also via erasure). While technically very nice, many people had major problems understanding it.

Mark Thornton

Let’s hope they ditch type erasure in the next version then eh?

And while they’re at it they could allow generics using primitive types as well.

Cas :slight_smile:

I see a lot of whining, when the reality is - it doesn’t bloody matter. Generics does enough good, and only has a couple, well known, issues that ultimately are never going to affect my code. So I’m happy with it.

[off topic]
Blah^3 - interesting rant on Apache… I have it seems the exact opposite opinion of them. You can’t blame AF for the fact that most open source projects are never finished. There are a few Apache products that I make use of without trouble. In terms of open source projects they have one of the better collections.
[/offtopic]

[quote]I see a lot of whining, when the reality is - it doesn’t bloody matter.
[/quote]
Agreed - while it has issues, the great improvements to the usability of the Collections framework make it all worthwhile, in my opinion.

[quote]In terms of open source projects they have one of the better collections.
[/quote]
And agreed! My job, at least, would be 10,000% more difficult if the Apache Foundation weren’t churning out useful APIs on a continual basis.

[quote]I see a lot of whining, when the reality is - it doesn’t bloody matter.
[/quote]
Maybe. I’m still distressed about the increased maintenance costs of people abusing the API’s, or partners forcing us to start using them when talking to their API’s.

You can blame them for refusing to re-use any / all existing open-source projects and starting again from scratch, thereby wasting lots and ltos of time.

I’ve used (and continue to use) many ASF projects. At first, they seem great. Over time you come to realise frequently (leaving aside the flagships) that the project had X hours put into it, of which Y would have been saved if they’d not refused to use the pre-existing systems. A total of Z is needed to get to a prodcution usable version (not in any way perfect, just missing any critical bugs in the code used by 90% of people, etc).

Often, X + Y >= Z (approx).

i.e. if they’d re-used other code, they would have finished a good release a long time ago.

Instead, they hit a brick wall where they languish (Velocity, JMeter for example).

That’s very frustrating.

Probably wasn’t clear, but … I think highly of where they’re aiming, I’ve just become bitter at their repeated inability to get there on all these many fronts.

In parallel, I think badly of the Apache webserver, whose design for many years was fundamentally stupid seemingly because - according to comments on the mailing lists - a core of people who apparently couldn’t understand simple facts about scheduling overhead and refused to go to a proper server threading model, as used on all server software everywhere else in the world.

I am (or would be, if these things were ever delivered!) grateful and supportive of the philosophy and devotion of people involved, just the actual realised achievements are so depressing.

Finally: this is all gross generalization. There are fundamental flaws in any debate on such a basis; for instance, I don’t use their collections at all. It is plausible that you could use a handful of ASF projects and just happen to get the cream of the crop, and have completely different experiences from me.

Most software is shit. Most of the software I write is shit. Mostly everyone else’s software is shit. The OS people are kind enough to let us see just how shit. For the rest of all the software there is, we just get to see it behaving shit instead.

Apache HTTPD and Tomcat are brilliant examples of shitness.

Cas :slight_smile:

[quote]I see a lot of whining, when the reality is - it doesn’t bloody matter. Generics does enough good, and only has a couple, well known, issues that ultimately are never going to affect my code. So I’m happy with it.
[/quote]
Never say you will never be bitten by Java 5 code! Have a look at Sun Generics forum to see strange new things…

A few examples, just to tease you:


public class Problem
{
      public static void main(String[] args)
      {
            java.util.LinkedList<String> list1 = new java.util.LinkedList<String>();
            list1.add("foo");
            list1.add("bar");
            list1.remove("bar");
            java.util.LinkedList<Integer> list2 = new java.util.LinkedList<Integer>();
            list2.add(3);
            list2.add(7);
            list2.remove(7);
      }
}

OK, that’s not generics only but also autoboxing! This program fails with IndexOutOfBoundsException because it does not translate list2.remove(7) as list2.remove(new Integer(7)), just as it would do for list2.add(7).

Also, this one is cool:


Integer x = 2;
Integer y = 2;
Integer a = 200;
Integer b = 200;
// true
System.out.println("x == y : " + ( x == y ));
// false
System.out.println("a == b : " + ( a == b ));

Or generic presumably simplifying the code and making it safer. I like this definition:


public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll)

Explanation: Including “extends Object” is an ugly trick that causes the compiler to erase the method to
“Object min(Collection coll)” instead of “Comparable min(Collection coll)”. This would make
the erased method compatible to J2SDK 1.4…

Yes, new Java version is a bastard one and not all marketing hype Sun is employing to say cleaner, safer Java hides the truth: the baby is ugly!

lol @ CAS

Saw a TV program today about Demetrius. He was a cynical philosopher, and lived from 1 before christ to 63 after.

He thought alot of anger (probably because he worked as a tutor for emperor Nero). He said that anger came from too high expectations , meaning that we humans tend to expect too much and thus be dissapointed when the real world wouldent fufill our expectations .

So the story goes that when emperor Nero demanded that he killed himself, he just took a bath and slith his wrists, with no remorse or anger.

Anyway the morale is. You expect too much of SUN and of software.

Let me put it like this, most of you have been working with software for years. It keeps shrewing up, it keeps being fucked one way or the other. Why do you keep being surprised?. Why be angry?

;D

Its called learning.

Every programmer starts to be fascinated with small programming languages like basic or C. Those languages have a giant seductive power to make a programmer think that everything can be done with a simple instruction like:

x = y + 2

or

if x = 0 then goto exit

And it’s true. The problem his that everythig can be done with a URM machine which has only three instructions:

S(n) increment register N
J(n,m,i) jump to instruction i if the content of registers n and m are equal
Z(n) zero the contents of register n

Soon the programmer starts to realize that the more important question is not really if it can be done or not but how economicaly (in terms of programing hours) the task can be achieved.

After the programmer recognizes the problem he jumps to the next level. He will next try structured programming with functions, subrotines, organized in modules.

This will look like the solution at first. If i can subdivide the problem in smaler problems i can attack any problem of any complexity and turn it into a piece of cake.

This is when the problem becomes the language itself. The programmer starts to recognize patterns in their programs and patterns cannot be well represented as a single function or without changing the language.

The programmer will also recognize the need to control errors in their code when the aplications he creates grow so much that no single person can know all the details or when its important to rotate people and work with code made by others. There is also the problem that people with the right competences is hard to find.

After this the programmer recognizes yet more problems and jumps to another level. This time he will use contract programming and OO language design to attack the new problems he has identified.

Soon contract program will become a limitation because of the language used to define the contracts. OO is not capable to colect all patterns eficiently because OO is just another type of pattern.

So by identifying the new problems the programmer will again dispair and reach for a new level.

This time the programmer will want no restrictions or half-assed solutions. The programmer will want a language that can inspect and write itself; a language with a simple paradigm that will not impose any programming pattern in particular.

Sooner this too will become irrelevant. The programmer will realise the most import thing is not the language itself but the programmers but knowledge of the problem he wants to solve and the elegance of its implementation.

So its perfectly natural for people to have all these complains about Java generics. Java wasn’t really made to be the perfect language but just an easy step into the next level. 8)

[quote]You can blame them for refusing to re-use any / all existing open-source projects and starting again from scratch, thereby wasting lots and ltos of time.
[/quote]
Blame them? Why should I care if they waste their own time? It’s not like I paid them to finish a project for me.

Velocity is one that I recently started using. It works well enough for me as it is. So I don’t care that it wasn’t active for a while. That is the open source way after all. If you need it to do something more you can (and often have to) do it yourself.
Velocity has started moving again. But the point is that it’s the same everywhere. People working for free can’t keep at it forever. Velocity hit a wall and then eventually found someone else to take on some tasks.

The fact that somebody else could have done something better is always going to be true. If you are worried or frustrated about that you will always be frustrated. Take what they have given you (for free) and use it to your advantage. If you can do better join the project or shut up. :slight_smile: