this post was submitted on 09 Mar 2024
1 points (100.0% liked)

Rust

5960 readers
1 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
top 15 comments
sorted by: hot top controversial new old
[–] [email protected] 0 points 8 months ago (2 children)

Dang. It seems like there is a lot of momentum around transitioning away from C/C++.

Is C++ going to be the new FORTRAN/COBOL/PERL in 30 years?

[–] [email protected] 0 points 8 months ago* (last edited 8 months ago)

It seems like there is a lot of momentum around transitioning away from C/C++.

There is. But it won't be fast, because of the humongous amount of existing C and C++ code. They won't disappear for a long time, it will just get less and less over time.

[–] [email protected] 0 points 8 months ago

Sign me the fuck up, I want to get paid absurd amounts of money to do basic stuff in a language I am already proficient in

[–] [email protected] 0 points 8 months ago (2 children)

At work, we started the c++ migration to rust doing the following:

  1. Identify "subsystems" in the c++ code base
  2. Identify the ingress/egress data flows into this subsystem
  3. Replace those ingress/engress interfaces with grpc for data/event sharing (we have yet to profile the performance impact of passing an object over grpc, do work on it, then pass it back)
  4. Start a rewrite of the subsystem. from c++ to rust
  5. Swap out the two subsystems and reattach at the grpc interfaces
  6. Profit in that now our code is memory safe AND decoupled

The challenge here is identifying the subsystems. If the codebase didn't have distinct boundaries for subsystems, rewrite becomes much more difficult

[–] [email protected] 0 points 8 months ago

Sounds like you're well on your way with a good process. The book Software Architecture: The Hard Parts is a pretty decent guide to breaking apart a monolith. It's not a 100% follow it to the letter guide IMO, but I think the overall approach makes sense. At each step you have to consider trade-offs instead of following any kind of dogma.

[–] [email protected] 0 points 8 months ago* (last edited 8 months ago) (1 children)

@varsock @Timely_Jellyfish_2077 out of curiosity, why use grpc in lieu of ffi?

[–] [email protected] 0 points 8 months ago* (last edited 8 months ago) (2 children)

I don't think I am well positioned to answer that question given my experience. Ill give it my best.

I believe the advantage of more abstraction of gRPC was desireable because we can point it at a socket (Unix domain or internet sockets) and communicate across different domains. I think we are shooting for a "microserves" architecture but running it on one machine. FFI (IIRC) is more low level and more about language interoperability. gRPC would allow us to prototype stuff faster in other languages (like Python or go) and optimize to rust if it became a bottleneck.

Short answer is, we are able to deliver more value, quicker, to customers (I guess). But I don't know much about FFI. Perhaps you can offer some reasons and use cases for it?

[–] [email protected] 0 points 8 months ago* (last edited 8 months ago)

@varsock rust has very good code generation for C (and sometimes C++ as well) headers via bindgen (https://github.com/rust-lang/rust-bindgen). This allows you to potentially make minimal changes to the code without have to refactor to use a new protocol on the legacy side, and has faster performance (benchmark to confirm), since there’s no serialization/deserialization step.

[–] [email protected] 0 points 8 months ago

FFI is just calling Rust directly from something else (or vice versa), and has pretty much no performance compromises. The main downside is potential safety implications at the FFI boundary (i.e. need to guarantee Rust doesn't release C++ memory or vice versa), but if you're already fine with gRPC performance penalties, you can just copy everything at the boundary and not worry about it.

It's basically the way Python native modules work, and can be used between any C-compatible languages.

[–] [email protected] 0 points 8 months ago (2 children)
  • We see no realistic path for an evolution of C++ into a language with rigorous memory safety guarantees that include temporal safety.
  • A large-scale rewrite of all existing C++ code into a different, memory-safe language appears very difficult and will likely remain impractical.

Tough spot to be in, but I'm glad there are more and more people calling out for a transition away from C/C++. One can only hope that Rust doesn't become the new C++ aka the garbage dump of programming languages. Every large player wanted to write C++ in their own way, so they added it to the language and now we have this... thing.

CC BY-NC-SA 4.0

[–] [email protected] 0 points 8 months ago

Unfortuately c++ interoperability is hard. I wouldn't write c++ without vector and other containers (templates). Or classes complete with inheiritance (rarely multiple) and thus name mangeling. I now have millions of lines of that stuff and it is hard to write anything else because it has to mix.

[–] [email protected] 0 points 8 months ago (2 children)

In the long run, I wonder if rust will spawn a family of new memory-safe languages.

[–] [email protected] 0 points 8 months ago (1 children)

I am also very interested in seeing what the next generation of Rust-inspired languages will look like, and not because I am dissatisfied with Rust today. Rust has significantly raised the bar of how a good programming needs to work and any new language in the systems programming area (and beyond) will inevitably be compared to it.

[–] [email protected] 0 points 8 months ago

Finally, the victory of the ML family is at hand! Just like RISC over CISC. It just took a long time.

[–] [email protected] 0 points 8 months ago

Statically typed, compiled, memory safe languages? I can live with that 👌

CC BY-NC-SA 4.0