Java

Bryan Sant bryan.sant at gmail.com
Tue Feb 13 12:22:49 MST 2007


On 2/13/07, Jacob Fugal <lukfugl at gmail.com> wrote:
> It is an issue. In my experience, time spent writing code is a
> negligible amount of time I spend developing. A far greater amount of
> time is spent grokking existing code and thinking about the issues the
> code I'm going to write has to address. When I argue against
> verboseness in a language, I'm not complaining about the effort I must
> spend to write all the boilerplate, but the semantic noise that it
> adds.
>
> Ignoring concepts of language "beauty", if I'm writing an iteration
> over a collection, my options with and without foreach are:
>
>   /* without foreach: */
>   for(Iterator iter = collection.iterator(); collection.hasNext();) {
>       MyObject obj = (MyObject)iter.next();
>       /* ... do stuff with obj ... */
>   }
>
>   /* with foreach: */
>   for (MyObject obj : collection) {
>       /* ... do stuff with obj ... */
>   }
>
> The foreach version stays out of my way not just when I'm writing that
> code, but also when I read it. The IDE can help me enter both versions
> just as quickly, but the IDE has no way of helping me reduce the
> semantic noise in the first example. That is why it's an issue.
>
> Jacob Fugal

Good point.  I agree.  The readability is far improved with foreach.



More information about the PLUG mailing list