Live data from Hacker News

Is C++ Doomed?

tednesday.wordpress.com

71–80 of 168 posts

Re: Is C++ Doomed?

#71
I think the first step is to explain to people that C++ is just C with more stuff, the original is way simpler and the ONLY real reason to use a C++ compiler is that most dependencies that you need (OpenGL, OpenAL etc.) uses C++ by default.

That took me 3 years to figure out on my own, such a waste of time.

In C++ defense namespaces, strings and streams do have some usefulness to them, but if I could use a C compiler to build a modern 3D MMO I would remove those in a heartbeat!

Edit: I know there are construed ways to call the OpenGL API directly without wrapper, but GLEW (damn Windows) is too comfortable for me to switch yet... Eventually I might switch to TinyC and write my own OpenGL/AL... That or implement my own J2ME!

Re: Is C++ Doomed?

#72
post #61

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 fro…

From 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...

Re: Is C++ Doomed?

#73
post #5

It's true that implementing a standard library in C++ seems daunting but a) most C++ users don't implement stuff that goes into the standard b) you can tailor your data structures to the problem at hand instead of making it usable with every type and use case c) quoting Stroustrup: "There are only two kinds of languages: the ones people complain about and the ones nobody uses".

b is a limitation. C++ makes writing good general code a nightmare so you reduce to taylor your data structures to your problem c is just folk wisdom. That quote is just untrue a is true but it has gotten to the point that implementing C++ std libraries and compilers is so daunting a task that even the big vendors do not rush into it anymore. There is this growing fatigue that left only MSVC, gcc and llvm in the game…

>c is just folk wisdom. That quote is just untrue

Nothing folk wisdom about it. It's not 100% true but the quote is meant to highlight that most of the languages that get highly praised tend to the ones where the only people using it are those who really love it. People don't use C++ or JavaScript or other high demand languages because they're such wonderfully designed languages that they love, they use it whether they want to or not because it's the industry standard. Compare that to people who write Haskell, or D or other niche languages where the only people using those languages are the ones who really like it. If people had to use Haskell or other smaller community languages because they somehow became industry standards, I assure you'd be hearing tons and tons of complaining about performance issues, how buggy they are, how annoying it is to do X, Y, Z...

As is you don't hear people complaining about Haskell or D because the people who find those languages to be annoying simply stop using them and there's little reason to write a blog post about it. The predominant reason to write a blog post about a niche language is to basically give it some degree of praise.

>There is this growing fatigue that left only MSVC, gcc and llvm in the game,

What do you mean by this? I'm not aware of any other language that has three independent implementations that are all kept up to date within a year or so, the only language that comes close would be Java but even that is mostly dominated by Oracle's implementation.

Re: Is C++ Doomed?

#74

I should note that writing data structures in rust is also a fraught business! In practice, that’s just a property of languages that don’t have garbage collection. Exception safety is a serious complication in c++! Exceptions were a mistake in the language, particularly given the existence now of std::optional.

that's just false. Exceptions were not a mistake and std::optional isn't even a good type to replace more than communicating that there is no value. It's as good as returning nullptr, in this case. And what strength of an exception guarantee does one really need? A basic guarantee is not that bad to give and most things do not need to worry if they don't use unmanaged resources without RAII types(e.g pointers).

But the big thing is, a large amount of code does not have error states at all, they always work. Another chunk have preconditions, that are generally developer errors, that shouldn't be throwing either. That leaves the parts that interact externally. And here is where one learns, it's not a dichotomy of exceptions or error flags/results... it can be both. It's more to do with the shape of the code.

One example is, one is passing a string buffer to a parser, an exception is probably fine as the error cannot be dealt with within the parser. It didn't create the malformed document and cannot fix it. To use error types will greatly complicate the inner workings of the library as it has to deal with errors at a majority of calls internally. This leads to more bugs(assuming more code == more bugs) and complexity/branches. One already paid for the branch to check for the error in the document too, now they have to pay for branching up the stack. Exceptions strong part is that they cannot be implicitly ignored. One can do that with error types that force a read prior to destruction too though.

For short distance things, where one is handling the error state after the call, not throwing is fine.

Re: Is C++ Doomed?

#75
post #19

User finds bag of M&Ms difficult to open: "IS CANDY DOOMED?"

I'd compare C++ more to tobacco than to candy: it once looked like a good idea, but now its side effects are considered dangerous.

Re: Is C++ Doomed?

#76

C++ has its problems, but it has two advantages to other languages: (1) it is evolving and extensible at a deep level: one can identify strategies and create solutions based on the template system, because that's how the standard library itself is created. (2) it is backward-compatible, which means that we can continue to support the incredible amount of software already available for C and C++.

While that is true, this in turn means that the result is complex. You have old and new ways to do things, and new things are complex with all the integrations into the different parts.

Unified initialization sounds great, always use brace initialisation and be done, you think ... but no it's complex.

Or move semantics and universal(?) references are introduced to solve efficiency problems and make things nicer. For simple stuff it works, but oh the mess becomes wild.

How well modules will work out is still to be seen. Suddenly you need the build system to be a compiler and can't parallel build everything anymore, but have to create a dependency graph to build in order, while the standard treats that as a implementation detail.

C++ has some great features, however it would need a big cleanup, a cleanup which would break all code, worse than Python 2 vs. Python 3, in a world where other environments and languages are viable alternatives. Thus C++ can't afford the big jump.

Re: Is C++ Doomed?

#77
post #61

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 fro…

I 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.

Re: Is C++ Doomed?

#78

> That means you need to write code that wraps every possible resource in RAII logic. This is a great point. It means that you cannot mix C and C++ code without care, which seems like a huge design smell to me especially since this is not something that can easily be verified statically. Using C++ with exceptions disabled is the only foolproof way to run it in a large heterogenous application.

> Using C++ with exceptions disabled is the only foolproof way to run it in a large heterogenous application.

Is there a way for a ctor to report failure in newer C++ standards or are exceptions still the only way[1]?

[1] https://www.yosefk.com/c++fqa/exceptions.html#fqa-17.2

Re: Is C++ Doomed?

#79
post #32

I'm no C++ expert. But Wouldn't a private constructor and a static method that returns nil if input is bad fix this problem? Joshua Kerievsky talks a bout this problem in his book [Refactoring to patterns]( https://www.programmingbooks.dev/#refactoring-to-patterns ), specifically the refactoring "Replace Constructors with Creation Methods" That is maybe beside the point of the articles argument he is making about C++…

Then you can't allocate the object in-place (e.g. on the stack), and also you have to ban copy assignment/construction. Probably a more common solution is like what STL's own fstream does - don't throw an exception on construction, and have a "not valid" state.

Re: Is C++ Doomed?

#80
post #22

> Let’s say I want to know if a constructor failed This seems like the beginning of a bad situation. I mean, this shows why constructors that do any complex work that can error out are a bad idea.

No, they're fundamental to how C++ is idiomatically used. "Resource acquisition is initialization". This means that, if you have an object, and creating that object can fail, then it should fail in the constructor. So you either have a valid object, or none at all - you never have an invalid object. Now, you could squint and say that an optional returned from a factory is a valid object; that is, it's a valid optiona…

How is a factory function not idiomatic? It's not as if C++ is a single paradigm language that encourages a singular style or paradigm like OO.

RAII is a mess in certain circumstances (looking at you, Vulkan API) and sometimes straight up just doesn't work anyway.

If your initialisation is prone to failure, don't do it in a ctor.

Post reply on HN