Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One thing I don't get is why do people prefer functions like accumulate? Why not:

    int sum = 0;
    for(auto&& wc : word_count) sum += wc.second
    return sum;
It's shorter, more general, more familiar, possibly has better performance[[citation needed]], and gives better errors if you mess something up.


Its more composable, and because its less general, it more clearly articulates intent and iis easier to scan for bugs.

Or at least it would in an ecosystem where functional programming is embraced, but I don't know how practical it is in practice. Its not composable if you can't expect any other given piece of code to be written in a way conducive to composing with accumulate.


In C++? No idea - I think C++ just has an inferiority complex and wants to look cool.

In other languages, though, it's pretty neat. For example, in Rust one just does

    data.iter().fold(0, |s, e| s + e)


functional programming hype




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

Search: