Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.


JavaWorld Talkback >> 959023

Pages: 1
Daniel Barbalace
Unregistered




How generics could have been more readable
      #16138 - 03/10/05 02:42 PM

It's unfortunate that Sun was too afraid of adding new reseved words to the language. Generics could have been made

much more readable by introducing two keywords: "of" and "isa". Now any programmer that is using "of" as a keyword

deserves to get burt for being foolish enough to use a predaticate to stand for an object (noun). Perhaps some

people have used "isa" as an identifier that is also an acronym for something. But those people can choose to either

stay at 1.4 or use the "search-and-replace" utility built in every single IDE and text editor to replace "isa" with

"myIsa". This could even been done recursively on a directory with a simple Java application or a script.

If we had "of" and "isa" reserve words, things become much clearer. We can replace awkward looking code as follows:


Instead of
Vector <Dog> dogs = new Vector<Dog>();
say
Vector of Dog dogs = new Vector of Dog();

Instead of
Vector <? extends Mammal> pets = dogs;
say
Vector of Mammal pets = dogs;
and know that this is valid because a Vector of Dog is a Vector of Mammal (since Dog extends Mammal)

Instead of
class Mammals <T extends Mammal>
{
private Vector<T> items = new Vector<T>();
void add(T item)
...
}
say
T isa Mammal; // T has file scope. Maybe it would be better to change T to AnyMammal
class Mammals
{

private Vector of T items = new Vector of T();
void add(T item)
...
}

Instead of
class Mammals<E extends Mammal> extends Vector<E>
{
}
say
E isa Mammal; // E has file scope. Maybe it would be better to change T to AnyMammal
class Mammals extends Vector of E
{
}

Currently, Java does not have a file scope. However, letting a template name have scope of the local file (or

stream, if you are reading a class from a socket, database, etc.) is perfectly ok because the template name should

never, ever be used outstide the file. Therefore, there is need for a namespace either.


Post Extras: Print Post   Remind Me!   Notify Moderator  
cyborg
Unregistered




Re: How generics could have been more readable [Re: Daniel Barbalace]
      #35132 - 08/08/06 09:06 AM

That would be the Pascal style of doing things but Java is very much into the C style. Guess what syntax the generics is based off? Yes, it's the C++ style angle brackets. Sun don't want to scare off those C++ developers from Java by using verbose words rather than symbols!

Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 1 anonymous users are browsing this forum.

Moderator:   

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 3678

Rate this topic

Jump to

Contact us JavaWorld

Powered by UBB.threads™ 6.5.5