- the "do it over and over again" retoric is not entirely correct. The concrete implementations of the iterator has to be implemented over and over, but not the Iterator interface itself. In fact, in the Java standard library, there's only one universal Iterator interface.
- If the only stuff that has to be done over and over again is the iterator implementations, this is not any different in dynamic languages
- The Gof does mention very specifically the different kinds of iterator patterns, in particular:
- external iterator - where the client of the iterator controls the iteration(generally how it's done in Java, C++ and python)
- internal iteration - where the client passes the iterator a code block, or closure, and the iterator controls the iteration(smalltalk, ruby)
- Some languages have iterators built right into the language(python, ruby)
- external iterator - where the client of the iterator controls the iteration(generally how it's done in Java, C++ and python)
- Although the code samples were in C++ only, Gof did give examples for both external and internal iterators, although internal iterators in C++ still suck, so it wasn't a good example(they used a template method pattern to do it, which is not very generic)
What does this all mean? People, if you have the Gof book, read it! Really read it, before you really go attacking it. I mean to say something about Christopher Alexander, but will leave it for a later post.
Update: However, I do agree with the point that much of what the book covers is how to implement the patterns in C++, which is much cluggier than in many dynamic languages. But there's a reason for this: some people just don't have a choice to which the language they use. This was more so in the 90s when C/C++ was the fastest platform but is still the case today where Java dominates the enterprise.
