9 reasons to start using C++11
cpprocks.com
cpprocks.com
But I just have this nagging worry that C++ is going to collapse under its own weight. C++ was already the most complicated language in common use IMO (except possibly Perl); with C++11 there are more keywords, more constructs, more variations. I just hope this doesn't make C++ seem totally unapproachable to beginners, or too hard to keep up with for people who are already using it.
Even now on low-powered devices like phones you can often get away with more wasteful languages like Java or even Javascript. And server-side there are a bunch of much higher-level languages that are close enough in performance and usually with a far richer ecosystem to boot.
Sadly from all options I listed above, C++ is still the best one supported in the industry. But coupled with a good static analyzer, it is quite nice.
What we miss is the possibility to have native code generation support for higher level languages to become more widespread.
Desktop applications, where a good integration with the operating system is required.
System programming and distributed systems as well.
I lost a bit faith on VM based systems for deployment, due to too many deployments gone wrong.
Now I advocate systems where you can get the best of both worlds. A VM based environment for development, and compile to native code when releasing the product.
Something like Eiffel, ML and Lisp language families already offer.
Java and .NET also have such options available, but they are not widespread.
What's funny is that high-level languages develop a culture of not caring about performance, which makes what could be a mild problem, much much worse.
Java is actually a pretty fast language(for most purposes), you wouldn't know it from 9 out of 10 desktop java applications I've used.
I've dabbled in OCaml and Haskell but my current favorite is Go. I'm still looking for a good excuse to use it.
IMO the new pointer stuff is excellent, and relieves the large majority of the memory management burden.
I think the main change C++11 makes in this area is the introduction of std::unique_ptr.
In my opinion (and experience) when you need the performance advantages of C++, you are usually within the domain where C is good enough (and perhaps a better choice for its simplicity). When you need the features of C++, you are probably better off with something like Python (not specifically, but in the same "league").
Seeing how easy it is to use a higher-level language combined with C for critical sections, I just don't see the point of C++ anymore.
Disclaimer: I don't really like C++. The only pleasant experience I had with it involved ignoring the STL completely and using Qt (http://qt.nokia.com/). I like C though.
pretty much any system involving long list- or set-like types with a decent level of complexity. Most other languages enforce far too much indirection, padding et. al for collection types. Especially generics fail miserably compared to templates for that particular matter. C, on the other hand, will make everything MUCH harder. Especially proper use of RAII and (const) references allow (almost) zero overhead and almost no error-prone pointers (especially zero pointer arithmetic) in the whole system.
It is false that C "will make everything MUCH harder". How hard something is to implement in a particular language depends on the problem and the people doing the implementation. C is only perceived to be much harder because people have become overly-dependent on language features (aka "syntactic sugar") and cannot reason about problems in terms that do not require those features.
I'm not talking about using assembly here. It is not a matter of an unstructured language vs. a structured one. I'm talking about features. This is particularly relevant because in many places where C++ is used, the coding standards prohibit the use of more than a limited subset of the language, effectively transforming it into "C with classes".
For me, that really is the edge that C++ holds over C.
Stroustrup discusses this here:
http://channel9.msdn.com/Events/GoingNative/GoingNative-2012...
Polymorphism and "good generic data structures" (in the sense you are implying) are not a necessary requirement of elegant and maintainable code. It is part of the problem that programmers have taken OO concepts as the end-all of good code, and must apply those concepts everywhere even if that means implementing them from scratch at the cost of (unnecessary) complexity.
Large systems have been written in C. Many large open-source projects use C. There is no evidence that these are less maintainable (in general) because of language choices.
Some of these graft OO concepts onto C. GTK is noticeable for this (although it doesn't seem to be too bad for application developers, I'm afraid for those tasked to maintain the libraries themselves).
Procedural programming is not a sin (if "procedural programming" exists at all today, as most of the simplest object concepts have become common practice and are now though as an integral part of it).
As far as I know, there is no such 'old saying'.
However, The determined Real Programmer can write FORTRAN programs in any language.
If from OO, I could have only Java-like interfaces, it would probably be enough. Implicit type conversions could also work I suppose.
I have an example. The Squid proxy code used calling via function pointers everywhere as DIY polymorphism. That made it quite difficult for me (ymmv) to follow the code.
Things like ctags would have worked if they'd used "real" C++ polymorphism.
IMHO. YMMV.
C is my obvious choice, but...
When it comes to deciding between C and C++, C++ beats C in one aspect: templates. For example, quick sort in C++ performs a lot better than C because templates enable lots of compiler optimizations. (Rest of the C++ features are just garbage for my purposes.)
I just hope next C revision adds some form of template support into the language.
But do not forget that the improvements given by C++11 do not void all the reasons to not use C++ at all. Avoid C++ if you can.
As much as newer languages come about, in the end, you are working with a Von Neumann machine, of which both C and C++ are well suited for.
The only problem with C++ as far as I can tell is that you need to know a lot, not to make mistakes. There are too many ways to do things, that if you don't know what you are doing, you are probably going to do things wrong. However, once you _do_ know, and use libraries like Boost, I think it is difficult to come up with a reason why not to use C++ for lower level programming, with performance requirements.
Also, I'll have to disagree with C++ being a narrow market. Just the market where C/C++ is almost required (high performance or low level) is large enough as it is.
Then there is the discussion of which language is _more_ suited for a given task when you are doing higher level stuff that doesn't have high performance requirements. It might be wasted resources to put people with high knowledge of C/C++ to that kind of tasks. As for the language itself, in terms of productivity; _if_ the developers are experienced, I don't see any problem with it. With help from Boost and/or Qt, it is as easy as writing python (almost, sometimes :) ).
- Maintaining two slightly different versions of most declarations is unproductive.
- Not having a stack trace when the program crashes slows down debugging tremendously.
- C++ compilers are horribly slow
- Shared pointers are very slow memory hogs but not using them makes memory management a lot more error prone.
- C++ isn't faster than Java any longer, sometimes even a lot slower, unless memory is the bottlenck (which is often the case though)
I use C++ only if I absolutely must determine the exact memory layout of data structures.
Almost all middleware is now written in Java. C# took over the frontend development on Windows. New openings in C++ seem limited to quant fields (bank backends on linux) and driver development.
That is a bit worrying with Oracle's recent shenanigans with Java copyright.
I wonder what people like Rich Hicky and Martin Odersky have to say about this subject.
In one project, I implemented an EDSL for performing a destructuring bind on a string (CFG production, actually). The types of the components of the pattern determined what the pattern would actually match.
This was all done in a previous version of C++, so I didn't have variadic templates available. I also didn't want to heap allocate the internals of patterns.
What I did was to store an array of void pointers and a function pointer as private fields within a pattern class. When constructing the pattern, pointers to the things to which parts of the string to be bound were put into the array, thus throwing away their types. BUT, the function pointer pointed to a static method in of a class template, which only operated on the array of void pointers in a type-safe way, precisely because it was compiled with the knowledge of the types.
I use this type of subversion when appropriate, and it's often a very convenient solution to an otherwise tricky problem. Such a thing would either not be possible--or be incredibly inconvenient--in C. It's often very useful to treat different stuff uniformly, knowing that your abstractions can maintain type safety.
Portability is probably the main reason I'm concerned about switching my codebase to the new standard...
For details consult the following:
http://clang.llvm.org/cxx_status.html
http://gcc.gnu.org/projects/cxx0x.html
http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.a...
The new smart pointers make me nervous after the auto_ptr fiasco but they seem to be working fine in my code so far.
I'm looking forward to trying out the lambdas as soon as they hit in XCode.
- which architectures is the author discussing when he talks about performance gains, what are the ISA requirements and numbers?
- what compilers are supporting it?
- why is it good to have "magic" happening in the background? E.g. reason 4 is not something I'd promote.
Of course, the fact that this is so useful might make you wonder if C++'s type system is too complex in the first place.
http://stackoverflow.com/questions/189172/c-templates-turing...
There is never a case where you have to wonder what the type of an "auto" variable is, it is always the return type of whatever function or method you are invoking. If you don't already know what that return type is, you won't be able to use the result anyway.
2. Apache maintains a list of which compilers support what. http://wiki.apache.org/stdcxx/C%2B%2B0xCompilerSupport
3. The auto keyword isn't supposed to be magic. Rather it's for catching complex types that aren't easily to discover, such as the returns of template functions and iterators, and making it easier on the programmer by not forcing the typing out of long types. The type is resolved at runtime (as best as I am able to tell) and can help clean up some of the messiness of template programming.
The reason I'm not happy with "auto" is that as a programmer you'll end up hunting down types in source. Even more so if you inherit code from someone else. So we'll add them in comment as mental note instead of properly declaring them?
You call it messiness (visual clutter in the article) but in my experience it'll promote laziness and pitfalls for beginners. It's just a matter of time before you'll see questions like 'why does the compiler infer the wrong type here?' on StackOverflow.
Re-reading my post I see it's easily interpreted as arrogant. That wasn't my intention.
There's a looooot of material about pro and contra arguments, if you look at C#'s type inference.
Replace
auto x = ...
with var x = ...
and you can read a good amount of arguments about the benefits and (potential) downsides, and where people deem it useful and clear or where brittle and questionable.
The argument you're making was discussed at length when this feature was first introduced. I think it applies 100% here as well.