ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Readable Java 1.5
Subject:   eachof
Date:   2003-09-27 19:46:50
From:   anonymous2
I find the eachof syntax quite readable. It resembles a type declaration as used in mathematics. And it is a natural fit - Decl x : y means that the values of x will range over the values in the collection b. This therefore works kind of like a universal quantifier.


On the other hand, the proposed eachof syntax is less clear. When I see a statement like int x = eachof y, then the next question to ask is what happens if I do this int x = eachof y + eachof y? See, the problem is that the "eachof y" really forces a specific kind of execution - it has to work like a queue where values are read off it - something that will require more careful consideration of the particular runtime behavior of the JVM. On the other hand, the Decl x : y syntax is more declarative in nature. There's fewer "gotchas", the scope of the eachof statement and the region of code to be iterated is clearly bounded. (It was suggested that it should simply bind the the nearest loop, in the same way as continue and break, but then we might also have the question of "what if we don't want to attach to the innermost loop?" - surely, to be consistent, the syntax should support eachofs that refer to a label - and, finally, it isn't clear what behavior is desirable when the size of d and e (in your example) are not of equal length - whatever is chosen will simply lead to confusion among users.



1 to 1 of 1
  1. Re: eachof
    2003-09-28 09:58:29  sjungels [View]

1 to 1 of 1