The misunderstood one
Tuesday, August 12th, 2008 | Computer Science, Software Development
I’m a usual follower of C++ related blogs and newsgroups and still I’m impressed how much this language is misunderstood after 10 years of a precise standard. I’m actually starting to ponder if we are ready for C++0x while a lot of people yet misunderstand C++98 and C++03.
I often end up discussing with my colleagues about the fact that they prefer a less powerful, but more reliable and less obscure language like C. I know that C++ isn’t one of the easiest languages to master correctly and I also know that it has some problems about compilers often changing their behaviour and with slow templates compilation time. All things that C++0x is trying to make easier or faster with extern templates, move constructors, delegate constructors and type determination.
C++0x will be a quite complex and advanced language, which will give the programmer a lot of control over the compiler, but still after 10 years of existence of the standard C++ and formal STL libraries you can find posts like this which confuse good design practices and theories with runtime optimizations.
Having the stack container with the pop method returning void is exception neutrality not a runtime optimization. Strong exceptions safety means that the operation has either completed successfully or thrown an exception, leaving the program state exactly as it was before the operation started.
What would happen if we have a T pop() method returning the head after removing it? We might have the copy-constructor of T fail throwing an exception and find that after removing our head we also lost it forever. Having it just remove the item means that our code might only have success removing our item or fail to remove our item leaving the state exactly as it was before.
This is one of the first issues raised years ago, an issue discussed in depth since the article of Tom Cargil in 1994. An issues explained by Meyers and Sutter in their books and available in a lot of community blogs like the boost one. And still this isn’t clear even to long time C++ developers.
C++ is a multipurpose language, having all that freedom of movement requires more deep knowledge of the language itself. Shouldn’t we change how C++ is taught and more strictly enforce some practices before moving to a new standard? As a sporadic C++ teacher I often end up with this question…
-
abhinav
-
Simon
-
jon
-
KM
-
KM
-
Joe Burmeister
-
Fabien
-
Leon
-
Dan Pritchett
-
amol
-
Fabien
-
Ebrahim
-
Bartosz Milewski
Search
Archives
- January 2012
- November 2011
- October 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- September 2010
- August 2010
- July 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- December 2008
- November 2008
- October 2008
- August 2008