News for hackers. Stuff that matters.
Re:Toward a better programming by jeorgun on Friday March 28, 2014 @06:35PM (#7490394)
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.

There are no comments on this comment yet.