Hear us Roar
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.
|
Showing messages 1 through 1 of 1.
-
Re: eachof
2003-09-28 09:58:29
sjungels
[View]
|
| |
Programmer's are more likely to have seen the ":" used in basic set theory, for example,
S = { x : 0 < x <= 1},
<br>
where ":" is pronounced "such that." This could have been the basis for a nice collections iterator, for example
for (String x : x elementof C)
where C is a collection. But the Java 1.5 proposal doesn't do it that way, and the colon character by itself is still cryptic, as I argued in the article.
The issues you raise in the second paragraph apply only to the extended version of "eachof" which I should have more clearly stated was a "bonus." A simple eachof designed as a drop-in replacement for the "for :" syntax would not raise any semantic issues different than "for :".
Thanks for an interesting post.