I'm a Python2 developer and I just ordered The C++ programming language, 4th edition, from Bjarne Stroustrup's, to learn C++11. But right after I ordered it, I started to wonder if I made a mistake. Are the changes made to C++ in C++11 analogous to how Python moved from 2 to 3 insofar as code significantly breaking and not being backwards compatible? Or is learning C++11 safe to do?
If I coded C++11 in XCode, the latest version being whatever it is, would it work on say a Windows machine? Or does that depend more on what will compile the code, fairly certain that XCode uses LLVM.
-
Breaking changes in C++11 and C++11 compiler support (yes, that's entirely up to the compiler and standard library implementation).– MatCommented May 22, 2013 at 17:10
-
2C++11 is largely backward compatible. Of course, it is still to be seen if developers are going to adopt the new features or not. A big part of the Python community is still using Python 2.– GiorgioCommented May 22, 2013 at 17:12
2 Answers
C++11 is both more and less disruptive than Python 3000.
It is less disruptive since it contains fewer breaking changes and those breaking changes are rarely encountered.
It is more disruptive in that it will pretty significantly change the way code is written and systems are designed in C++. Programs in Python 3 are mostly written the same way they were in Python 2. The breaking changes are mostly cleanup, like getting rid of old-style classes. C++11 OTOH contains some features that can quite drastically change the way you write code: for example, the combination of a memory model, standard library concurrency primitives, lambda literals and type inference allow for syntactically and conceptually lightweight high-level concurrency in the style of Clojure or Haskell.
-
+1: I agree that the changes in C++ are quite disruptive. I wouldn't have been surprised if they had chosen a new name for the language. It will be interesting to see how the C++ community reacts to this new language.– GiorgioCommented May 23, 2013 at 10:56
-
3
There are certain features from C++98/03 that are deprecated, such as auto_ptr, the 'register' keyword, etc. But for the most part if your code compiled under C++98 it will be fine for C++11. The only breaking changes are the new keywords (and the re-using of the auto keyword.) So, unless you wrote C++98 code that used statements like
auto int x = 5; // auto means "on the stack"
or used the keywords 'decltype' or 'nullptr', etc. as variable names, your code should be fine under C++11.
EDIT: As mentioned there are more breaking changes, but they won't trip up the average C++98 code base. I remember hearing a story about how they chose the keyword 'auto' for type deduction (can't vouch for it being true): they did a count of every time the keyword appeared in many large code bases and determined that the C 'auto' keyword went basically unused. Case in point: they take backwards compatibility very seriously.
-
Thank you. Just to clarify my position some more, when I started learning python, people told me to learn 2 rather than 3. But basically in this case it seems like its okay to learn C++11.– c-o-dCommented May 22, 2013 at 17:13
-
2
-
I've heard that same story of them spending a lot of time looking and only finding a handful of valid uses of
auto
. I can't help but feel it came from the mouth of Bjarne Stroustrup. --- Yeah, that's where I remember it from. "Several committee members trawled through millions of lines of code finding only a handful of uses -- and most of those were in test suites or appeared to be bugs."– chrisCommented May 23, 2013 at 5:09