Live data from Hacker News

Ask HN: Why would you ever use C++ for a new project over Rust?

news.ycombinator.com

1–10 of 42 posts

Ask HN: Why would you ever use C++ for a new project over Rust?

#1
Was having this debate with a coworker recently who’s a Rust fanatic and prior C++ eng; he said the tooling and support has gotten so good you would just be shooting yourself in the foot if you ever started something new on C++. I wasn’t convinced but is this really the case? Like if you had equal skill in both, is there ever a case for doing a project in C++ (outside of being forced by the platform you’re working on or anything outside your control)?

Re: Ask HN: Why would you ever use C++ for a new project over Rust?

#4
>> is there ever a case for doing a project in C++ (outside of being forced by the platform you’re working on or anything outside your control)?

No.

That is part of the reason why so many big companies (Google, Microsoft, Amazon, etc.)[1][3][4] are pushing ahead on Rust adoption and large government agencies[5][6] are recommending memory safe languages over C and C++.

Google did a study and found that their Rust developers were twice as productive as their C++ developers [2].

Rust should be preferred over C++ unless you have no other choice.

[1] https://thenewstack.io/google-spends-1-million-to-make-rust-...

[2] https://www.theregister.com/2024/03/31/rust_google_c/?td=kee...

[3] https://www.theregister.com/2024/01/31/microsoft_seeks_rust_...

[4] https://blog.qwasar.io/blog/why-is-rust-growing-and-why-do-c...

[5] https://www.nsa.gov/Press-Room/Press-Releases-Statements/Pre...

[6] https://www.whitehouse.gov/wp-content/uploads/2024/02/Final-...

Re: Ask HN: Why would you ever use C++ for a new project over Rust?

#6
The best way to think of Rust as essentially the new Java, which sort of "won" over C++ due to its more strict syntax with mandatory OOP and code patterns. Rust enhances this by running most of the checks in the compiler so you get native code, with very few runtime additions for type safety.

But just like Java, its almost useless to code in it for personal or smaller projects.

For almost all of my projects where I needed performant code, the way I would do this is write it in C, and then just call the code from Python or Node. Its much easier to just focus on low level performant C code that can be written in usually one file, and then just write all the interface to it through higher level languages, especially for web frameworks.

Re: Ask HN: Why would you ever use C++ for a new project over Rust?

#7

The best way to think of Rust as essentially the new Java, which sort of "won" over C++ due to its more strict syntax with mandatory OOP and code patterns. Rust enhances this by running most of the checks in the compiler so you get native code, with very few runtime additions for type safety. But just like Java, its almost useless to code in it for personal or smaller projects. For almost all of my projects where I n…

Interesting, haven’t heard this viewpoint before of Rust being a drop in replacement for Java. From my limited experience with Rust it felt like the learning curve was way steeper than when I was learning Java for my previous job. Good point on C though, one of my old CS instructors would always call C his swiss army knife since its so small he had practically the entire syntax in his head.

Re: Ask HN: Why would you ever use C++ for a new project over Rust?

#8

>> is there ever a case for doing a project in C++ (outside of being forced by the platform you’re working on or anything outside your control)? No. That is part of the reason why so many big companies (Google, Microsoft, Amazon, etc.)[1][3][4] are pushing ahead on Rust adoption and large government agencies[5][6] are recommending memory safe languages over C and C++. Google did a study and found that their Rust deve…

Thanks for all the sources! Especially surprised on the Google one, used to work there and remember hearing that considerable parts of Fuchsia (https://en.m.wikipedia.org/wiki/Fuchsia_(operating_system)) were written in Rust but didn’t know they were also conducting studies across the org about how much more productive eng were with it. Pretty cool

Re: Ask HN: Why would you ever use C++ for a new project over Rust?

#9
post #3

From Chandler Carruth who leads the C++, Clang, and LLVM teams at Google: https://github.com/carbon-language/carbon-lang/blob/f9ce0b19...

“Existing modern languages already provide an excellent developer experience: Go, Swift, Kotlin, Rust, and many more. Developers that can use one of these existing languages should. Unfortunately, the designs of these languages present significant barriers to adoption and migration from C++.”

Hadn’t heard of Carbon, very cool. Super telling line with the “Developers that can use one of these existing languages should.” Thanks for sharing!

Re: Ask HN: Why would you ever use C++ for a new project over Rust?

#10

The best way to think of Rust as essentially the new Java, which sort of "won" over C++ due to its more strict syntax with mandatory OOP and code patterns. Rust enhances this by running most of the checks in the compiler so you get native code, with very few runtime additions for type safety. But just like Java, its almost useless to code in it for personal or smaller projects. For almost all of my projects where I n…

> But just like Java, its almost useless to code in it for personal or smaller projects.

That's entirely the opposite from my experience. Rust is a pleasure to code in for personal projects once you're familiar with the language, especially compared to C/C++. Managing dependencies is more straightforward, and there are a lot of crates out there to make writing your project easier.

Post reply on HN