3 ms·
I think C++ has a very bright future - due to two driving forces: 1) The C++ Standards committee has been doing a very, very good job. Aside from the big one (
by hendzen 12y ago
I think C++ has a very bright future - due to two driving forces:
1) The C++ Standards committee has been doing a very, very good job. Aside from the big one (compiler enforced memory safety), some of the best Rust features are on their way into C++. For example:
- Traits: C++ concepts are on their way - there is even a working implementation in a gcc branch.
- Iterators: See Eric Niebler's range proposal and accompanying range-v3 library.
- Monadic error types (including do-notation!) proposal: http://www.hyc.io/boost/expected-proposal.pdf http://www.hyc.io/boost/expected-proposal.pdf
Other great stuff coming to C++ over the next few years:
- ASIO in the standard library - see prototype here: https://github.com/chriskohlhoff/asio https://github.com/chriskohlhoff/asio
- Resumable functions
- Composable futures
- Parallel algorithms + concurrent containers
... much much more
2) Clang/Libc++ development is unbelievably rapid and it has greatly improved the tooling available to C++ developers.
Some highlights here:
- Clang-format and clang-tidy to help developers write cleaner code
- Sanitizers like AddressSanitizer, MemorySanitizer, ThreadSanitizer, UndefinedBehaviorSanitizer that instrument binaries to find bugs at runtime
- Much better error messages for template heavy code
- an API for easy development of custom tools that parse/consume C++ code
... much more
- jdub 12y agoBecause adding more things to C++ will make C++ better. :-)
- kbenson 12y agoShort, succinct, and utterly inscrutable[1]. ;) 1: http://en.wikipedia.org/wiki/Poe%27s_law http://en.wikipedia.org/wiki/Poe%27s_law
- heinrich5991 12y agoSanitizers only help find bugs that are actually triggered. Security vulnerabilties usually come from code paths that are not commonly exercised.
- makomk 12y agoI'm not sure that's actually true in the case of ThreadSanitizer - a well-designed data race detector can detect race conditions that didn't actually get triggered in that run. In any case, usually people try and exercise those rare code paths by running a fuzzer against sanitizer-instrumented code.
- heinrich5991 12y agoThreadSanitizer can also only catch bugs that can occur in the code paths that are exercised – and running a fuzzer can certainly show the presence of bugs, but I'd be wary if someone claimed it can show the absence of them.
- pjc50 12y agoI don't think adding features helps much, it just continues to raise the barrier to entry; C++ needs a means of "banning" "unsafe" techniques; e.g. an option you can turn on that causes C-style casts or pointer arithmetic to be a compiler error.
- humanrebar 12y ago- Traits: C++ concepts are on their way - there is even a working implementation in a gcc branch. Rust traits and C++ concepts are not the same thing at all. C++ concepts are sort of like template parameters with better (not complete) type checking. Rust traits are closer to interface declarations. Though it's really hard to do a description of either justice in an HN comment. The rest of your bullet points are fair, if a bit optimistic. I don't see all the features you listed making it into C++ 2020. But I'm hopeful that many of them will be, especially sane libraries for extremely common problems like ASIO.
- tomjakubowski 12y agoThe closest comparison that comes to mind for Rust traits is Haskell type classes, except for some (important!) implementation details like Rust's static monomorphization. You even get something similar to existential types with trait objects.
- seabee 12y agoDescribing what they are may be too hard for a HN comment, but what they achieve is easier. Traits are the way Rust supports both dynamic dispatch and static dispatch in polymorphic functions. C++ supports both kinds of dispatch too, but the means to achieve it are not the same across all scenarios. If you want to go from one to the other, you'll probably have to rewrite your code or create wrapper classes in C++. In Rust, you accept a &trait instead of constraining a generic type. C++ handles static dispatch through implicit template interfaces today, in the future by concept maps (but you can implement an ersatz version of it today, described in a blog post I wrote on this very topic[1]). Dynamic dispatch is always through your class's vtable. [1] http://chrisbranch.co.uk/2015/02/make-your-c-interfaces-trait-forward/ http://chrisbranch.co.uk/2015/02/make-your-c-interfaces-trai...
- rkangel 12y agoBut there are a few things in Rust that would be very difficult if not impossible to ever add to C++: The borrow checker - the Rust type system is much more powerful in lots of ways, of which the ability to check and enforce ownership of objects is just one. Macros - C++ pre-processor macros aren't in the same league as a proper syntax tree based macro system like Rust (and Lisps etc.). Another thing that you've left off your list is modules, which has been proposed for C++. My suspicion is that the need to support the legacy is always going to make those features not quite as good as their equivalent in a language designed from fresh.
- steveklabnik 12y agoWhile it's true that C++ still has lots of great things, the features aren't always directly comparable, due to C++'s existing semantics and commitment to backwards compatibility. For example, if you move a uniq_ptr, it will become null, and using it will cause a segfault. In Rust, moving a Box<T> works just fine, because using it after the move is a compile-time error.