On Friday, 20 September 2013 at 08:59:44 UTC, Peter Alexander
wrote:
On Friday, 20 September 2013 at 02:24:31 UTC, bearophile wrote:
At Going Native 2013 there was a very good talk that among
other things suggests to avoid raw loops in C++ code. But
while this is good advice (so much that raw loops are becoming
a bit of code smell for me), there are several situations
where imperative loops keep being better for me. Explicit
recursion is not always more readable and more easy to
understand than imperative foreach loops.
I don't think his advice is to use recursion instead of loops.
I believe the point was that raw loops can usually be replaced
by something more generic (e.g. std::find, std::rotate,
std::transform, etc.). The loop is just an implementation
detail of a more high-level algorithm. Within those algorithms,
it's ok to use loops.
While at the university, I got to read a paper about a HPC
computer architecture with NUMA, that used Lisp as their systems
programming language.
The functional programming approach was the only way to really
take proper advantage of the hardware specific architecture.
This is why it is better to use algorithms instead of explicit
loops, as they can be made to scale.
--
Paulo