And so it goes, around again.

by Charles Miller on September 2, 2009

Back in 2002, I wrote the following about the proposal for an ‘enhanced for loop’ in Java 1.5.

Foreach takes probably the most common use of Smalltalk blocks, the internal iterator, and creates a syntactic special-case for them. Once again, it's a band-aid solution. Foreach removes the annoying duplicated syntax for the simplest case, but it does nothing to give programmers the chance to remove duplication on the more complex cases.

So it seems now for Java 7, closures having been dropped from the roadmap, it's time to apply the next band-aid. This time the recipient is the next in the line of usual suspects, resource management:

Absent a language change, you must close resources manually. That is why Java’s competitors have automatic resource management constructs (C# has using blocks and C++ has destructors).

Back to me from seven years ago:

Once foreach is implemented, the precedent has been set: whenever the lack of [closures] causes us to lag behind C#, don't fix the underlying problem, work around it with a variant on what we have already.

The funniest part, of course, is that C# 3.0 has had closures (or at least succinct lambda expressions with type inference) since 2007.

Previously: Self-LART

Next: The Aliens Have Landed