Bartosz Milewski seems to like D more than C++ now :)
bearophile
bearophileHUGS at lycos.com
Fri Sep 20 02:36:48 PDT 2013
Peter Alexander:
> 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.
In my comment I have packed too much in too little space. Let me
try again:
In Haskell you usually don't use explicit recursion. You usually
use higher order functions. But once in a while, for performance,
to implement those HOFs or for other reasons you use explicit
recursion.
In that Going Native 2013 talk it was argued that in C++ it's
usually better to use STL algorithms instead of raw loops. But
sometimes you have to use raw loops, when you implement those
algorithms, and in other situations.
In D it's often better to use std.algorithm/range instead of raw
foreach loops (despite probably unlike C++ in D a heavy use of
ranges leads to a lower performance, even if you use the LDC2
compiler).
So in Haskell, C++ and D it's better to use higher iteration
abstractions instead of raw recursion/iteration, but once in a
while you have to use it. From what I've seen so far, in those
cases I prefer to use explicit foreach iteration in D instead of
explicit recursion in Haskell.
Bye,
bearophile
More information about the Digitalmars-d
mailing list