top | item 44134694

(no title)

growlNark | 9 months ago

> Embracing Resource Acquisition Is Initialization (RAII) makes C++ the safest, most productive and fun C++ has ever been.

This seems like an extremely low bar.

Anyway, what use is there for C++ in 2025 aside from maintenance of legacy codebases and game engines? Off-hand I'd say C++ programmers are twice as expensive as rust programmers for the same semantics, and then you're still stuck with a C++ programmer you need to figure out how to socialize with.

discuss

order

green7ea|9 months ago

Author here, I do prefer a language like Rust that makes all of this automatic but that isn't always an option. There are other parts of Rust that can be hard as well.

I wrote this article for a few friends who have recently started working with an existing, large C++ code base. Some industries like the video game industry have also stuck to C++ (they have their reasons).

A good programmer can work within the given constraints to make a useful program — sometimes, one of those constraints is the choice of language.

BoingBoomTschak|9 months ago

Once Qt is properly accessible in Rust, I think your claim will be a lot more realistic. This goes for other important C/C++ libraries (e.g. libavcodec, vips/ImageMagick, VTK) without a solid (maintained, documented, etc...) Rust interface.

tialaramex|9 months ago

Qt is a C++ kitchen sink library - perhaps it feels very important to C++ programmers but I can't imagine Rust people are looking forward to having more redundant types that do exactly the same thing as a type they've used for years but like, now with a Q in their name.

The fact that lists like yours so often end up being "Look at all these C libraries" ie not actually about C++ at all is revealing. It's an endorsement of Bjarne's position that he needed that C compatibility, decades later C++ alternatives remain unpopular but it also tells you that you're never going to raise the bar this way. C++ is not a route out.

AFAIK there is no equivalent of rustls-openssl-compat for C++. The knowledge that this library (OpenSSL) is trash never spurred any C++ programmers to do better and provide the same ABI but with a C++ implementation.

motorest|9 months ago

> This seems like an extremely low bar.

Is it, though? Most mainstream languages fail to support anything resembling RAII, at least as first-class support. Do you actually have an example of a language that does a better job at resource management than C++?

asyx|9 months ago

Rust simply because the constructor being a static method on the type that can return basically anything including optional and result types and copy / move semantics are handled very easily through macros instead of constructor / assignment operator overrides.

palata|9 months ago

Not that I agree with the condescending parent (e.g. "you're still stuck with a C++ programmer you need to figure out how to socialize with"), but...

> Most mainstream languages fail to support anything resembling RAII

Wikipedia says: "RAII is associated most prominently with C++, where it originated, but also Ada,[3] Vala,[4] and Rust"

> Do you actually have an example of a language that does a better job at resource management than C++?

They don't necessarily offer a pattern like RAII, but what about "try-with-resources" in Java, or "use" in Kotlin that goes with `AutoCloseable`?

And what about "using" in C#?

What about "defer" in Swift?

I find those simpler than RAII.

znkr|9 months ago

When I switched from C++ to a bunch of other languages, I missed RAII initially. However, I quickly learned that other languages just do it differently and often even better (ever had to check an error when closing a resource?). Nowadays, I think that RAII is a solution to a C++ problem and other languages have a better solution for resource management (try-with-resources in Java, defer in Go, with in Python).

tialaramex|9 months ago

Obviously a language with linear types is just better at this, such as Austral.

In terms of languages you'd actually deploy today Rust is better both at this narrow feature and more broadly.

pjmlp|9 months ago

Ada/SPARK, with better ergonomics than Rust, but its use will stay niche in high integrity computing.

oytis|9 months ago

Where are C++ programmers paid better than Rust programmers? I thought Rust salaries are being driven high by all the crypto/fintech companies + scarcity

bluGill|9 months ago

productivity counts not hours. If you can get the same work done faster then you cost to the company is lower even - possible even if your salery is higher.

though it isn't clear how much of rust's increased productivity is caused by being a new language where the architecture mistakes of the past decades are not slowing you down. We will need several more decades to answer that.

pjmlp|9 months ago

For one, the compiler and runtime implementation of the language you might happen to use, that that includes Rust.

flohofwoe|9 months ago

> stuck with a C++ programmer you need to figure out how to socialize with.

You're obviously trolling, but:

IME Rust attracts the same 'difficult' characters that are also attracted to C++ (because both are 'puzzle solving languages' instead of 'problem solving languages') the typical Rust coder may be even worse because of the missionary fervor and 'holier than thou' attitude.

oytis|9 months ago

Puzzle-solving languages are rather Lisp or Haskell. Both C++ and Rust are very practical for their problem domain.

ninkendo|9 months ago

> the typical Rust coder may be even worse because of the missionary fervor and 'holier than thou' attitude

Anecdata, but the number of times I actually encounter these missionary Rust coders (the RIIR types) is utterly dwarfed by the number of times I hear people complaining about them. The memes making fun of the insufferable rust evangelists are at least 10x as prevalent as the evangelists themselves.