4 ms·
I agree that C++ is a mess of a design, but I don't think this article quite gets how. RAII and move semantics are two of C++'s best features, and the ones that
by pubby 5y ago
I agree that C++ is a mess of a design, but I don't think this article quite gets how. RAII and move semantics are two of C++'s best features, and the ones that any replacement - like Rust - will copy.
To me, bigger flaws with C++ are that it's too big. The language is bloated with multiple features that accomplish similar things, but each with their own odd corner cases and interference. Anytime there's an issue from a language component, the solution is to tack another language component on top of things. See for example the progression of Macros -> Classes -> Templates -> Constexpr -> Concepts. Each tried to fix flaws in the previous design, but each introduction made the language more complicated, not less.
> But exceptions come at a performance cost.
I mean it's slow to throw, but non-throwing code paths are hardly affected. Typical implementations store the exception unwinding stuff off to the side, so the only cost is binary size.
> That means you need to write code that wraps every possible resource in RAII logic.
Consider using scope guards. You can write them directly in your code, without a separate class per resource.
int* ptr = malloc(...);
auto guard = defer([&]{ free(ptr); });
- mFixman 5y agoFrom a post in /r/cpp [1], > As of C++20, the right way to write a trivial getter in C++ looks like `[[nodiscard]] constexpr auto GetFoo() const noexcept -> Foo { return foo_; }` C++>11 is such a mess than most useful changes are invisible to most users due to bloat. I think it's way past time to call it quits and abandon active development of the language. New features will come from other languages without 35 years of baggage. [1] https://www.reddit.com/r/cpp/comments/swv6wh/when_not_to_use_constexpr/hxozdse/ https://www.reddit.com/r/cpp/comments/swv6wh/when_not_to_use...
- UncleMeat 5y agoI'm not sure it is remotely reasonable to choose a language for a project based on the verbosity of accessor signatures when being maximally pedantic. C++ is indeed a mess but there is almost no alternative for existing enormous codebases than to keep making it better. The industry will slowly adopt memory safe system languages, but that's going to take ages to go beyond greenfields and absolutely security-critical systems.
- rowanG077 5y agoWhy would you write a trailing return type for a simple getter?
- Rusky 5y agoI do think the article's criticism of C++'s move semantics is fair. Rust's "copy" of both RAII and move semantics is drastically simpler, and C++'s version is part of what makes the language so huge.