Related Entries

Remove duplicate jars
Simple MongoDB+Java example
Lightweight JSP development environments
jEdit with jGoodies
Jython is great

« Semi-connected computing
» Quick links

Readable Java 1.5

I still think the proposed version of for loop is not readable enough.

“ The Java 1.5 proposal offers programmers a false choice between desirable new features and readability. In fact, all of the proposed new features for 1.5 can be represented by clear, unambiguous, and readable constructs without breaking backwards compatibility.”

As far as for-loops are concerned, I think Guido’s choice of syntax for Python is the best I’ve seen in any language.

for object in sequence: do_something(object)

For satisfying the urges of C programmers to write

for(i=0;i<x;i++)
Python uses a much better function, range(start, end, step) so that one can write the loop like
for i in range(x):

For iterating over a collection, no funky iterators are required, since collections are sequences.

According to the O'Reilly article, the proposed new format for Java is:

for(Object o: collection){}
The author proposes a variation like:
for (Object o = eachof collection)
I think his proposal is much better than the colon. Sun’s proposal is not explicit enough. Note: Equivalent of class A extends B implements C in C# is class A:B, C - I don’t like this either for the same reason. Explicit is better than implicit. Personally, I’d prefer:
 for(Object o in collection)
but I suppose that will break existing code.

While on the subject of readability, here is a recommended bookmark: Integrating Struts, Tiles, and JavaServer Faces.

  1. You've left out the c#:

    foreach(Type t in TypeCollection)

    And the c# (and possibly c) syntax for(x=0; x<10; x++) isn't just a sequence, it is really a while loop in disguise...

    for(initial statement; while condition; statement each pass)

    Posted by: David Kearns on September 25, 2003 07:22 PM
  2. Sadly, it's way, way too late to do anything about it. On my reading of the situation, the loop syntax was pretty much set in stone a year a go.

    The only way out is to toss Java and go program in Python :)

    Posted by: Alan Green on September 26, 2003 12:26 AM
//-->