My-Gate • Blog » 2012 » März

C++11 is a new language

Dieser Beitrag ist auf Englisch verfasst, da es mir leichter fällt über das Thema zu schreiben.

c  11Now it’s again already some time since the new C++ standard got officially released then again many new features are not new at all. A few things got already introduced with the Technical Report 1 (TR1) from back in 2007 but it wasn’t directly built into the standard. In some way you could call the TR1 the alpha version of C++11. Then there is boost, the most popular non-standard library of which many ideas got copied and standardized.

But let us first back up a bit and look at a short timeline:

  • 1979 – Bjarne Stroustrup began working on C with Classes.
  • 1983 – The name of C with Classes got changed to C++ where the ++ represents the increment operator on C.
  • 1985 – The first commercial release happened and a few small iterations followed.
  • 1998 – The C++ standard committee published the first official ISO standard for C++.
  • 2003 – After five years of getting experienced with C++ the committee released a corrected version of the old standard.
  • 2005 – Getting closer to a completely new standard the committee pushed out the Technical Report 1 which wasn’t directly part of the standard but showed already features which happen to be in the standard now.
  • 2011 – Some might have already given up but the new standard then got finally release and that with a lot of new features.
  • 2012 – People working on compilers now, are trying to catch up with the new standard.

This timeline shows that C++ advances very slowly. For developer wanting portability and lot of different features it’s annoying but the same developer will then be glad, C++ doesn’t change quickly and guarantees stability and speed. Who would want to rewrite thousand lines of code just because the standard did change? Also how would you be able to catch up with all the changes?
The long time between the two C++ standards, which is 14 years for the ‚flawed‘ version and 7 years for the corrected one, let the committee and all the people around the world think about what C++ does and what’s missing and over the years, technology evolved too. Stuff like parallelization which wasn’t a big topic 14 years ago but look at it nowadays, it’s about the most important one, since we hit the wall where processors can’t get faster and we have to divide the work onto multiple processors and conquer our tasks.

So you get it – C++11 is great but what is so great about it?
There is a good maintained list over at Wikipedia, so I won’t go much into anything here, but let me just highlight from my naive perspective the most important change.
Whenever you talk about C++ with other developers who don’t use C++ they’ll often start joking about C++’s Access Violation and Memory Leaks and they are not that wrong. They are common errors with C++ but many of those could be prevented by disallowing certain things or by using garbage collectors. Then again when you look at the ‚philosophy‘ behind C or C++ you notice that they never were about restricting things. Specially not for a reason like: ‚The programmers nowadays are just so dumb and can only write messy code, so let’s restrict everything so one can only do what we think is best for them.‘ No C++ is about unlimited freedom and possibilities. But how can the obvious problems with false memory management and overused pointers be solved?
The new standard introduces with its Standard Template Library (STL) smart pointers. Whenever you allocate some memory on your own, you have to delete it at some point again, if you forget to do so or if a function throws an exception or returns before it reaches the delete statement, the memory won’t get freed. shared_ptr and unique_ptr got solve these problems. They automatically delete the object once the smart pointer object reaches its destructor hence gets destroyed. Additionally with the use of smart pointers over normal pointers you won’t run into the problem of a wild pointer, they either holds a valid object or are set to nullptr which is the new way of setting a pointer to NULL.
In future C++ code it will be very common to never see the keywords new and delete, instead there will be a lot of make_shared() or make_unique().

But this example is just one part and there is so much more. Coming from the knowledge of the old C++ basics to the new C++11 you can only agree to the words of Bjarne Stroustrup:

"C++ feels like a new language"

Everyone interested in C++ programming should start reading and learning more about C++11 just because it holds so much more than C++03. For that reason I can recommend you to browse through the videos of Channel 9. The two videos embedded below are a must for every C++ programmer, also who would want to miss a talk from Bjarne Stroustrup himself or even Herb Sutter? Although I have to warn you, those videos are not YouTube videos. They don’t go two minutes but mostly two hours. Enjoy and happy C++11 programming! 🙂

For the geeks: Unfortunately the ISO doesn’t let you download the standard for free but you’d have to pay a few hundred bucks. But there’s close to the official release draft which holds about everything. I can’t compare it but people on the internet say the differences as minor as only people who are trained to read such gazing stuff will understand them. Anyways here you go:

C++11 standard – draft n3242

Kommentar [1]
Geschrieben am 05.03.2012 von admin in Computer, Linux, News, Windows
 Tags: , , , , ,