As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 12 years ago.
So I've been trying to do some research and would like the opinions of other developers on this topic. I am an experienced C++ programmer and have been using the current C++ standard for some time. I have been reading articles that "C++0x will undoubtedly become the new standard." How far off are we does everyone think from making the switch to a whole new programming standard? Also, which, in your eyes, is a better standard? From how I understand it, C++0x will come with more standard libraries making development easier without many more dependencies. Please help me to catch up!
Thanks!
Dennis M.
It would be pretty sad if the next version of C++ were quantitatively worse than the current one. The entire point of the new revision is to improve things.
Well, it depends.
The current C++ standard (C++03) is currently "better" because most of the latest C++ compilers and standard library implementations conform fairly well to the standard. Yes, there are issues, but most of them are very well known (e.g., hardly any compiler supports export) or are fairly easy to work around.
Support for C++0x is pretty patchy right now. Different compilers support different parts and there have been pretty major modifications made to it over the last year, so compilers that did provide early support for some features are now "buggy" if you consider their conformance to the latest drafts.
Going forward, though, C++0x will be a huge improvement over C++03. Major features like the concurrency memory model and the standard threads and atomics libraries are extremely important for the future of the language. Move semantics will make it easier to write clean, high performance code. Most of the new language features will make developing in C++ a more enjoyable experience.
"C++0x will undoubtedly become the new standard" is an understatement. C++0x is the draft of the new standard. Parts of it are available now in compilers like G++ 4.5.
It is impossible for C++0x to be qualitatively worse than the current C++ standard, because one of the essential things about the new standard is that it is fully backward compatible. If there are bad parts, you can just avoid them. (Of course, that doesn't mean that new features in C++0x can't be used to create really bad code that you'll have to deal with, but if you're coding on your own, you can always choose to avoid C++0x features that are worse in your opinion.)
Depends on what you mean by "better". If you mean "More likely to work with whichever compiler I'm using at the moment", then the old standard will certainly be better, with a little boost thrown in.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have an old program written in C from the 1990's. I would like to update it so that it will work for the next persons and on modern compilers. Currently I am using a really old version of TurboC to make changes. Should I be focusing on rewriting this in modern C or C++? Which will be the easiest to bring this code up to date without having to rewrite too much and be able to reuse most of the existing code?
My programming background has mostly been in hprogramming languages like Perl, Python, PHP, Powershell, and Visual Basic, so I am not too familiar with the differences between C and C++.
C and C++ are different languages, not different versions of the same language. Stick to C, although you could use the fancy features of newer versions of the standard, like C99.
Your last sentence pretty much answers your sentiment. If you aren't familiar with the differences and you only know older languages I wouldn't update this program unless there is something horribly wrong with it that is affecting many users.
You could update it just within the C world to adhere to C99 or C11 if you have a newer compiler
Given:
have an old program written in C from the 1990's.
You have two questions:
Should I be focusing on rewriting this in modern C?
Maybe, maybe not. I would try to adhere to a standard C89, C99, or C11. This mainly depends on your tools and how much new development will happen.
Do you like declaring variables other than at the beginning of scope? If so, then possibly update to C99. Are you using any tools that really like C89 and show errors or warnings with C99 conventions? If so, then stick to C89.
If the program is continually being updated and you are hiring young people, then newer conventions might be beneficial.
Should I be focusing on rewriting this in C++?
No.
Most well-written C programs are also valid C++ programs, or require just a little adaptation. The opposite is not true.
It's probably easier to stick with ANSI/ISO C and leave both doors open for the next maintainer.
It's probably about the same effort to move to a modern C compiler vs. a modern C++ compiler. The evolution of C and C++ have diverged where each has similar features but they're not source compatible.
There are a few factors that would lead me to choose to update to C++:
Modern C doesn't seem to enjoy as much support as C++. For example many new things in C seem to get implemented only as required by C++, especially in the Microsoft world. VS doesn't even support C99 except for what's in C++, let alone C11.
C++ is a better C: "C++ is "a better C" in the sense that it supports the styles of programming done using C with better type checking and more notational support (without loss of efficiency)." This is still true of modern versions of C.
C++ adds features that support some very powerful techniques. Really making use of them may be best left to library developers, but that means C++ can support really great libraries.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'd like to begin transitioning to use C++11 in a large, cross-platform codebase. The main problem is that the level of C++11 support varies between the compilers that are used.
Aside from littering macros throughout the code, does anyone have any examples/suggestions on how to ease this transition? Please provide techniques for specific features. For example:
// cpp11compat.h
// For compilers that do not have 'nullptr', we will define it as 'NULL'.
// Any misuses of 'nullptr' will be caught by C++11 compliant compilers.
// Obviously, this won't fix anything that depends on the type 'nullptr_t'
//
#ifdef STUPID_SUN_COMPILER
#define nullptr NULL
#endif
Thoughts?
I would suggest that you start with finding the largest common denominator of C++11 features by current compilers. For a survey see: http://wiki.apache.org/stdcxx/C%2B%2B0xCompilerSupport
The most widely supported features include auto, decltype and move semantics, so you could start with rewriting your code with those, and make a #define fix for the platforms that don't support a specific feature that most other platforms do support (e.g. nullptr).
For the file organization of all the config files, you might want to check the source code of Boost.Config It contains several directories, ordered by platform and purpose. E.g. config/platform/irix.hpp contains all the platform specific stuff for Irix.
EDIT:
Another good way to do emulation of language features is to look at the Boost libraries for Language Feature Emulation tags. They contain libraries such as Move, Foreach and previously Lambda that have very similar (although not necessarily exactly the same) syntax as the standard C++11 features. This allows you to let Boost worry about platform compatibility.
Little time has passed since the publication of the standard. While you could probably reach almost all of C++11 features through boost, this year probably is not the best timing for starting that type of migration unless you already are on this road, because it would result in migrating twice.
So I suggest that you give compiler vendors another year or two before you start migrating. Meanwhile, try to stop supporting any abandoned platforms where no updated compilers are likely to appear if you feel that C++11 is very important for you throughout the code base.
(In fact, it is completely fine and common to never completely migrate a large codebase to the next version of a language standard, but that is not relevant to your question the way it is currently phrased.)
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
C++11 provides us with a lot of new great and immensly useful tools. GCC support of C++11 has already made good progress. So I have thought about when to switch to C++11. This question relates to gcc only, I do not expect to compile my (our) code with any other compiler.
Would you (did you) switch to C++11 before gcc supports the entire C++11 standard to benefit from the features already implemented? Would you still do this in a production environment where stability and correctness is very important? Do you think it would be a reasonable approach to allow developers only to use certain C++11 features?
How would you (do you) go about deciding when GCCs C++11 support is ready for a production environment?
(Note: I'm aware of this question, but it specifically relates to gcc 4.4 and is somewhat outdated)
It depends.
If it were to power my blog or something like this ? Definitely.
If it were to power a critical service ? Of course not.
I believe that the support of C++11 is too immature as it is now, to be called production ready.
You may settle on a version of gcc, but the truth is that because the successive drafts evolved as new problems were discovered and tackled, the code you write now may well be rejected by a later version, or the behavior may change lightly.
Therefore, I think this judgement truly depends on what you intend to be doing. There is a reason the space shuttle is powered by an old and proven technology: it's a matter of trade-off between ease of development and confidence in the tools.
It's your judgment, you know your situation better than we do.
The GCC C++ developers still think their C++03 support is not up to par, and therefore aren't even setting the __cplusplus version correctly (citation needed, I can look up the bug+discussion). They marked the support as experimental because they started implementing the basics before there was a final draft/standard. By now (ie GCC 4.6), most major flaws have been removed, although some details remain inconsistent with the exact standard wording.
If possible, you should also test with Clang, which IMHO strives and succeeds at better adhering to the puny details in most places where GCC lacks the necessary enforcement. Production use is something that's personal. Me, I think that every compiler has bugs, and although the chance of a bug in the "new stuff" is statistically more probably, chances are you'll also encounter an older bug messing with your perfectly compliant code. That's why I suggest using at least two compilers to prevent any incompatibilities (or at least reduce them as much as possible).
As for the Standard library, libstdc++ is functional for the most part, but lacking in some large and useful parts like <regex>, which is sad. If you're feeling lucky, you should be able to get LLVM's libc++ working on at least Linux and Mac, this is a feature complete c++11 library minus <atomic>), but also the "new kid on the block".
To summarize: the more compilers and Standard libraries you run your code against the better (although you should check which ones are correct, and which are buggy). This inevitably reduces the amount of C++11 features available to you, although if you go with GCC/Clang, only lambda's, uniform initializers and <atomic> fall outside your scope. MSVC is a different story...
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
After reading an amount of C++ articles and tutorials, I often see the phrase "C++ is not C!" or some variant. If this is true, why is C++ trying to be compatible with C? Surely this just encourages C programmers to write bad C++ code? I'm only a newb in the field, so feel free to bombard me with reasons why I'm wrong in thinking that C++ should just make it's mind up and forget C. Ell.
The purpose of compatibility with C is so that C++ programs can have convenient access to the billions (trillions?) of lines of existing C code in the world. It was never intended as a suggestion to code C++ as if it was C.
Peripheral objectives were:
Leverage the C skills that many programmers have (given that it is still one of the most widely used languages in the world).
Encourage the use of C++ as a better C, for: a) easing the transition to C++, and b) improve C coding practices for programmers who have no intention of going to C++.
You can read the historical perspective from the man himself here.
Should C++ forget C? In a sense it already has, the development of the two languages progress independent of each other.
C++ started as "C with classes", and it was just a precompiler that transformed the class & co. syntactic sugar into C code (C was chosen because it was quite widespread, C compiler were available for many platforms); this was one of the reasons it was (is) C-compatible. Another (and maybe more important) one was to remain compatible with the existing C codebase (libraries, syscall, ...), which has been a significant advantage for its widespread usage.
However, during its evolution and standardization, C++ evolved in something quite different.
All the new features that were packed in it (notably advanced OOP capabilities, exceptions, templates) and the evolution of its standard library (especially the inclusion in it of the STL) encouraged new programming styles, that differ significantly from the old "C with classes" style; many common C idioms became obsolete, and had better replacements in C++ (see e.g. std::string vs C-style strings, std::vector vs "normal" heap-allocated arrays). Still, it wasn't a good idea to remove the "older" features, since (1) C compatibility is still important in many cases, (2) the "old" stuff is the foundation for the C++ data structures (std::vector internally uses raw pointers and plain heap arrays) and (3) the background philosophy of C++ is to let the programmer choose.
Since in general the "native" C++ alternatives are better than (usually safer/easier to use/more difficult to misuse, and in general as fast as) the corresponding C idioms, it's usually told to C++ newbies to forget about C and start directly from C++, to avoid picking "C bad habits".
In particular, many C habits (=> e.g. raw pointers) become dangerous when exceptions are used, so it's better that a new programmer starts from the beginning with the idea that his code can be interrupted at any place, and make it exception safe from the beginning wrapping its resources in RAII classes.
C++ used to be compatible with C (it was even compiled with a C compiler, using preprocessor macros to turn it into C), but then newer versions of C came out, and C++ got it's own compilers, and since then, then languages have become different. Still, with a little care, you can get C code to link properly with C++ code.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
This is a question in two parts, the first is the most important and concerns now:
Are you following the design and evolution of C++11? What blogs, newsgroups, committee papers, and other resources do you follow?
Even where you're not using any new features, how have they affected your current choices?
What new features are you using now, either in production or otherwise?
The second part is a follow-up, concerning the new standard once it is final:
Do you expect to use it immediately? What are you doing to prepare for C++11, other than as listed for the previous questions?
Obviously, compiler support must be there, but there's still co-workers, ancillary tools, and other factors to consider. What will most affect your adoption?
Edit: The original really was too argumentative; however, I'm still interested in the underlying question, so I've tried to clean it up and hopefully make it acceptable. This seems a much better avenue than duplicating—even though some answers responded to the argumentative tone, they still apply to the extent that they addressed the questions, and all answers are community property to be cleaned up as appropriate, too.
Can't guess how many are interested in the new C++0x and I am pretty sure that everyone who knows C++ and uses it is curious and eager for more news about it.
I started using everything new from C++0x as soon as it was implemented from g++. Still for small non portable projects.
Why? - People constantly telling me to forget about c++ and switch totally to a scripting language to gain faster code developing and forget about memory management. However, my best experience and knowledge is in c++. I know RAII and use Boost library everyday. Now, the new features make me write much faster then before. Knowing that rvalues are here, pointers(even the smart) disappeared from the code. STL algorithms with lambdas just rock and initilizer lists make me so happy. Auto keyword is furious.
So, my primary reason to use C++0x now is speed of development.
I'm not using C++0x today, because it will lead to losing code portability. Because there is no C++0x Standard today.
Answer: No
Reason: code portability
No, because it's not fully implemented on the compilers I use.
When C++0x comes out, and Visual Studio 2010 is fully released, along with a "matching" g++, I will use C++0x when I can. This is likely because I frequently start new projects (I make games).
Although I have an existed code-base, it changes every time I figure out a way to do something better; change isn't an obstacle for me. Taking advantage of C++0x would just be another change.
You'll find different opinions with larger code-bases. Some places prefer code to look uniform, and that means spotty C++0x isn't an option: they'd either have to convert the entire thing to take advantage of C++0x, or not use it.
Other places might encourage the use of C++0x features, and in spare time try to fix up older code to match.
And other places, like me, might immediately want to take advantage of all C++0x has to offer.
The answer is: it depends.
No, but I would like to, especially for the lambda functionality.
No.
All my application software is developed in Java. All my quick-and-dirty code is done in Python. All my low-level work is done in C. I don't generally use C++ (hence it hasn't affected me).
If I did use C++, I'd treat c++0x like I'm treating C1x - I'm making sure my code won't break but I'm not going to use the new features until the standard is done and dusted.
As to whether I'll use new features as soon as the standard ratifies, no. The process will be a gradual one. As maintenance gets rolled out for my current applications, I may add it, depending on the likely benefit.
Even new applications that I write will require a need for the new language features before I consider using those feautures.
No, I'm still using VC6 most of the time :(, won't get on to C++0x until 2020 at the earliest (perhaps I should change company?)
I'm using lots of C++0x, in particular variadic templates and functions, auto and decltype, and rvalue references.
While things can be a little fun, with g++ 4.5 and Visual Studio 10, these features are now fairly stable and work the same on both compilers.
Software projects I am starting now probably won't be released for a year or so, and by then I expect these new compilers to available as standard.
Yes when toying arround on my own code that doesn't have the pretention to go out in the nature.
No when I code something that some people will use on older compilers.
Depends. I'm getting ready to use certain C++0x features in my master's thesis (although so far I've stuck with C++03 compilers mostly while waiting for VS2010b2)
I wouldn't use it in actual professional production work yet, though. For that, I'd want to wait until the standard had been finalized, and in the case of MSVC at least, until the compiler had been released in a non-beta version.
I'm using the TR1 (regex, unordered_map, unordered_set...) and some boost features that'll be in the next standard like (hopefully) lexical_cast... everyday, not just today :)
New job this year, so I willingly changed sides to the .NET/C# world. Most of the gripes I had with C++ are just non-existant in C#. They did a lot of things right (d'oh! Me praising MS)
I think C++ has become a monster, and when I last looked at it C++0x appeared to grow the monster instead of slimming it down to the really necessary subset.
Just my two cents for a subjective question ;)
Learning about the features coming in for C++0x was interesting, in particular when I realized I was already using some of them via C++ TR1. So far the extended for ("foreach"), static_assert and the improvements in <functional> are the ones I'm using the more in C++0x programs.
It has also taught me a bit about code reuse. Trying to reduce the amount of code I have to change to adapt to C++0x, and at the same time preserve the code compatible with C++-pre-0x as much as I can (for eg.: library stuff) has taught me to integrate some C++0x fixes and elements to my pre-C++0x toolbox; in particular extending numeric_limits<> to include the const_ members, adding nullptr emulation, adding default_delete and similar constructs, and making use of the (apparently often forgotten, as I've not found code using it besides mine) [slist|forward_list].
I'd say using C++0x today has helped me better continue to use C++-pre-0x today. I'm not sure I'll be taking the leap to "full" C++0x anytime soon, considering Boost helps to cover some ground there. And that I don't intend to touch regexes or threads with C++ in a long, long time.
I am using static_assert, decltype, and, occasionally, r-value references
for now, all I'm using is auto and decltype, since most of my code doesn't use anything necessitating r-value references or things of the like, and I'm quite satisfied with auto for now(beats declaring a an iterator of a vector of maps)
unordered_map. It should've been obvious when map was originally specified that not everyone would want to pay the cost of sorting their associative container keys but, oh well, at least we finally have a completely standardised STL container for it.
I'm also using the threading library and other stuff. Haha, I'm an early adopter! I'm not employed and I don't work directly with anyone so I can basically do as I like with these things. :)