Skip to main content

what have they done with Java?

57 replies [Last post]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dog
Offline
Joined: 2003-08-22

Arguments against generics:
- provides little benefit, adds complexity (cost >> benefit)
- ugly, subject to abuse (see C++)
- promotes exposure of complex collections instead of properly encapsulated objects
- promotes "generic programming" style which is a departure from Java's OO roots
- God, I hope they don't use it EVERYWHERE!!
- Smalltalkers didn't need no stinking generics

Arguments for generics:
- provides type-safety and reduces dangerous casting
- provides "documentation" (enforced documentation) of what you can expect to find inside a collection thus making code more maintanable
- provides idioms that are impossible to express as concisely without them
- real programmers aren't afraid of generics, they are the one thing that will "complete" Java
- C# will have them, we need to get an upper hand

But the single best argument FOR GENERICS is:
- it's a dead horse, the cat is out of the bag, live with it or leave!

Being on the losing side is hard.. but we have to concede defeat..

(disclosure: I'm not a generics fan.. it was one reason I abandoned C++ and embraced Java)

pholser
Offline
Joined: 2003-07-24

> Arguments against generics:
> - promotes exposure of complex collections instead of
> properly encapsulated objects

how so?

how would leaving generics out discourage such exposure?

kcpeppe
Offline
Joined: 2003-06-15

>
> how would leaving generics out discourage such
> exposure?

Leaving generics out of the spec does not discournage one from exposing collections in an API, only education does! What would say is that generics are a crutch for those that would incorrectly expose a raw collection and thus subjucate it to abuse. In this way, generics promotes this style in a mis-guided quest to obtain complete type safety.

You cannot control how people will use the language but what you can do is influence their choices. Generics create an influence that IMHO, works against good design practices.

There was an interesting book written by Dave Thomas (http://c2.com/cgi/wiki?DaveThomas) called, Smalltalk with Style. Even though the book was written for Smalltalk, there are a number of style features that do apply to Java because they go beyond language and more into what good OO code should look like. One of the style guidelines is that a method should never be more than what you can see on the screen. The reason that this guideline works in any language is because smaller methods tend to be useful in a larger number of situations. So instead of procedurally hacking in everything that needs to be done in a few methods, if you should find the core abstractions and then allow the larger pieces of functionality navigate through the more primitice methods (not unlike a workflow). The economies of generics quite simply work against this principle. In other words, If I code small methods, my code bulk will actually increase. The suggestion is that I should write longer methods. If I write longer methods, I'll most likey have to write more methods that are also longer.

One of the points of my 55K line to ~8k line refactoring that I didn't bring out is that aside from missing some key abstractions was the repeated use of "logic" in large methods that could not be reused. repackaging that logic into smaller methods allowed us to reuse that logic (we could observe DRY where as before, we were not able to).

It is for this reason alone that I will continue to argue against using generics. Type safety is not an issue for me. Yeah, it's pain if someone doesn't understand that collections should really be homogenous or if they exposed a collection and didn't document the expected type. but a far larger problem is the promotion of coding practices that add to bad design and bloat. IMHO, generics fall into this class of features.

patrikbeno
Offline
Joined: 2004-10-11

Sorry but I have to say you just don't understand why any of the mentioned features are useful. And that does not make them bad.
Right now don't have any resources to explain it all here :-( But I just suggest you invest some time into investigating why those features were introduced.

- assert is at least better because it is shorter and can be can turned off. But you have to use it properly that's all.
- generics: http://forums.java.net/jive/post!reply.jspa?messageID=3945#3945
- metadata are intended to be used for something completely different that your example

But everything can be misused. Kitchen knife can be used as a weapon but it does not make it a bad thing.

Howgh

saintjohn
Offline
Joined: 2004-10-25

> Sorry but I have to say you just don't understand why
> any of the mentioned features are useful. And that
> does not make them bad.

Sorry, but i understand why any of the mentioned features are useful (especially for former C++ programmers).
But, IMHO, these doubtful advantages don't excuse such significant changes of java language specification.
E.g., Enumerations can be easily implemented without j2se1.5 changes. See, for example Bloch's "Effective java programming".

IMHO, to j2se1.5, a russian proverb can be applied:
"By good intentions, the way to hell is cobbled"

patrikbeno
Offline
Joined: 2004-10-11

[i]> Enumerations can be easily implemented without j2se1.5 changes. See, for example Bloch's "Effective java programming". [/i]

well now you hit it :-) because Bloch's type safe enumeration pattern is the very thing that lead to introducing Java 5 enumerations.

And I am happy for that.

monika_krug
Offline
Joined: 2004-10-14

> - introduction of generics is caused by some
> far-fetched reasons. They absolutely don't outweight
> one major drawback - java code becomes
> hard-to-read.

Particularly in connection with Collections, generics make Java code a lot easier to read.

Monika.