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.

If only std algorithms took containers (by that I mean things that container for accepts too) as arguments (and not iterators)... even in the form of new functions like foreach_all, transform_all etc.

Reply via email to