Hacker News new | past | comments | ask | show | jobs | submit login

Why not use C++?

For the most part, these aren't security critical components.

You already have a massive amount of code you can use like say llama.cpp

You get the performance that you do with Rust.

Compared to Python, in addition to performance, you also get a much easier deployment story.




If you already have substantial experience with C++, this could be a good option. But I'd say nowadays that learning to use Rust *well* is much easier than learning to use C++ *well*. And the ecosystem, even if it's a lot less mature, I'd say is already better in Rust for these use-cases.

Indeed, here security (generally safety) is a secondary concern and is not the main reason for choosing Rust, although welcome. It's just that Rust has everything that C++ gives you, but in a more modern and ergonomic package. Although, again, I can see how someone already steeped in C/C++ for years might not feel that, and reasonably so. But I think I can farely safely say that Rust is just "a better C++" from the perspective of someone starting from scratch now.


Indeed.

Plus, one doesn't usually just 'learn C++'. It's a herculean effort and I've yet to meet anyone, even people exclusively using C++ for all their careers, that could confidently say they "know C++". They may be comfortable with whatever subset of C++ their company uses, while another company's codebase will look completely alien, often with entire features being ignored that they used, and vice versa.

Despite that, it's still a substantial time commitment, to the point that many (if not most) people working on C++ have made that their career; it's not just a tool anymore at that point. They may be more willing to jump entire industries rather than jump to another language. It is a generalization, but I have seen that far too often at this point.

If someone is making a significant time investment starting today, I too would suggest investing in Rust instead. It also requires a decent time investment, but the rewards are great. Instead of learning where all the (hidden) landmines are, you learn how to write code that can't have those landmines in the first place. You aren't losing much either, other than the ability to read existing C++ codebases.


> But I'd say nowadays that learning to use Rust well is much easier than learning to use C++ well.

For someone(me) who was making a choice recently, it is not that obvious. I tried to learn through rust examples and ecosystems, and there are many more wtf moments compared to when I am writing C++ as C with classes + boost, especially when writing close to metal performance code, rust has many abstractions with unobvious performance implications.


> rust has many abstractions with unobvious performance implications.

such as?



Rust is much better than C++ overall and far easier to debug (C++ is prone to very difficult to debug memory errors which don't happen in Rust).

The main reasons to use C++ these days are compatibility with existing code (C++ and Rust are a bit of a pain to mix), and if a big dependency is C++ (e.g. Qt).


Additionally the industry standards on GPGPU APIs, tooling ecosystem.

Maybe one day we get Live++ or Visual Studio debugging experience for Rust, given that now plenty of Microsoft projects use Rust.


> Maybe one day we get Live++ or Visual Studio debugging experience for Rust

I don't know what Live++ is but the Rust debugging experience is already better than C++. In VSCode I can just click "Debug Test" next to a test and it magically all works. It's never that slick in C++, even in Visual Studio.


VSCode is a joke versus Visual Studio proper, try to do hot code reloading in Rust, dive into GPU, parallel debugging, trace points, this is the kind of stuff Live++ or VS offer.


Lots of reasons, but a big one is that dependency and build management in C++ is absolutely hellish unless you use stuff like Conan which nobody knows. In Rust, you use Cargo and everyone is happy.


There are lots of things I don't know until I learn how to use them, duh.

Cargo is great, for pure Rust codebases, otherwise it is build.rs or having to learn another build system, and then people aren't that happy any longer.


Build.rs is great on most cases. The important thing is that it's easy for users to download and build everything.


When everything is Rust. That breaks down otherwise.


You can always use something as simple as Make for your C++ proj with manually dumping dependencies to some libs folder.


That doesn't solve the problem of making it easy for people to download and build the dependencies.


The idea is that dev packages dependencies in lib folder, so when people retrieve sources, they also retrieve all dependencies.

But you are right, that this is some extra work for dev, so this is question of trade offs: do you want to deal with all C++ build tooling mess, or you are Ok to do some manual steps.

Another alternative is to use some popular stable linux distro as build platform, then many libs will be packaged as part of that distro.


Oh, you mean vendoring. Yes, you can do that, but there is no easy support for keeping those vendored dependencies in sync with upstream. And if you want really nice things like notifications when those dependencies have security updates that you need to apply --- forget it.


I've worked with C++ in the past, it's subject to taste. I like how Rust's rigidness empowers rapid change _without_ breaking things.

Besides, the ML ecosystem is also very mature. llama.cpp has native bindings (which Swiftide supports), onnx bindings, ndarray (numpy in Rust) works great, Candle, lots of processing utilities. Additionally, many languages are rewriting parts in Rust, more often than not, these are available in Rust as well.


Why use C++? What's the benefit over Rust here?




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

Search: