Your 2 cents: Java Generics, love it, hate it, or waiting?

D

Danno

Right now I think they suck especially when working with libraries that
are older than tiger. That is my opinion.
What is your vote on generics?
 
H

hiwa

I like only its shallowest/simplest usage.
Other parts are just clumsy, as I feel them.
 
T

Timbo

Danno said:
Right now I think they suck especially when working with libraries that
are older than tiger. That is my opinion.
What is your vote on generics?
I liked them at first, then I thought they were odd, but now I
understand them properly I like them again. I do think some of the
type inferencing is hard to follow though.
 
E

Ed

Danno skrev:
Right now I think they suck especially when working with libraries that
are older than tiger. That is my opinion.
What is your vote on generics?

Well, generics are optional; so I'd have rather the question have been
phrased, "Do you use them?" To which I'd have answered, "No."

I do not, however, convulse into a frothy rage when I work with code
that does use them.

The use/not-use generics argument sleeps at the bottom of the
lightless, freezing ocean alongside the end-of-line/new-line
open-bracket argument; if you have the time and passion, you can
charter a submersible to go down and snuffle around in the silt.

But it just doesn't matter.

..ed
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Timbo schreef:
I liked them at first, then I thought they were odd, but now I
understand them properly I like them again. I do think some of the type
inferencing is hard to follow though.

ACK

- --
Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFD1ho7jt+nXoeNxg8RAu9dAJ0dpMeVm0YgEyKdL2Wlh/ICxU/NTACdGffi
ksfpSSWVHvgHCjAlfVctJ3A=
=X5la
-----END PGP SIGNATURE-----
 
O

opalpa

My direct programming experience is they do make portions of code a
little shorter to write and clearer to read.

That positive is in part negated by how confusing previously straight
forward documentation has become. The solution for this is to use java
1.4 documentation and java 5.0 compiler.

Well over 90% of my generics use is in ArrayList, HashMap, HashSet,
TreeSet, and my own pair class. I use these genericised classes, but
have made only two genericised classes on my own: pair, and a very
simple NoRemoveIterator.

I do not use generics in Comparators. Comparators are simple when used
with Object instances/casts and the mental burdon of using generics in
Comparators seems to outweight the benefit in my opinion, for now.


Opalinski
(e-mail address removed)
http://www.geocities.com/opalpaweb/
 
A

Alan Krueger

Danno said:
Right now I think they suck especially when working with libraries that
are older than tiger. That is my opinion.
What is your vote on generics?

Haven't had a chance to use them yet. We may be able to move into 2005
when most of our customers move beyond 1.4 JDKs.
 
J

Joe Attardi

What is your vote on generics?

Personally, I am a big fan. As has been pointed out, they are optional,
so in cases where they are fitting, they are a great addition to the
language. While some will disagree with me on it, I prefer these new
language features over having to cast everything from Object.
 
C

Chris Smith

Danno said:
Right now I think they suck especially when working with libraries that
are older than tiger. That is my opinion.
What is your vote on generics?

Once vote for hate.

It was a promising idea, and I'm a strong believer in static analysis
for the most part. In this case, though, the weight of the extra
complexity added to the language is just not worth it.

Much of the potential benefit is killed by the type erasure idea. The
harder question is whether I would have like generics without type
erasure. I think the answer is yes, I would have liked them.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
C

Chris Smith

Ed said:
Well, generics are optional; so I'd have rather the question have been
phrased, "Do you use them?" To which I'd have answered, "No."

This is simply not true. Generics are NOT optional when reading and
trying to understand the Java language specification. They are NOT
optional when working with third-party code. They are optional if you
work on your own code in your own basement and sell it as shareware on
the internet for a living.
But it just doesn't matter.

Of course it matters. If it didn't matter, why would Sun have spent
probably several million dollars on providing the feature.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Roedy Green

++against;

The problem with it is you create 10 times as many errors as you catch
because it is so complicated with such ugly syntax. The big difference
is, you can catch the errors it creates at compile time.

My contribution to the solution is canned code, e.g Comparable,
Comparable, HashMap that you can copy paste and insert the class
names. It is just about impossible for a newbie to figure the
structure out and the error messages are utterly baffling.
 
T

Thomas Hawtin

Danno said:
Right now I think they suck especially when working with libraries that
are older than tiger. That is my opinion.
What is your vote on generics?

Vote for.

Makes code cleaner and very much easier to understand (so long as you
understand the language, of course). It's particularly important for
boundaries between classes. OTOH, it isn't going to appeal to those that
like dynamically typed languages.

Erasure is irrelevant the vast majority of the time.

Tom Hawtin
 
D

Danno

So, question:

For now, do you @SupressWarnings when you are using external legacy
libraries on methods that you have no way of reconciling?
 
O

opalpa

I notice the following:

javac '-Xlint:-unchecked' x.java

is broken with the javac I'm using right this moment.

"These options are non-standard and subject to change without notice."
the compiler acknowledges the flag but it doesn't respond correctly.

I don't like that the following code:

ArrayList<List> l = new ArrayList();

is to be written:

ArrayList<List> l = new ArrayList<List>();

I get all the benefits I'm seeking with the former and therefore do not
use the latter.

Opalinski
(e-mail address removed)
http://www.geocities.com/opalpaweb/
 
C

Chris Smith

In my opinion no benefit is lost by "type erasure". I've yet to come
across a single benefit lost.

No benefit lost at all? What about the ability to write code without
generating warnings? To drop the ludicrous Class<T> parameters to all
sorts of generic methods? Maybe you don't think these are important
benefits, but it's overstating rather a lot to disagree that any
benefits are lost.
Also there is a huge benefit gained -- compatibility with previous java
releases.

Specifically, the compatibility gained is the ability to use code
compiled with Java 1.5 in a pre-1.5 release. This is not an important
kind of compatibility, and it appears Sun has decided not to maintain it
anyway, since the class file version number was changed.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
T

Thomas Hawtin

Chris said:
Specifically, the compatibility gained is the ability to use code
compiled with Java 1.5 in a pre-1.5 release. This is not an important
kind of compatibility, and it appears Sun has decided not to maintain it
anyway, since the class file version number was changed.

It's the ability to use pre-1.5 and J2ME code with generic code. 1.4
implementations of now generic types still work, as does passing and
receiving now generic types to old code. Without that there would be
trouble.

OTOH, without the ability to run generic code on 1.4 and J2ME, I'd have
preferred a better solution. It's a bit difficult to change that now
with all the unchecked code that breaks static typing out there.

Tom Hawtin
 
O

opalpa

No benefit lost at all? What about the ability to write code without
generating warnings?

I don't see how this is lost. Type erasure refers to generics info
being lost after compile finishes, right? Type erasure does not effect
the number of generated compiler warnings.
To drop the ludicrous Class<T> parameters to all
sorts of generic methods?

Can you be more specific, please. I do not see what you are referring
to. Maybe we mean very different things by "type erasure". Here is an
article that uses "type erasure":
http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html .

Regardless of "type erasure" or .... "type retention" the paramters,
signatures, documentation of methods would not change. Can you list a
handful of methods that take "Class said:
Maybe you don't think these are important
benefits, but it's overstating rather a lot to disagree that any
benefits are lost.

Now I'm guessing we mean something very different by "type erasure".
The items you noted are not effected by generics type info being erased
after compilation.

Opalinski
(e-mail address removed)
http://www.geocities.com/opalpaweb/
 
O

opalpa

Specifically, the compatibility gained is the ability to use code
compiled with Java 1.5 in a pre-1.5 release. This is not an important
kind of compatibility, and it appears Sun has decided not to maintain it
anyway, since the class file version number was changed.

I was of something else: If you have sources that were written before
5.0 you can write new classes which use generics and have data flow
between instances of previously written classes and generics using
classes.

--

If you have classes B,C,D which use class A internally, where class A
is a container. You then modify A to be a generic, paramterizable on
Classes. The change to A does not break B,C,D. B,C,D can stay excalty
as they were even though the container they use internally has changed
to be a generic.

Opalinski
(e-mail address removed)
http://www.geocities.com/opalpaweb/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,811
Messages
2,569,693
Members
45,478
Latest member
dontilydondon

Latest Threads

Top