The Source for Java Technology Collaboration

Home » java.net Forums » JDK » Java SE

Thread: Remove generics in JDK SE

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 25 - Last Post: Aug 11, 2007 10:05 PM by: azlan95
javadesigner2

Posts: 1
Remove generics in JDK SE
Posted: Jun 27, 2007 1:06 PM
  Click to reply to this thread Reply

Generics as proven to be unreadable garbage for me and many other java programmers.

It's a fundamental design problem. Even Ken Arnold, author of the language specification
thinks so:

http://weblogs.java.net/blog/arnold/archive/2005/06/generics_consid_1.html

It needs to be removed either officially. Is the openJDK Governing Board doesn't want
to do this, the openJDK tree needs to be formally branched into a new jdk tree.

At first, we will need to do the following:

1) Change javac so it does not understand generics
2) Change javadoc so it does not understand generics
3) Change the jdk libraries and revert all generics code into non-generic equivalents.

Anyone interested in working on this with me ?

--j
javadesigner@yahoo.com

tarbo

Posts: 425
Re: Remove generics in JDK SE
Posted: Jun 27, 2007 2:00 PM   in response to: javadesigner2
  Click to reply to this thread Reply

Hm... I don't really see why generics would be unreadable garbage. They are a little complex at times, but since I've started working with them, I wonder how I ever did without. I work a lot with containers, generators/factories and the like and enjoy the type safety I am given with--to me--a minimum of fuss.

You can work without generics if you so prefer. Just don't include the angled brackets and AFAIK you can happily work away like the good ol' days. I don't see why they should be forcefully removed when you can choose to ignore them.

jwenting

Posts: 478
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 5:46 AM   in response to: tarbo
  Click to reply to this thread Reply

When I first saw code with generics I too thought it was hard to read.
Once I got used to it though it's a massive improvement, especially when you're relying on 3rd party APIs returning collections (or worse, Collections containing Maps containing Maps containing Collections of Maps, I've seen it).

mthornton

Posts: 528
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 6:39 AM   in response to: jwenting
  Click to reply to this thread Reply

Wow, jwenting offering support for generics!
Obviously collections are the poster case for generics. While I haven't seen collections nested quite that deeply, some nesting isn't unnatural.

jwenting

Posts: 478
Re: Remove generics in JDK SE
Posted: Jun 29, 2007 1:03 AM   in response to: mthornton
  Click to reply to this thread Reply

They worked out well. While I still feel adding them wasn't necessary (and in some cases may make things look obscure to the uninitiated which may provide an extra hurdle to people learning the language, something that Sun always claims they want to avoid), they did do a pretty decent job of it overall.

They are thus a mixed blessing. To the experienced user they can be a powerful and helpful tool, to the beginner they provide extra complexity that has to be mastered.

arreumb

Posts: 2
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 3:27 AM   in response to: javadesigner2
  Click to reply to this thread Reply

Remove generics ? And what about all the code that used generics until now ?

ullenboom

Posts: 7
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 3:48 AM   in response to: javadesigner2
  Click to reply to this thread Reply

Your are joking, aren't you? Generics are an essential part of JPA, Web Services, …, and the current Java Closure specification. Now it’s a little too late for removing. I only see a radius of operation in introducing type information on runtime to make the best of a bad job.

Best wishes,

Christian

@url http://www.tutego.com/

mthornton

Posts: 528
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 4:21 AM   in response to: javadesigner2
  Click to reply to this thread Reply

> It's a fundamental design problem. Even Ken Arnold,
> author of the language specification
> thinks so:

Did you notice that he also thinks it too late to reverse?

Some of the complications are fundamental to generics (such as subclassing) while others are a consequence of erasure. So if we can't go back, perhaps we can go forward to reified generics.

opinali

Posts: 24
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 5:30 AM   in response to: javadesigner2
  Click to reply to this thread Reply

What about focusing your efforts into improving generics - either in the standards way (push the JCP to do that, e.g. reification) or forking openjdk? Besides not breaking gigabytes of recente APIs and code, there's the additional benefit of not making you look silly.

jwenting

Posts: 478
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 5:44 AM   in response to: opinali
  Click to reply to this thread Reply

people screaming for "new features" and "fixes" have a way of making themselves look silly like that.
Usually it's because they really don't know what they're talking about, and if they do it's because they're religious zealots who have no concept of things outside their own little box and think that the entire world revolves around their wants and needs.

dansiviter

Posts: 36
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 5:58 AM   in response to: javadesigner2
  Click to reply to this thread Reply

Yer what?!

Firstly, Java has a history of maintaining compatibility with older versions. Removal is not an option.
Secondly, confusing? Generics has vastly cleaned up much of the untidy casting of objects and has helped in removing run-time ClassCastException as types are checked at compile-time.
Thirdly, I simply disagree that they are complex. I picked them up very quickly, I use them day in day out. And if you don't like them, don't use them.

Sun were worried that once they open source the code base, anti-social forking of the code base could a problem. This causes incompatibilities that essentially breaks what Java is all about: write once, run anywhere!

Ken's article was written two years ago. I wonder if he has changed his opinion since then.

hytparadisee

Posts: 9
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 6:09 AM   in response to: javadesigner2
  Click to reply to this thread Reply

"Generics as proven to be unreadable garbage for me and many other java programmers."

So you enjoy casting all over the place? Or you adore wrapping around your method for some extra code size? Go ahead! No one will stop you. I just don't understand if you don't like generics, why not use them? You can still use whatever you wanted in the old way, just treat them as though you are using jdk1.3 all right? If not, i cannot believe what you would do once closure is out -> Change javac so it does not understand closures?

sasdav

Posts: 17
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 6:50 AM   in response to: javadesigner2
  Click to reply to this thread Reply

Generics are a good feature and I feel they should stay in on the condition that Swing models support them.

cbaatz

Posts: 2
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 7:29 AM   in response to: javadesigner2
  Click to reply to this thread Reply

I once was told something I believe is fundamentally true. In the life of a programmer there will be fundamental paradigm shifts in which some programmer will be able to adopt to and others wont. At the risk of sound harsh, if you don't like something don't use it.

As everyone knows there is a process for getting something added to the Java language standard and you really missed your chance to voice your complaints. I'm tiered of seeing postings complaining about how something works/looks. If enough people stop using the feature it will be forgotten (Java seems to never actually remove stuff).

cowwoc

Posts: 1,055
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 10:29 AM   in response to: javadesigner2
  Click to reply to this thread Reply

Maybe we can put a more positive spin on this...

I agree that we should either remove Generics or put in the necessary effort to reify them and add convenience mechanisms (a "safe" typedef perhaps?) to make Generic code more readable and easier to write.

Generics works wonders for Collections, I don't disagree at all. But try doing anything more complicated with them in user-defined generic classes and you'll quickly run into a wall. I would be very glad if OpenJDK cleaned up Generics.

Thank you,
Gili

alski

Posts: 15
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 10:32 AM   in response to: javadesigner2
  Click to reply to this thread Reply

You're only kidding, right? Kidding I hope any way. Last time I checked, generics were optional, you don't have to use them unless you want to. In fact, I wish they implemented them in the Swing models but they didn't. Asking to remove them is like saying everyone should have their teeth pulled because one person has problems with them and couldn't stop biting their own tongue.

gafter

Posts: 7
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 11:24 AM   in response to: javadesigner2
  Click to reply to this thread Reply

> Generics as proven to be unreadable garbage for me
> and many other java programmers.
>
> It needs to be removed either officially. Is the
> openJDK Governing Board doesn't want
> to do this, the openJDK tree needs to be formally
> branched into a new jdk tree.

The openJDK board doesn't control the language specification, only the community supporting one implementation of it.

> 1) Change javac so it does not understand generics
> 2) Change javadoc so it does not understand generics
> 3) Change the jdk libraries and revert all generics
> code into non-generic equivalents.
>
> Anyone interested in working on this with me ?

Not really. I don't see how you can do it, since javac and javadoc use generics heavily, but you find such code to be unreadable. If you learn to understand the code so you can modify javac and javadoc, then generics will be readable to you and the change is no longer needed.

erickson

Posts: 10
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 11:46 AM   in response to: gafter
  Click to reply to this thread Reply

Zing! Virtual high five, gafter.

eputrycz

Posts: 26
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 3:43 PM   in response to: javadesigner2
  Click to reply to this thread Reply

> It's a fundamental design problem. Even Ken Arnold,
> author of the language specification
> thinks so:

No... He doesn't mention any "fundamental design problem". He just thinks that it makes code too complicated. Also Ken Arnolds doesn't speak for all java developers.

I think the compiler could make code with generics less verbose but other than that, the benefit of preventing *ugly* casts with generics is trememdous.

Erik.

prunge

Posts: 101
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 4:00 PM   in response to: javadesigner2
  Click to reply to this thread Reply

This would break a large amount of code that now uses generics - it aint gonna happen.

I agree that generics can be complicated, especially when you start getting deeply nested types with a mixture of self-referencing type variables with wildcards, but really how often does the average developer use these?

I have noticed quite a few developers still do not understand generics properly. They get how you can declare a List that can only contain Strings, but as soon as you get into wildcards and writing your own generic types, I'd bet that a fair amount of Java coders would get stuck.

I'd also be much happier if reification was added.

carcour

Posts: 79
Re: Remove generics in JDK SE
Posted: Jun 28, 2007 5:45 PM   in response to: javadesigner2
  Click to reply to this thread Reply

Generics are the best addition to the Java programming language. Maybe you don't have experience with generified code! If you don't like it then don't use it

azlan95

Posts: 40
Re: Remove generics in JDK SE
Posted: Aug 9, 2007 4:08 AM   in response to: carcour
  Click to reply to this thread Reply

I think the biggest mistake is the "enum" keyword. Many old codes and binaries have Enumeration enum;

Azlan

tarbo

Posts: 425
Re: Remove generics in JDK SE
Posted: Aug 9, 2007 11:01 AM   in response to: azlan95
  Click to reply to this thread Reply

I find it highly unlikely that code containing Enumeration will be compiled using a 1.5-compatible compiler. Even then, would it be such a hurdle to text-replace enum with something else?

azlan95

Posts: 40
Re: Remove generics in JDK SE
Posted: Aug 11, 2007 3:01 AM   in response to: tarbo
  Click to reply to this thread Reply

I think you meant: highly unlikely the word Enumeration *won't* compile with 1.5 compiler.

It's not the word Enumeration, it's the word "enum" which is a keyword starting in Java 5. Anyway for those who still have the source codes, they can do the edition, but those with only binaries, well "it's not compatible with 1.5"

Azlan

tarbo

Posts: 425
Re: Remove generics in JDK SE
Posted: Aug 11, 2007 2:47 PM   in response to: azlan95
  Click to reply to this thread Reply

No, I did mean that I find it highly unlikely someone using a 1.5 compiler will use the Enumeration class, which was obsoleted in 1.2 with the introduction of the Collection Framework. And I realise you meant the word "enum", not the class Enumeration, but the point stands that, if you run code that uses the pattern "Enumeration enum" through a 1.5 compiler, you might as well do a text search-replace on "enum" or move onto Iterator (if possible).

If all this is impossible, you can still use "-source 1.4" as a compiler switch, but you'll have to be aware that you can't use language features introduced since 1.5. Which should not be a problem, given that editing to 1.5 source compatibility was the issue to start with.

"but those with only binaries, well "it's not compatible with 1.5""
Whether you used the word "enum" in source code or not will not affect compatibility after it is compiled. Libraries compiled earlier will still run in 5 and beyond, so there is no need for any edit there.

azlan95

Posts: 40
Re: Remove generics in JDK SE
Posted: Aug 11, 2007 10:05 PM   in response to: tarbo
  Click to reply to this thread Reply

http://mail-archives.apache.org/mod_mbox/forrest-svn/200602.mbox/3C20060220005638.94326.qmail@minotaur.apache.org%3E

http://www.koders.com/java/fid23E1027A6DB0EBF0A95B63BF36909BA9869BD79.aspx?s=cdef%3Atree

http://www.codeguru.com/java/articles/124.shtml

http://www.redhat.com/archives/fedora-directory-users/2005December/msg00337.html

http://vip.cs.utsa.edu/classes/cs4773s98/notes/cs4773.topic10.html

I googled and found these five classic examples of how coders' normally think when it comes to choosing an Enumeration object name.

btw most likely each one of these came from an independent mind, yet it's interesting to note how all of these minds think alike when choosing "enum" as object names.

Having said that I hope Sun will not change anything. What has been decided, stick with it. Coders must adjust to the new keyword.

As for the old binaries being able to run on 1.5, I'm not too sure. I tried to run an older application on 1.5 but it was broken. My suspicion is its because of the "enum" keyword. I have not tested my own classes with "enum" object names on 1.5.

The -source is not supported in 1.5, not on my machine at least. I have 1.5.0.06

Now the Enumeration is not only "derived" from Vectors. Sure we can substitute Vectors with Collections but what about JarFile? Enumeration is also "derived" from JarFile. Enumeration<E> enu = JarFile.entries();

So to say Enumeration is obsolete I guess is not quite true. It is still very much relevant as far as I can tell. And notice in one of the links I posted dated as recent as 2006. Many codes like those are still being used today.

Azlan




 XML java.net RSS