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

advertisement

AddThis Social Bookmark Button
Article:
  Readable Java 1.5
Subject:   Re: eachof
Date:   2003-10-01 03:57:29
From:   anonymous2
Response to: Re: eachof

I struggle to swallow suns argument relating to the foreach keyword.
Surely the loop syntax and method call syntax are significantly different as well as the context they are used in to allow existing code to live on.
foreach() {...} and foreach(arg1,arg2);


And to the "programmers" out there that thought it was a good idea to create a method called "foreach" in their source(apart from the obvious question why did you not call it forEach) didn't anyone tell you in programming 101 that mimicing your favorite(and usually previous) language was always the road to pains-ville.



So I'll go along the foreach route and invent the "in" keyword for good measure
imagine if you will, a world...


foreach ( String name in nameCollection ) {
System.out.println( name.length() );
}


Its java-tasic clean and intuitive, all as you'd expect in java world.


And since this is my world I'd like to invent the following extra variable magic: "next" and "previous" also magically the correct types or null if your at either end of the collection.


Sometimes you just have to take a hit on backwards compatibility and stop trying to be all things to all men.


The article was very interesting and the eachof operator along with its bonus syntax is worth having anyday. To me using "eachof" or "in" makes no difference as long as it fits java world intuitiveness-ness and requires little thought.


Don't be mistaken into thinking I'm against cryptic :'s in my code. I'm heavily in to perl and theres nothing I like more than a liberal sprinkling of ->'s and :: but that is a different world and has no place here...