Question

Possible Duplicate:
When did the “c++” tag start to imply C++11 by default?

I see a lot of answers around SO that use features of C++ that I'm not familiar with. Upon further investigation, I find that they are part of the new C++11 standard. However, from my understanding, most compilers don't support much, if any at all, of the C++11 features, and those that get "close enough" are still considered to be somewhat buggy experimental. In respect to both questions and answers, how should recommending the use of C++11 features and code be handled? Should the asker specify if they can and want to use C++11?

As an asker myself, I typically work in an environment that does not support the use of C++11 (a small dev team, where one dev can't just up and decide to move to a new (or updated) version of a compiler to use a new feature), so it would frustrate me and inefficiently use the time of the answerer if I received an answer to my question that solves it perfectly, yet uses a feature that I can't access.

Edit: I understand that SO is not for one person, but all that may come across it in the future, especially when it will no longer be referred to as C++11.

Edit: I would like to add a noteworthy, in my opinion, comment made by Almo: "From this site: gcc.gnu.org/projects/cxx0x.html "Important: GCC's support for C++11 is still experimental." That does not sound like a de facto standard to me. I don't think you'd see a big corp basing business-critcal stuff on features the compiler said was "experimental"."

Was it helpful?

Solution

I always use C++11 first and foremost in my answers. That makes the answer better because it will resist the sands of time. Remember that the goal of providing an answer on StackOverflow is not to help one person at a time. It's to help everyone that will ever come across that answer. When someone clicks a link to that answer in some search engine results page in five years time, they will be happy I did that.

Doing so also helps spreads awareness of the new features, making it more likely that people will upgrade their compilers, or put pressure on their vendors to upgrade them.

I do take in consideration the fact that people will be stuck with... second-grade compilers for a while, especially those using MSVC, so when appropriate and feasible I also provide alternatives using the old language.

If an asker cannot make use of C++11 answers, they should mention so in the question. That makes it clear that the limited environment is a part of the problem. It is the asker's job to describe their problem correctly, not the answerer's job to guess it. But even in those cases, I do not eschew from at least mentioning any C++11 features that would make this or that part of the solution easier. It doesn't hurt.

But one should go beyond considering C++11 when answering new questions. There are lots of old questions that now have potentially outdated answers in them! When you see an old question that can be better answered using new features, post a C++11 answer on it. That's why we have the Necromancer badge.

OTHER TIPS

You can use any features from the current (i.e. C++ standard), unless the asker of the question has mentioned a specific compiler version, in which case you should use only what that compiler supports.

If you "typically work in an environment that does not support the use of C++11", and you don't mention that environment in your question, you have no one to blame but yourself if you can't use the answers you get.

C++ is defined by a standard, not by any particular implementation or non-implementation. This is one of the many great things about the language. If a question asks about "C++", with no further qualification, it is asking about the language, not any particular implementation of it.

C++11 is the current version of C++, so unless the question specifically gives a requirement to work on a particular compiler or with a particular version of the standard, answers should assume that the question is asking about C++11.

If C++03 (or earlier) answers are given, they run the risk of being out of date as soon as they are posted. In the long term, the vast majority of C++11 will be implemented by every major compiler vendor, and so C++11 answers will provide far more value to the site over time.

That said, there is nothing wrong with an answer that point out cases where behaviour is different between C++03 and C++11 (or cases where particular compilers have trouble, for that matter), as this can provide a more complete answer to a given question. Answers that are only correct for C++03 (or only correct for a particular compiler) should be clearly marked as such, to avoid the spreading of misinformation.

I think the standard is more or less a wild herring here. Answers should be based primarily on what's generally available, not what the standard says should be.

Obviously, if the question directly specifies a compiler, you pretty much need to try to stay within the limits of that compiler (though, of course, if somebody specifies, for example, VC++ 4.1 or gcc 1.37, most people can be forgiven for not remembering exactly what shortcomings those exact versions had).

Lacking that, I think most answers should be based on what (most) current compilers implement more than on what the standard says they should do. Yes, it's nice if you can give an answer that will still be good in 10 or 20 years -- but it's much more important that it be useful now. If something changes enough to render an answer less than useful in the future, it can be edited or a new answer added when it becomes necessary/useful. An answer that nobody can use is useless even if it's theoretically correct.

Of course, the rules change a bit when (for example) the [language-lawyer] tag gets involved or somebody's asking specifically about a (possible) compiler bug. In such a case, it may be perfectly reasonable to post code that won't work with any existing compiler (e.g., "here's code I think should work, but not only your compiler fails with it, but all the others seem to also").

Until C++11 is the de facto standard, I'd say answers should only use C++11 if the question specifically states that it's ok to use it, either in the text or via a tag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top