Eric said:
It was the C++ weenies, definitely. You're entirely
correct: The C++ saboteurs have contaminated Java with
generics simply and only to make the language unattractive
and cause its ultimate demise. The Java people have been
suckered into kissing the Bjarne Stone.
Funny thing, I know you intended this as sarcasm, but I agree with it as
written. Well. not quite literally -- I don't suppose there's any
conspiracy -- but I do think that generics have been introduced out of
ill-considered, or unconsidered, C++-envy.
I don't see anything like enough value in (Java's) generics to justify the new
level of complexity. John's post captured perfectly the (perfectly real) value
in generics, so much so that I'm going to quote it again here -- John C.
Bollinger said:
I see some value in the additional self documentation provided by
generic declarations. I also think there is a certain degree of
usefulness simply in organizing your thoughts at design and early
development time well enough to write type constraints.
I (like Chris Smith, it seems) think the above virtues are /way/ more important
than the error trapping of static type checking. But I question whether
generics actually supply /enough/ of the above good things to make up for their
complexity. The arcane effects of erasure, the seemingly arbitrary
restrictions (especially on the use of primitive types -- a problem compounded
rather than eased by auto-boxing), the weird upper/lower bounds
notation/concept... All these mean, as far as I can see, that programmers are
being distracted from the real work of producing working programs, and are
instead being forced to waste time thinking about how to keep the compiler
happy.
Added to that, I am getting the impression that generics are also distracting
people from sound OO -- tending to use generics /instead/ of objects with
clearly defined roles. I'm not really sure that the tendency is widespread,
but if it is, then that's a Bad Thing indeed.
Oh, yes. I also suspect that the implementation is buggy. At least, when I
tried some moderately complex generical programming, I was getting some Very
Strange error messages from the compiler. That suspicion does not in itself
prove that there's anything even slightly wrong with generics -- of course ! --
but what /is/ relevant here is that either the implementation is buggy,
implying that the concepts are over-complicated, or if the implementation is
(mostly) fine, then my understanding must be badly flawed. If the latter is
true, then there is a further choice: either I that am a lot less competent
than I think, or that the generics concepts are a lot more complicated than
is acceptable. Guess which option I'm currently plumping for ;-)
Oh, yeah, and one other teeny-tiny thing: If you make
a mistake, it gets diagnosed at compile time instead of at
run time. Which would you rather receive: a compiler error
that you alone see, or a ClassCastException with all the
honchos from The Big Customer watching? If you'd prefer
the former, learn to like generics.
This is, of course, contentious. There are many people who disagree
(violently! ;-). I happen to be among them. But my point here is not to ague
the point one way or another, but to correct the impression that you may be
giving to less experienced programmers (more my your tone than by the actual
content) that this is a cut-and-dried issue, that the jury has returned its
verdict, and that the book has been closed.
Early error trapping is obviously a Good Thing -- if it's free. The problem is
that it is not. The gains have to be compared with the costs (in brittleness
of design/implementation, in extra complexity, in extra verbosity). The
question of whether the gain pays for the costs of static type checking is far
from closed; there is simply no consensus on the issue. In particular we can
look at the /incremental/ gain in early error trapping provided by generics
(over and above what we already got from Java's pre-generics type-system), and
compare that with the incremental costs (in complexity, etc) of the new
generics. Regardless of whether Java's old type system really earned its keep,
we can consider whether generics are a nett benefit as an add-on. I do not
believe that they are.
-- chris