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

It's even a poor example of C++. Using valarray, you end up with basically the same thing as your above examples:

    #include <valarray>
    #include <iostream>
    
    double standard_dev(const std::valarray<double> &vals)
    {
    	return sqrt(pow(vals - (vals.sum() / vals.size()), 2).sum() / vals.size());
    }
    
    int main()
    {
    	std::cout << standard_dev({2, 4, 4, 4, 5, 5, 7, 8}) << '\n';
    }
…and none of those are really much less readable than the math version. All in all, that "example" clearly wasn't made in good faith, and left a bad taste in my mouth.



Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: