6 ms·
> What is modern about any of features that have been added? Nothing. On the other hand, which features of a “modern” language are missing in C++ by now? Type
by claudius 12y ago
> What is modern about any of features that have been added?
Nothing. On the other hand, which features of a “modern” language are missing in C++ by now? Type deduction is still a bit less powerful than in Haskell, yes, but apart from that I can’t really think of anything that may or may not be missing.
This in turn implies that C++ allows essentially any style of coding you may wish for at the moment while at the same time staying some orders of magnitude faster than essentially the entire competition.
- Guthur 12y agoC++ is no faster than any other language, it's the code that is written which is measurable. The real wins in performance for real world applications are in terms of algorithmic complexity. A poorly implemented solution in C++ will still be slow, the language does not make it fast. Any micro optimization you can make with C++ will be an order magnitude less significant than O(log n) vs O(n). The likes of Janestreet will likely need high performance software yet have great success with Ocaml for example, which incidentally can be very fast. Just saying C++ is fast does not make programs written in C++ actually fast.
- claudius 12y ago> The real wins in performance for real world applications are in terms of algorithmic complexity. A poorly implemented solution in C++ will still be slow, the language does not make it fast. Yet a well written implementation in C++ will still be faster than an equally well-written implementation in, say, Python or Haskell or whatever. Not in an asymptotic sense, but easily by a factor ranging between two and 200. For me, this can be the difference between waiting a couple of weeks or half a year for some computation to complete :) > Just saying C++ is fast does not make programs written in C++ actually fast. Of course not, but C++ makes it possible for programs written in C++ to be fast.
- pkolaczk 12y agoComparing to Python or Haskell, maybe you're right, but not to CLR-based or JVM-based statically typed languages. Very often the differences between Java/C# and C++ are the same order of magnitude as differences between various C++ compilers. The mythological C++ performance is often overstated (there are some performance advantages in C++ but they are rarely big enough to justify language choice).
- tfinniga 12y agoI think C++ is justified when you're constrained by CPU, RAM, or other resources. That is, if the limiting factor is development speed, or network traffic, or waiting for user input, then C++ probably isn't going to be worth it. But if in your problem area you can get a competitive advantage by being faster, using less memory, or tightly controlling other resources, then C++ is probably the right choice. If you really need it, you can use some inline assembly too. For example, look at a VM's JIT compiler: it needs to capture a profile from a running application, analyze hotspots in that profile, recompile those on the fly to native code, and coordinate with the VM to swap that out on the fly. The more time and memory that is used to do all this, the slower every application on the VM will run. Since there's a very constrained environment, C++ is a good choice for JIT compilers. And if you look at the CLR/VES or JVM, they are indeed written in C++.
- pkolaczk 12y agoFair enough. But the number of resource-constrained systems is pretty low these times. A phone, watch, dishwasher or xero machine are no longer resource-constrained. Also, C++ is not really shining IMHO in very-constrained environments - at least not "modern C++" dialect. Template-heavy libraries can blow up code-sizes pretty severely and dynamic memory allocation happening behind-the-scenes in the standard library is not free either. So for those very constrained systems, pure C or a very tiny subset of C++, i.e. C with classes, no exceptions, no templates, might be often a better choice.
- tfinniga 12y agoYeah, I realize my view on this is a bit skewed. A lot of the examples people give where C++ is still justified are things that I have done in my career - image processing, video editing, rendering software, CAD software, solving large sparse matrix systems, etc. On the other hand, there is a reason why native apps are popular on the iPhone. Likewise, some games are programmed in high-level languages, but the performance advantage of C++ keeps it dominant in games. Between games and mobile devices, I'd say C++ isn't going anywhere any time soon. C++ can indeed be very bloated, like you say. On the other hand templates do allow for code reuse without the function call overhead.. I believe std::sort is faster than qsort. For me, if there was another language that was as well supported as C++ but allowed higher-level structures and programming methods, I'd be very much in favor of it. For now it looks like new versions of C++ are the closest there is. Nobody really likes C++ for its elegance, it's just a very practical choice.
- tfinniga 12y agoIs it possible to write C++ programs that are slower than their counterparts in other programming languages? Yes. Is it possible to write programs in other languages that are just as fast as good C++ implementations? Often it is not. That performance comes at a cost, it really depends on what your application is. Horses for courses.
- jmpeax 12y ago> Any micro optimization you can make with C++ will be an order magnitude less significant than O(log n) vs O(n) Wrong. See (from about 46min): http://channel9.msdn.com/Events/Build/2014/2-661 http://channel9.msdn.com/Events/Build/2014/2-661
- tomp 12y agoLightweight threads are missing, as are tail calls. Both (especially the second) prevent C/C++ from being a viable target for functional compilers.
- claudius 12y agoAgreed on guaranteed tail call optimisation, but it seems[0] that it is at least possible to get it in some cases on some compilers. It seems that calling dtors after the return (somewhat obviously) makes it impossible to do it, although appropriate scoping might help. I however didn’t play around with it, merely rephrasing what [0] wrote. I’m not sure about threads (and how light/heavy those currently in C++11 are). [0] https://stackoverflow.com/questions/34125/which-if-any-c-compilers-do-tail-recursion-optimization https://stackoverflow.com/questions/34125/which-if-any-c-com...
- pkolaczk 12y ago"but apart from that I can’t really think of anything that may or may not be missing" * Hygienic macro system. * Pattern matching. * Strong generic type system. * Persistent containers. * Lockless data structures. * Memory-safety. * Null-safety. * Reflection. * Dynamic/variant types. * Modules. * ...