tags:

views:

133

answers:

3

Hi,

I have this classic question of how should the C++ Standard (I mean the actual official document of the finalized ones) e.g. C++98, C++03 be used to learn and teach C++. My idea is only from the point of view of an average C++ user and not from the point of view of the language lawyers or someone who wishes to be in the Standards committee, compiler writers and so on.

Here are my personal thoughts:

a) It is aweful place to start learning C++. Books like "C++ in a Nutshell", "The C++ programming Language" etc do a very good job on that front while closely aligning with the Standard.

b) One needs to revert to the Standard only when

  • a compiler gives a behavior which is not consistent with what the common books say or,

  • a certain behavior is inconsistent across compilers e.g. GCC, VS, Comeau etc. I understand the fact that these compilers could be inconsistent is in very few cases / dark corners of the language e.g. templates/exception handling etc. However one really comes to know about the possible different compiler behaviors only when either one is porting and/or migrating to a different environment or when there is a compiler upgrade e.g.

  • if a concept is poorly explained / not explained in the books at hand e.g. if it is a really advanced concept

Any thoughts/ideas/recommendation on this?

+2  A: 

The standard should be used to ensure portability of code.

When writing basic c++ code you shouldn't need to refer to the standards, but when using templates or advanced use of the STL, reference to the standard is essential to maintain compatibility with more than one compiler, and forward compatibility with future versions.

DominicMcDonnell
+6  A: 

The C++ language standard would be an absolutely terrible place to start learning the language. It is dense, obtuse, and really long. Often the information you are looking for is spread across seven different clauses or hidden in a half of a sentence in a clause completely unrelated to where you think it should be (or worse, a behavior is specified in the sentence you ignored because you didn't think it was relevant).

It does have its uses, of course. To name a few,

  • If you think you've found a bug in a compiler, it's often necessary to refer to the standard to make sure you aren't just misunderstanding what the specified behavior is.

  • If you find behavior that is inconsistent between compilers, it's handy to be able to look up which is correct (or which is more correct), though often you'll need to write workarounds regardless.

  • If you want to know why things are the way they are, it is often a good reference: you can see how different features of the language are related and understand how they interact. Things aren't always clear, of course, but they often are. There are a lot of condensed examples and notes demonstrating and explaining the normative text.

  • If you reference the C++ standard in a post on Stack Overflow, you get more a lot more upvotes. :-)

  • It's very interesting to learn about the language. It's one thing to write code and stumble through getting things to compile and run. It's another thing altogether to go and try to understand the language as a whole and understand why you have to do things a certain way.

James McNellis
Chubsdad
@chubsdad: It depends. If the quoted text is not unambiguously clear, then it should be summarized and explained. It also depends on the apparent skill level of the person asking the question: if the questioner is likely a beginner with the language, making extensive citations to a language standard might be a bad idea. If the questioner leaves more confused or frustrated than when he came, that's no good.
James McNellis
A: 

I use g++ to compile my C++ programs and there I use the option -std=c++0x (earlier, -std=c++98) to make sure that my code is always standard compliant. If I get any warning or error regarding standard compliance, I research on that to educate myself and fix my code.

ArunSaha