Java Forum / General / November 2005
Generics - good, bad or indifferent?
TechBookReport - 28 Oct 2005 11:09 GMT Does anybody have a good word to say about generics in J2SE 5.0? I can't help thinking it's a sledgehammer to crack a nut. Casting into and out of collections wasn't such a big deal. Sure type-safety is important, but the implementation is intrusive and ugly (aesthetics seem important to me). If anything surely the class cast problem is something that intelligent tools like Eclipse or NetBeans could have solved without resorting to language changes. Particularly as erasure means that it's only at compile time that generics provide a benefit.
Am I missing something or did we just add complications to the language for little real benefit?
Pan
 Signature TechBookReport Java book reviews http://www.techbookreport.com/JavaIndex.html
iamfractal@hotmail.com - 28 Oct 2005 11:21 GMT TechBookReport skrev:
> Does anybody have a good word to say about generics in J2SE 5.0? I can't > help thinking it's a sledgehammer to crack a nut. Casting into and out [quoted text clipped - 13 lines] > TechBookReport Java book reviews > http://www.techbookreport.com/JavaIndex.html "Intrusive and ugly," seems rather strong. I'm just glad that they used the angle brackets that C++ already uses for templating; no point in re-inventing a symbol when there's already heritage.
And as for generics being part of the language, well, yes you have to know them in case you're using code that uses them, but they are still optional for your own, original work. Generics should be used when the following two conditions hold: A) There are a significant number of casting errors caused by mxing types in collections. B) Identifying the errors introduced in (A) is significantly time-consuming.
.ed
-- www.EdmundKirwan.com - Home of The Fractal Class Composition.
Larry Barowski - 28 Oct 2005 20:56 GMT > "Intrusive and ugly," seems rather strong. I'm just glad that they used > the angle brackets that C++ already uses for templating; no point in > re-inventing a symbol when there's already heritage. Using the angle brackets in this way added a lot of mess to the language grammar (because, for one thing, <x <y <x>>> , <x <y <z>> > , <x <y <z> >> , and <x <y <z> > > are four different token sequences that all mean the same thing). Some priority must be given to keeping the grammar clean and keeping a good separation between grammar and lexical specification. Of course, there are only so many available symbols, and I can't think of a symbol pair that would look good and lead to a clean grammar. <#x<#y#>#> just doesn't look right.
Oliver Wong - 28 Oct 2005 21:08 GMT >> "Intrusive and ugly," seems rather strong. I'm just glad that they used >> the angle brackets that C++ already uses for templating; no point in [quoted text clipped - 4 lines] > <x <y <z>> > , <x <y <z> >> , and <x <y <z> > > are > four different token sequences that all mean the same thing). To me, this is like complaing the following 4 lines are 4 different token sequences that all mean the same thing (note I'm assuming your first example is a typo and the second x should be a z):
<4tokenSequences> int x; int x; int x; int x; </4tokenSequences>
> Some priority must be given to keeping the grammar clean > and keeping a good separation between grammar and > lexical specification. Of course, there are only so many > available symbols, and I can't think of a symbol pair that > would look good and lead to a clean grammar. <#x<#y#>#> > just doesn't look right. Because you can nest generic type information, you need an a pair of symbols: an "open" symnol and a "close" symbol. With ASCII, you're pretty much restricted to one of the four (), [], {} or <> (any other pair, e.g. $% or ~/, would probably look unnatural), and of those 4, <> really does seem like the least confusing one to use.
- Oliver
Thomas Hawtin - 28 Oct 2005 21:28 GMT >>>"Intrusive and ugly," seems rather strong. I'm just glad that they used >>>the angle brackets that C++ already uses for templating; no point in [quoted text clipped - 8 lines] > token sequences that all mean the same thing (note I'm assuming your first > example is a typo and the second x should be a z): To the programmer, yes (so long as they aren't a C++ programmer). To the lexer, >> and >>> is shift arithmetic and logical shift right operators. The lexer needs to be fudged so that it returns a series of individual
> symbols if the grammar state is within a generic declaration.
> Because you can nest generic type information, you need an a pair of > symbols: an "open" symnol and a "close" symbol. With ASCII, you're pretty > much restricted to one of the four (), [], {} or <> (any other pair, e.g. $% > or ~/, would probably look unnatural), and of those 4, <> really does seem > like the least confusing one to use. You can naturally nest " and ', as INTERCAL does. Also Java uses Unicode, so it wouldn't be too awful to use other symbols. Might make some poor character set handling clean up its act.
Tom Hawtin
 Signature Unemployed English Java programmer http://jroller.com/page/tackline/
Bent C Dalager - 29 Oct 2005 00:29 GMT >You can naturally nest " and ', as INTERCAL does. Now, that's a first: "That's how INTERCAL does it" used as an argument in favour of a feature :-)
Cheers Bent D
 Signature Bent Dalager - bcd@pvv.org - http://www.pvv.org/~bcd powered by emacs
Larry Barowski - 29 Oct 2005 02:12 GMT > To the programmer, yes (so long as they aren't a C++ programmer). To the > lexer, >> and >>> is shift arithmetic and logical shift right operators. > The lexer needs to be fudged so that it returns a series of individual > symbols if the grammar state is within a generic declaration. That kind of parser-lexer interaction makes me queasy. Sun provided a grammar solution, but it isn't pretty. Humans will naturally interpret the generics grammar as a lexer state change, so the fact that there is a grammar solution isn't entirely satisfying.
Larry Barowski - 29 Oct 2005 01:53 GMT > To me, this is like complaing the following 4 lines are 4 different > token sequences that all mean the same thing (note I'm assuming your first [quoted text clipped - 6 lines] > int x; > </4tokenSequences> Those are 4 identical token sequences.
Oliver Wong - 31 Oct 2005 19:18 GMT >> To me, this is like complaing the following 4 lines are 4 different >> token sequences that all mean the same thing (note I'm assuming your [quoted text clipped - 8 lines] > > Those are 4 identical token sequences. Yes, sorry, I didn't realize until Thomas Hawtin's reply that you were talking about difficulties involving parsing Java code. I thought when you said "adds a lot of mess to the language", you were talking about some sort of sense of aesthetics from a human perspective.
- Oliver
megagurka - 28 Oct 2005 11:59 GMT TechBookReport skrev:
> Does anybody have a good word to say about generics in J2SE 5.0? I can't > help thinking it's a sledgehammer to crack a nut. Casting into and out [quoted text clipped - 7 lines] > Am I missing something or did we just add complications to the language > for little real benefit? The benefit is big. Genericity is a fundamental building block of a type safe programming language (which, I hope, Java is meant to be), so generic types and methods should have been included in Java from day one. The implementation, as you mention, is lacking. Not changing the JVM to support generic types was a mistake and the cost of this mistake will only increase with time until it's rectified. The .NET implementation of generics has VM support, which is a big plus, but the implementation of type contraints is better in the Java version.
The awkwardness of using generic types could be mitigated by introducing type inference of field and local variable types, for example:
let v = new Vector<Point<Integer>>();
which would be equivalent to:
Vector<Point<Integer>> v = new Vector<Point<Integer>>();
Replace "let" with your favourite keyword. Maybe this could be filed as an RFE, if it hasn't been already. It probably won't be approved, because the Sun engineers are probably busy implementing the XML language syntax. *shiver*
/Jesper Nordenberg
Chris Uppal - 28 Oct 2005 12:35 GMT > Am I missing something or did we just add complications to the language > for little real benefit? That's my opinion.
The benefits gained are two-fold. We significantly reduce (but not eliminate) the risk of casting errors. We gain better self-documentation of the code.
The first of these is (IMO) completely negligible. It just wasn't worth the effort. It doesn't even justify the small effort of typing in the <>s. Let alone the massive complications to the javac implementation; to the java specification (which is now essentially unreadable, while it /used/ to be a valuable resource); and to all Java-aware tools such as Eclipse. (Just think what valuable improvements to Eclipse we are missing because the programmers' time was spent on the changes needed to support generics -- and God knows, Eclipse could do with a bit of improvement...)
The second is (IMO) a lot more valuable. Certainly I'd rather know that some method answers a List<Point> than just a List. However, when you factor in the "wildcard" notation, the generic type definitions quickly become unreadable. And, in my limited experience, so far, that happens more often than not. So you end up ignoring the spec, and assuming that it's "correct" and does in fact mean what logic and experience suggest it /should/ mean. So the documentary value is compromised.
I think they blew it.
-- chris
Oliver Wong - 28 Oct 2005 15:58 GMT >> Am I missing something or did we just add complications to the language >> for little real benefit? [quoted text clipped - 5 lines] > the risk of casting errors. We gain better self-documentation of the > code. [...]
> The second is (IMO) a lot more valuable. Strongly agreed. We've got multiple programmer working on this project where collections (e.g. Vector, ArrayList, etc.) are being passed around a lot. Prior to generics, someone would write code that puts stuff into a Vector, and someone else would write code that gets the stuff out of the Vector.
Once we had generics, we decided to actually document what the Vector contains (i.e. change Vector to Vector<String>). This generated quite a few compilation errors because apparently there was some miscommunication going around as to what actually belonged in a given collection.
What generics does is takes some of the runtime errors (mainly casting errors), and changes them to compilation errors, and that's usually a good thing.
The concept of generics itself is good, but it's implementation in Java isn't all that great. As megagurka mentioned, Sun really should have modified the JVM so that the type information isn't erased at runtime. As it stands now, generic feels like a feature hacked onto Java rather than part of the original design (probably because that's exactly what happened).
- Oliver
Roedy Green - 28 Oct 2005 20:09 GMT > Once we had generics, we decided to actually document what the Vector >contains (i.e. change Vector to Vector<String>). This generated quite a few >compilation errors because apparently there was some miscommunication going >around as to what actually belonged in a given collection. But then people work very hard to hide that information again in the declaration and put it only in the constructor to help restore the confusion. This is considered the adult way to program.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
TechBookReport - 31 Oct 2005 11:53 GMT >>Am I missing something or did we just add complications to the language >>for little real benefit? [quoted text clipped - 24 lines] > > -- chris I was thinking along those lines. One consequence is that learning Java is now a lot more complicated than it needs to be. This is bound to have a knock-on effect in the longer term.
 Signature TechBookReport Java book reviews http://www.techbookreport.com/JavaIndex.html
Roedy Green - 31 Oct 2005 21:20 GMT >I was thinking along those lines. One consequence is that learning Java >is now a lot more complicated than it needs to be. This is bound to have >a knock-on effect in the longer term. what does knock-on effect mean, "cumulative", "multiplier"?
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
TechBookReport - 01 Nov 2005 11:36 GMT >>I was thinking along those lines. One consequence is that learning Java >>is now a lot more complicated than it needs to be. This is bound to have >>a knock-on effect in the longer term. > > what does knock-on effect mean, "cumulative", "multiplier"? Cumulative probably. It's another complication to gaining proficiency in Java.
 Signature TechBookReport Java book reviews http://www.techbookreport.com/JavaIndex.html
Chris Uppal - 01 Nov 2005 10:45 GMT > One consequence is that learning Java > is now a lot more complicated than it needs to be. This is bound to have > a knock-on effect in the longer term. I'm not a teacher, but to me it seems as if the biggest problem will be that "generics" are not an implementation of parameterised classes (itself a perfect transparent notion, I would say), but only of parameterised types -- and an incomplete implementation af that. It's the irregularity and baffling[*] incompletness that will cause more problems. Parameterisation is a powerful notion, and a student either gets it or they don't; but when that notion is arbitrarily[*] restricted, then it becomes much more work to internalise. Someone (up-thread) compared generics with polymorphism; not a bad comparison IMO -- but the actual analogy would be more like polymorphism with some added "feature" such as that it didn't work if any method parameter was of a primitive type or array type...
([*] "baffling" and "arbitrary" from the POV of a newcomer, of course -- or of anyone who cares about simplicity and consistancy of design.)
-- chris
Thomas Hawtin - 28 Oct 2005 19:11 GMT > Does anybody have a good word to say about generics in J2SE 5.0? It appears that most of those spouting off about the evilness of generics are dynamic typing fans. If you don't like static typing, then you aren't going to want more of it. If you do like static typing, it might as well be done properly.
> I can't > help thinking it's a sledgehammer to crack a nut. Casting into and out > of collections wasn't such a big deal. No it's not a big deal. Although it is ugly, tends to lead to unnecessary code and the source is complicated precisely where you want it as simple as possible.
> Sure type-safety is important, > but the implementation is intrusive and ugly (aesthetics seem important > to me). If anything surely the class cast problem is something that > intelligent tools like Eclipse or NetBeans could have solved without > resorting to language changes. ClassCastException is a red herring. Searching through the Bug Parade brings up seven times more bugs with NullPointerException than ClassCastException.
> Particularly as erasure means that it's > only at compile time that generics provide a benefit. Given that we have such good static type checking, runtime type checking is an obscure feature. Having said that, as 1.4- isn't targeted, I would have preferred a JVM level implementation, particularly for covariant return types (which still have outstanding bugs).
It's not a valid criticism coming at it from a dynamic typing point of view, anyway. You can't, as I understand it, take a Smalltalk collection and ask what shapes will all its contents, past and future, will conform to.
The real issue, assuming you welcome static typing into your life, is documentation. It's much easier to understand what is in Set<EmployeeID> than Set with the element type hidden amongst the JavaDocs if at all and if kept in sync.
For instance, modifying a JRoller Velocity template, many of the methods return Lists. But the documentation (often) doesn't (didn't) say what they contain. I've inherited code that accidentally used the same map for two different mappings. That only became apparent because, coming from C++, I used to put type information within /*< >*/.
I find JavaDoc Use pages useful in understanding how a piece of code fits together. In olden days, if you didn't use arrays, you didn't get to see a lot of important relationships. In one case, I was witting the public API documentation to a product and wrote in on the type description the missing uses. Shortly after that the PSE changed the Collections to arrays. But really, we would like to encourage the use of interfaces over nasty arrays.
While some people coming to generics might find them confusing, if they push their minds back far enough, they probably found polymorphism confusing too. They are essentially the same thing, just with a layer of indirection. Perhaps it will take a while for texts to become stable.
Tom Hawtin
 Signature Unemployed English Java programmer http://jroller.com/page/tackline/
Roedy Green - 28 Oct 2005 20:11 GMT On Fri, 28 Oct 2005 19:11:49 +0100, Thomas Hawtin <usenet@tackline.plus.com> wrote, quoted or indirectly quoted someone who said :
>It appears that most of those spouting off about the evilness of >generics are dynamic typing fans. I think the reasons are more the complexity of the code required for a fairly trivial end, and the way type erasure causes so much code that makes perfect sense to humans, not legal.
It is a implementation driven syntax.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Chris Stiles - 29 Oct 2005 10:55 GMT >>It appears that most of those spouting off about the evilness of >>generics are dynamic typing fans. [quoted text clipped - 4 lines] > > It is a implementation driven syntax. One implementation detail that I'm not clear about. Both javac and JDTCompiler appear to allow inner classes inside generics. However javac will barf over use of the unqualified inner class name inside the generic in which it is declared, JDTCompiler appears not to.
 Signature regards, chris
Ian Pilcher - 30 Oct 2005 00:42 GMT > I think the reasons are more the complexity of the code required for a > fairly trivial end, and the way type erasure causes so much code that > makes perfect sense to humans, not legal. The latter reason is certainly my biggest frustration. I actually think that parameterized types are a big forward ... theoretically. The current implementation, however, verges on being unusable.
<rant> The current state of the Java compiler is a travesty. I can't figure out how Sun thinks its acceptable that there is no way to, for example, create an array of parameterized objects without generating a warning. Tiger is feeling a lot like an extended beta test for Mustang. </rant>
 Signature ======================================================================== Ian Pilcher i.pilcher@comcast.net ========================================================================
Stefan Ram - 30 Oct 2005 01:04 GMT >how Sun thinks its acceptable that there is no way to, for >example, create an array of parameterized objects without >generating a warning. What is a parameterized object?
Ian Pilcher - 30 Oct 2005 04:11 GMT > What is a parameterized object? My term for an instance of a parameterized type.
 Signature ======================================================================== Ian Pilcher i.pilcher@comcast.net ========================================================================
Stefan Ram - 30 Oct 2005 06:04 GMT >>What is a parameterized object? >My term for an instance of a parameterized type. The type of an instance is what
instance.getClass()
returns, or - possibly - every type T with
instance instanceof T
This type is never parameterized because of type erasure.
Types of objects (instances) (entities of the run-time model) are not parameterized - only types of expressions or other entities of the source-code model can be parameterized.
Thomas Hawtin - 30 Oct 2005 01:37 GMT > <rant> > The current state of the Java compiler is a travesty. I can't figure > out how Sun thinks its acceptable that there is no way to, for example, > create an array of parameterized objects without generating a warning. The problem there is arrays. It's arrays that should be avoided. In the same way you prefer String/StringBuilder over char[], you should prefer List<T> over T[]. ArrayList has already been implemented. We don't need to worry about it.
> Tiger is feeling a lot like an extended beta test for Mustang. > </rant> Perhaps Mustnag will fix a few bugs, but don't expect language changes.
Tom Hawtin
 Signature Unemployed English Java programmer http://jroller.com/page/tackline/
Ian Pilcher - 30 Oct 2005 04:15 GMT > The problem there is arrays. It's arrays that should be avoided. In the > same way you prefer String/StringBuilder over char[], you should prefer > List<T> over T[]. ArrayList has already been implemented. We don't need > to worry about it. I'm not sure if you're being intentionally sarcastic or not. You don't really think that arrays should never be used, do you?
Regardless, array creation is only one example. How about an object created by Class.newInstance?
> Perhaps Mustnag will fix a few bugs, but don't expect language changes. At least the Mustang compiler supports @SuppressWarnings. You know, the annotation that Sun introduced in 1.5, but didn't bother to actually support in fripping compiler.
 Signature ======================================================================== Ian Pilcher i.pilcher@comcast.net ========================================================================
Thomas Hawtin - 30 Oct 2005 05:28 GMT > I'm not sure if you're being intentionally sarcastic or not. You don't > really think that arrays should never be used, do you? I think arrays of objects should be avoided. Not always, but your code is probably better off with a List.
> Regardless, array creation is only one example. How about an object > created by Class.newInstance? The Class.newInstance method itself is fine (apart from the exception-safety aspect of it). Called on a object of the Class<T> it returns a reference of type T. What are you expecting here?
> At least the Mustang compiler supports @SuppressWarnings. You know, the > annotation that Sun introduced in 1.5, but didn't bother to actually > support in fripping compiler. 1.5 update 6 will support it.
Tom Hawtin
 Signature Unemployed English Java programmer http://jroller.com/page/tackline/
Ian Pilcher - 30 Oct 2005 06:04 GMT > The Class.newInstance method itself is fine (apart from the > exception-safety aspect of it). Called on a object of the Class<T> it > returns a reference of type T. What are you expecting here? Called on an object of Class<HashSet> it returns a HashSet. There is no want to convert that reference to a parameterized HashSet without a compiler warning. I'm simply flumoxed that Sun thought this was acceptable.
> 1.5 update 6 will support it. Well, that's good news. Do you have a source for this?
 Signature ======================================================================== Ian Pilcher i.pilcher@comcast.net ========================================================================
Mark Thornton - 30 Oct 2005 09:54 GMT >>The Class.newInstance method itself is fine (apart from the >>exception-safety aspect of it). Called on a object of the Class<T> it [quoted text clipped - 4 lines] > compiler warning. I'm simply flumoxed that Sun thought this was > acceptable. Your complaints all seem to be about the unavoidable consequences of erasure. Unfortunately the compatibility problems of not using erasure are such that I don't think Sun could have reasonably taken such a step.
Mark Thornton
Ian Pilcher - 30 Oct 2005 17:33 GMT > Your complaints all seem to be about the unavoidable consequences of > erasure. Unfortunately the compatibility problems of not using erasure > are such that I don't think Sun could have reasonably taken such a step. My complaints revolve around the *compiler*, and the fact that the current released compiler provides no way to do several necessary things without generating warnings.
 Signature ======================================================================== Ian Pilcher i.pilcher@comcast.net ========================================================================
Thomas Hawtin - 30 Oct 2005 12:10 GMT >>The Class.newInstance method itself is fine (apart from the >>exception-safety aspect of it). Called on a object of the Class<T> it [quoted text clipped - 4 lines] > compiler warning. I'm simply flumoxed that Sun thought this was > acceptable. Seems completely reasonable to me. If you were to pass Class<HashSet<String>> to Class.newInstance, then you would get a HashSet<String>. I'm simply flummoxed that you thought this was unacceptable.
In any case, you should expect casting and unsafe code if you play about with reflection.
Perhaps you refer the hack to the handling of Object.getClass that returns the erasure of the class (you can handle that in one place, if you wish). Also HashSet<String>.class will not work. There are also cases were the library hasn't used generics as well as it might.
The exception-safety aspect of Class.newInstance, is in my opinion unacceptable. Constructor.newInstance should be used instead.
>>1.5 update 6 will support it. > > Well, that's good news. Do you have a source for this? http://www.google.com/search?q=SuppressWarnings+5.0u6
Tom Hawtin
 Signature Unemployed English Java programmer http://jroller.com/page/tackline/
Ian Pilcher - 30 Oct 2005 17:32 GMT > Seems completely reasonable to me. If you were to pass > Class<HashSet<String>> to Class.newInstance, then you would get a > HashSet<String>. I'm simply flummoxed that you thought this was > unacceptable. I think it's unacceptable that the *compiler* doesn't provide a way to get a HashSet<String> reference without a warning.
> In any case, you should expect casting and unsafe code if you play about > with reflection. I don't have a problem with the requirement for casting. I have a problem with a compiler that provides no way to do *required* casting (without generating a warning which is not allowed in a lot of environments).
> http://www.google.com/search?q=SuppressWarnings+5.0u6 Thanks. I've been tracking 4986256; too bad they didn't put 2125378 in as a related bug.
 Signature ======================================================================== Ian Pilcher i.pilcher@comcast.net ========================================================================
TechBookReport - 31 Oct 2005 12:01 GMT > On Fri, 28 Oct 2005 19:11:49 +0100, Thomas Hawtin > <usenet@tackline.plus.com> wrote, quoted or indirectly quoted someone [quoted text clipped - 8 lines] > > It is a implementation driven syntax. Yep.
 Signature TechBookReport Java book reviews http://www.techbookreport.com/JavaIndex.html
TechBookReport - 31 Oct 2005 12:01 GMT >> Does anybody have a good word to say about generics in J2SE 5.0? > > It appears that most of those spouting off about the evilness of > generics are dynamic typing fans. If you don't like static typing, then > you aren't going to want more of it. If you do like static typing, it > might as well be done properly. If I was a dynamic typing fan I wouldn't be using Java at all. There are times when a quick and dirty hack is what you need and dynamic typing makes that easier. But to be honest even my one-off bits of code end up being Java, as it is for most Java developers I imagine. So, my comments are nothing to do with being against strong typing or static typing.
>> I >> can't help thinking it's a sledgehammer to crack a nut. Casting into [quoted text clipped - 3 lines] > unnecessary code and the source is complicated precisely where you want > it as simple as possible. But now you've moved the complication elsewhere.
> It's not a valid criticism coming at it from a dynamic typing point of > view, anyway. You can't, as I understand it, take a Smalltalk collection > and ask what shapes will all its contents, past and future, will conform > to. See previous - this is not about dynamic vs static typing.
> The real issue, assuming you welcome static typing into your life, is > documentation. It's much easier to understand what is in Set<EmployeeID> > than Set with the element type hidden amongst the JavaDocs if at all and > if kept in sync. But this can be solved using documentation and/or smarter tools.
 Signature TechBookReport Java book reviews http://www.techbookreport.com/JavaIndex.html
Tor Iver Wilhelmsen - 29 Oct 2005 19:29 GMT > Does anybody have a good word to say about generics in J2SE 5.0? They allow even more errors to be caught at compile time.
> Casting into and out of collections wasn't such a big deal. Nor is catching Exception instead of specific exceptions. But it's still bad practice compared to the alternative.
> Sure type-safety is important, but the implementation is intrusive > and ugly (aesthetics seem important to me). No, it doesn't, otherwise you would be using a good-looking language like Eiffel or Smalltalk instead of *any* member of the fugly C family.
> If anything surely the class cast problem is something that > intelligent tools like Eclipse or NetBeans could have solved without > resorting to language changes. You want to make IDE-dependent languages? I thought that idea died with Smalltalk?
> Particularly as erasure means that it's only at compile time that > generics provide a benefit. And that is good enough reason to have it.
TechBookReport - 31 Oct 2005 11:47 GMT >>Does anybody have a good word to say about generics in J2SE 5.0? > > They allow even more errors to be caught at compile time. But at what cost? It seems to me that the additional complexity in the language is a high price to pay.
>>Casting into and out of collections wasn't such a big deal. > > Nor is catching Exception instead of specific exceptions. But it's > still bad practice compared to the alternative. There's a difference between those. In the first place before generics there was no alternative to casting objects into and out of collections. It wasn't a bad practice, it was how things worked. This is not the same as catching Exception instead of a specific exception - in this case it really is a practice.
>>Sure type-safety is important, but the implementation is intrusive >>and ugly (aesthetics seem important to me). > > No, it doesn't, otherwise you would be using a good-looking language > like Eiffel or Smalltalk instead of *any* member of the fugly C > family. Not true. I think that Java has a relatively stripped down and sparse syntax that makes it easy to read clean, maintainable and readable code.
>>If anything surely the class cast problem is something that >>intelligent tools like Eclipse or NetBeans could have solved without >>resorting to language changes. > > You want to make IDE-dependent languages? I thought that idea died > with Smalltalk? No, I wasn't suggesting that at all. I was suggesting that if the classcast problem was so significant than added intelligence in some of the IDEs might have helped crack the problem. Leaving it with tools and not in the language means that those people who want a solution can seek out an appropriate tool, for everybody else the language is not encumbered with additional syntax.
 Signature TechBookReport Java book reviews http://www.techbookreport.com/JavaIndex.html
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|