News for hackers. Stuff that matters.
Re:Is C++ Doomed? by bodhiandphysics on Wednesday February 23, 2022 @04:17PM (#30446591)
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.

Re:Is C++ Doomed? by bodhiandphysics on Wednesday February 23, 2022 @04:22PM (#30446634)
Finanally, c++ is the only language I would ever want to do linear algebra in, or for that matter, many graph algorithms. Rust is adding features to make it useful for linalg, but it’s not their yet. Linear algebra is important!
Re:Is C++ Doomed? by MetricExpansion on Wednesday February 23, 2022 @11:13PM (#30450174)
Perhaps syntactically C++‘s operator overloading can make it quite palatable, but C and C++’s unique aliasing rules would mean that a naive implementation could leave performance on the table. There’s a reason it’s almost always Fortran at the bottom of the stack in most LinAlg codes in most languages.
Re:Is C++ Doomed? by chrisseaton on Wednesday February 23, 2022 @04:23PM (#30446657)
> Finanally, c++ is the only language I would ever want to do linear algebra in

Isn't something like MATLAB better for linear algebra than C++?

Re:Is C++ Doomed? by bodhiandphysics on Wednesday February 23, 2022 @04:30PM (#30446732)
Low level linalg... implementing solvers using openmp and CUDA
Re:Is C++ Doomed? by Jtsummers on Wednesday February 23, 2022 @04:29PM (#30446728)
Or Fortran or Julia.
Re:Is C++ Doomed? by bodhiandphysics on Wednesday February 23, 2022 @04:34PM (#30446797)
I don’t want to use Fortran! Julia is lovely
Re:Is C++ Doomed? by beached_whale on Wednesday February 23, 2022 @04:46PM (#30446969)
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? by 3836293648 on Wednesday February 23, 2022 @07:13PM (#30448597)
Exceptions as a concept weren't a mistake, but their specific details and implementation absolutely is.
Re:Is C++ Doomed? by beached_whale on Wednesday February 23, 2022 @07:58PM (#30448979)
I am curious, what would you change?
Re:Is C++ Doomed? by edflsafoiewq on Wednesday February 23, 2022 @04:31PM (#30446744)
Rust has the same exception safety issues. Eg Vec::retain_mut: https://github.com/rust-lang/rust/blob/532d3cda90b8a729cd982...