C++ Has Become More Pythonic—Jeff Preshing

Save to:
Instapaper Pocket Readability

A nice article pointing out similarities between modern C++ and Python:

C++ Has Become More Pythonic

by Jeff Preshing

From the article:

C++ has changed a lot in recent years. The last two revisions, C++11 and C++14, introduce so many new features that, in the words of Bjarne Stroustrup, “It feels like a new language.”

It’s true. Modern C++ lends itself to a whole new style of programming – and you can’t help but feel Python’s influence on this new style. Ranged-based for loops, type deduction, vector and map initializers, lambda expressions. The more you explore modern C++, the more you find Python’s fingerprints all over it.

Was Python a direct influence on modern C++? Or did Python simply adopt a few common idioms before C++ got around to it? You be the judge...

Add a Comment

You must sign in or register to add a comment.

Comments (3)

0 0

Sektor said on Dec 3, 2014 08:45 AM:

Come on. Give me a break. Python influence, ha ha ha.

Binary literals: this has been requested (suggested - maybe not loud enough), AFAIR, since 1996 year.

Range-based for loops: scripting languages like Perl or Tcl had them before the first thought of Python language has appeared.

Auto: type inference has been a long time ago, for example, in ML

Tuples: idem

Uniform initialization: the examples for Python given here can be also found in a variety of languages, not only scripting ones, also long time before anyone heard about Python

Lambda expressions: Python has supported lambda functions since 1994. Yes, and Lisp supported them since 1960 (IIANM).

Variable arguments: This has been supported various (also limited or clumsy) way in various ways (including C). Although again, Tcl was one of languages where this was solved decent way, long before Python came to existence.

Conclusions:
1. Congratulate yourself for a successful spawning a new flame war.
2. This article isn't funny nor inspiring.

Serious conclusions:

From my point of view, C++ has been just completed with the things that have been lacking since a long time, was requested by software developers, and these solutions have been already tried and tested in other languages, so they are considered good and useful, and additionally possible to implement within the syntax rules of C++. I'm glad to see that adding features to C++ has a little bit hastened since 1998 year, however this had a lot to do with compiler vendors (I'd see 2006 year as the first year when "almost 100% compliant" C++98 compilers were available - whereas C++11 compliant compilers were available next year after the standard was completed).

But among all the mentioned things there's neither one that can be characteristic to Python or Python-specific. Everything has been there long before.

Anyway, so far I know only two things in Python language that are Python-specific: the syntax relying on indents, and the most stupid multiple inheritance implementation in the world.
0 0

Herb Sutter said on Dec 3, 2014 09:59 PM:

Many languages steal -- directly from each other and/or from a common ancestor. smile Who borrowed from whom is less interesting to me than the demonstration of how modern languages are converging.

I rather like Jeff's article as useful on several dimensions -- as a refresher on modern C++ language features that older C++ developers are still getting used to, as a highlights reel of the particular points of convergence in C++ and Python, and as a demonstration of how well modern C++ now stacks up side-by-side in usability with other modern languages. Bjarne also lately has been showing slides with equivalent code side by side in modern C++ and modern Python and how it's often one-to-one. I find this convergence quite interesting, and in some cases unexpected.
0 0

Sektor said on Dec 5, 2014 07:44 AM:

Of course many languages "steal", although I rather prefer to say that they get inspired and follow good examples.

I just don't like stating the matter this way that C++ is becoming "more Pythonic" (even if Bjarne himself says that smile ). If this was to show how useful C++ is because of these new features, as compared to some other languages (also Python), it could have been done with a cross-language comparison. Using only Python makes a suggestion that C++ somehow "feels worse" than Python.

While these new features are not "Pythonic" - they are simply USEFUL. They don't make C++ "more Pythonic". They make Python less making sense of leveraging C++ in some tasks.

(Also, I'm not hiding that I'm not a fan of this language, and I'd welcome someone who would invent a language, let's call it "Vyper", which will just change the intentation-based syntax into brace-based one :D )