I felt like things got mixed up quite a bit in that particular
segment, and resulted in a bold and not fully qualified statement "For
considered harmful". Fact: Sometimes you need the index of a list,
sometimes you rely on order/relation/side-effects within a list and
sometimes you just have a crapload of unrelated items to process which
then of course lends itself to parallelization.

We've all learned that we should avoid polluting scope with temporary
variables and exposed state, which is why we should favor iterators
over indexing. However, there are a great deal of times where we need
the index either directly or indirectly when i.e. operating of
multiple aligned structures, treating the first item specially, or the
last, etc.

Also, let's not do parallelization just for the sake of
parallelization. Lots of iterator blocks make no practical sense to
spend energy on trying to parallelize, either because the input size
is statically defined to be small, or because the complexity makes it
a piece of cake for a modern CPU (< O(n^2) problems) leaving I/O being
a much larger bottleneck. Thus, I think it is much more important to
teach the use of the surrounding library (algorithms and data
structures), than to naively aim to avoid the for loop.

In C#,thanks to closures, if you determine your for loop has no side-
effects and needs to go faster, you just use Parallel.For(...) instead
and the runtime will take care of the rest. That's simple and easy,
all you need to understand is whether your loop body lends itself to
parallelization since this is obviously outside the ability of the
compiler* to magically infer.

*Here we're talking mainstream imperative Java/C#, not Haskell/ML/
Clojure/Scala or other experimental languages, AFAIK this is still
called The Java Posse.

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to