On 6 Jan 2011 17:33, "Cédric Beust ♔" <[email protected]> wrote:
>
>
>
> On Thu, Jan 6, 2011 at 3:47 AM, Carl Jokl <[email protected]> wrote:
>>
>> One item which I have heard mention recently is that the for loop
>> syntax is potentially harmful to teach because the for loop with an
>> index is inherently only processable with a single thread vs the
>> foreach loop which can potentially use parallel processing.
>
>
> This seems wrong. Just because the loop seems to be parallelizable doesn't
mean it is. The compiler needs to know whether your iteration is ordering
sensitive or not ("Is it okay if index 3 is treated before index 1?"). This
hint is much more meaningful than whether the developer is using an index of
foreach. The same applies to closures, LINQ or whatever comprehension
walking mechanism you favor.

If you have referential integrity (the same function, with the same input
always returns the same value, immutability is important here) and the
functions have no side-effects (e.g println) then it's mathematically
guaranteed that ordering won't matter.  You can still have indices, they
just don't need to be processed in-order.

For that matter, they needn't be on the same thread, processor or even
computer!

This is the very essence of why so many are now advocating functional
programming as such a good fit for concurrency.

>
> --
> Cédric
>
>
>
> --
> 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]<javaposse%[email protected]>
.
> For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en.

-- 
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