Live data from Hacker News

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

news.ycombinator.com

11–20 of 42 posts

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

#11
If your project depends heavily on general purpose GPU programming, you might start one in C++.

This was the case for a project I am working on that was started in the last year. The interop features in rust (and other languages) are simply not as reliable as writing kernels directly in CUDA or HIP or even DPC++. You _can_ attempt to write the GPU code in C++ and call to this from $LANG via ffi, but if you want to preserve data structures and methods to work on both the host and device, its still easier to write it once in C++.

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

#12

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

Yes, this is all very interesting, I've found golang is significantly simpler to get up to speed on from a c-family based education (c/c++/java) so I'm curious if these teams were both proficient before starting the projects. (And 3rd party package comparisons come into play). Either way enough to keep an ear out as I'm sure with the wealth of python & js developers the language of choice will be promoted by their experiences/evolution (so suspect mojo will also be something to keep an eye on)

(Notably I've gone through this evaluation recently and landed on implementing my personal project in c++23 (using cosmopolitan if possible) mostly for the value of updating my c++ knowledge (and perhaps look into cuda))

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

#15

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

Yes, this is all very interesting, I've found golang is significantly simpler to get up to speed on from a c-family based education (c/c++/java) so I'm curious if these teams were both proficient before starting the projects. (And 3rd party package comparisons come into play). Either way enough to keep an ear out as I'm sure with the wealth of python & js developers the language of choice will be promoted by their ex…

>> I've found golang is significantly simpler to get up to speed on from a c-family based education (c/c++/java) so I'm curious if these teams were both proficient before starting the projects.

Coming from a similar background, I have found Golang to be a nice, more efficient replacement for Java because it works great for backend web services, middleware, etc. Go is easy to learn and brings most of what is needed in its standard library (similar to Java).

Rust's sweet spot is where C and C++ shine: performance critical, maximum efficency required software such as operating system components, device drivers, media applications, etc.

Rust does have a learning curve, but most of what it enforces are best practices: 1) multiple readers or one writer resource usage, 2) organizing code hierarchy into trees, 3) sane patterns for concurrency, etc.

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

#16

Rust doesn’t even have a real GUI library yet, let alone support from common game libraries. C++ supports a hundred times as many compilation targets and platforms.

>> C++ supports a hundred times as many compilation targets and platforms.

I would not want to be the one writing that CMakeLists.txt

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

#17
If you want to create any real-time graphics application (video games, game engines, CAD software, visualization, etc.), or do any sort of scientific computing / HPC. The graphics ecosystem in Rust is still too undeveloped to see adoption (for the graphics API people are converging towards WebGPU, but it's still no match to Vulkan / DX12 / Metal), same goes for any GPGPU computing. Rust is also currently lacking in desktop GUI development (though nowadays Slint is trying to catch up with Qt!)

And in the case of apps where objects can have very dynamic lifetimes (like game engines or CAD), the borrow checker wouldn't really help with you that much since you would have to manage these with reference counting or some other way anyway (ex. arena allocation + generational indices).

What Rust excels over C++ at this point is just sane defaults / less footguns (no uninitialized memory, bounds checking even in release mode) as well as some language niceties, but Rust has its own issues for pragmatic usage (slow compilation, lackluster libraries, cumbersome to interface with C APIs, ...)

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

#18

Rust doesn’t even have a real GUI library yet, let alone support from common game libraries. C++ supports a hundred times as many compilation targets and platforms.

Games would probably be the biggest, most common scenario where C++ isn't going anywhere any time soon.

More generally, if you need to use existing C++ or even C libraries, Rust is at best an awkward fit unless someone else has already built and is actively maintaining the necessary bindings.

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

#19

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…

This reads like having no more than passing familiarity, and no real experience with rust.

It (just like so many other languages) is fantastic for personal projects. Especially because you can target cross platform easily and get native performance.

Proclaiming any non-estoteric language is "almost useless to code in for personal or smaller projects" speaks volumes.

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

#20
post #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.

OP never said rust was a drop in replacement for java
Post reply on HN