Inappropriate sarcasm

Dear modern C++. It’s okay. We like you. You don’t have to pretend you’re something you’re not.

Herb Sutter just gave an excellent talk on modern C++, but I thought one part was more than a little silly. At about the 10 minute mark, he showed an example (originally due to Bjarne Stroustrup) calculating the mean in Python and C++14. Before revealing the code, he sarcastically said that maybe he didn’t leave enough space on the right hand side because it will be so much longer and harder in C++. Then we see that the C++14 is line-for-line the same as how you would write it in Python. Har har.

screen cap of Python and C++14 side by side

The thing is, that isn’t how you would write it in Python. If you weren’t Bjarne Stroustrup, you would write

def mean(seq):
    return sum(seq)/len(seq)

Heck, if you’re using Python 3.4, you would just write

from statistics import mean

Showing that C++ is every bit as expressive as non-idiomatic Python doesn’t really show anything.

Inappropriate sarcasm