3 ms·
I'm not sure why this comment thread is so awful. It's as if veteran C++ devs are scared of Haskell or something. Lazy evaluation is a great boon for achieving
by chipsy 13y ago
I'm not sure why this comment thread is so awful. It's as if veteran C++ devs are scared of Haskell or something. Lazy evaluation is a great boon for achieving a mix of performance and flexible coupling.
In a lot of simpler, lower-performance cases you _can_ get away with just evaluating the same function with the same inputs repetitively, which doesn't require these tools, but having the "next step" available makes it possible to apply that strategy in more places.
- jzwinck 13y agoNot scared of Haskell, just we have other ways to do stuff like this in C++, namely iterators. I posted a solution using iterators here: https://news.ycombinator.com/item?id=7626984 https://news.ycombinator.com/item?id=7626984 My solution completely avoids dynamic memory allocation--even the stack allocation is just a handful of bytes per generated triple. You're right that lazy evaluation is useful for performance, but TFA acknowledges that its own implementation is not efficient because it dynamically allocates memory repeatedly. This is not something we can hand-wave away: it's at the core (no pun intended) of high performance in C++ and many other languages.
- mmaldacker 13y agoYou are right, but computing the first n Pythagorean triples is a terrible example to show lazy evaluation.