Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I learned C++ and enjoyed it but never went too deep. I always enjoyed C more. There's also so many S tier codebases to read to learn C better like the original Dune game engine or Unix utilities.

Having dabbled a bit with Rust recently I can't see any strong reasons to use C++. The combination of strong functional programing inspired type system with performance seems unbeatable. Almost a perfect language.

I'm sure there must be some legacy reasons to use C++ though. Maybe Game Engines, embedded programing, some kind of other legacy tie in?



I switch between C++ and Rust at work. Honestly with modern C++20/23 a lot of the pain points are being fixed mostly by just copying Rust. If you make a new C++ codebase its possible to do it reasonably cleanly. But at this point I don't understand why you would make new software in C++.

Here are a bunch of C++ annoyances I can think of. Library/Package management is nonstandard. Headers are code duplication. The standard library changes depending on implementation and is almost undreadable. Weird behavior in the standard. People relying on undefined behavior without realizing. Use before assignment issues. Subtle ownership issues and memory leaking due to bad refcounts. Needing to make everything const instead of by default. Checking for exceptions in everything you call to ensure your code is noexcept. Unreadable errors when working in the standard library. Heavily OO code is basically tech debt. The LSP is not structural like in Rust where the definition is found by checking the AST. Navigation and codebase discovery is slow in C++ because of the poorer LSP.

Rust has first class explicit 'nostd' support whereas in C++ you need compiler specific flags to disable the std lib and its hard to make sure you did it right. So the embedded reasoning is silly to me.

Rust also has game engines like bevy but they are new. You could hook into godot scripting with Rust if you want. Low level audio is just as easy in Rust and you can do it cross platform with a single crate.

In general I think it's just legacy code and hesitancy to change.


Huge amount of legacy across many dimensions, not just apps written in it [1], like number of users, published and available knowledge / resources (books, courses, blogs, articles, videos, software libraries, etc.), high compatibility with another huge language (C), etc.

This is just software industry general knowledge, for those who have been there for more than a few years in the field. I am not even a proper beginner in it, because I have never used it much, although I had bought, read and to some extent, understood some classic C++ books, including by the language creator (Bjarne Stroustrup [2]), Scott Meyers [3], and a few others, earlier. I did have a lot of experience using C for many years in production, though, including on a successful commercial product.

[1] https://www.stroustrup.com/applications.html

[2]:

https://www.stroustrup.com

https://en.m.wikipedia.org/wiki/Bjarne_Stroustrup

[3] https://en.m.wikipedia.org/wiki/Scott_Meyers


C++ makes sense when you need low latency, but don't really care about correctness

So I believe gamedev will stay on C++ the longest

Game crashes with segfaults for 0.001% users? So what?


HFT perhaps?


I can see that.

On most metrics I've seen Rust is comparable on general speed.

Maybe if you're at the level where you've essentially writing portable assembly and are okay with lack of safety. You need to know exactly what is happening within the CPU, maybe on custom hardware.

I bet some defense applications would be in this category too, although for my own sense of self preservation I would prefer the Rust type system.


Rust would probably be a good fit for HFT, but as the field is so dominated by C++ is hard for another language to make inroads. Java managed to some extent.

I would expect a lot of unsafe though.


Ecosystem effects are definitely important to C++'s dominance in HFT, but it's also a domain where a lot of the guarantees Rust offers just aren't all that relevant. From a security perspective most code always runs in sandboxes accessible to only a select few whitelisted IPs. True, you don't want a segfault while you're in the middle of sending an order to an exchange, but most of those are pretty easily smoked out in simulation testing.


Yes, if you are receiving malicious data from the exchange, getting p0wnd is the least of your concern.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: