Hacker News new | past | comments | ask | show | jobs | submit login

If you are familiar with both C++ and common high-order functions used in functional programming I still think that squareVec4 is, by leaps and bounds, the most readable.

squareVec4 is simple, concise, and leaves little to no room for ambiguity. squareVec6 is a monstrosity that requires reading more text that contains more complicated ascii and involves more concepts.

And for the author to then claim that making use of "cool stuff" in <algorithm> is more maintainable code? That's just crazy talk man!




Isn't this an artifact of C++ rather than a general truth, though? If you could just invoke something like:

   return v.fold([], def (acc, i) { acc.push(i*i) });
Or better:

   return v.map(def(i) { i * i })
Something like 'map' in this case is much more appropriate, since it's operation on a collection which returns a new collection with a given operation applied on each element.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: