DEV Community

Discussion on: Thoughts on Rust at First, but then Ramblings on Top Programming Languages

Collapse
 
aloneguid profile image
Ivan G

Well no, I'm not a Rust expert but surely have experience with Rust. And I don't dislike it, quite the opposite! I think Linux is in "wait and see" game with Rust, considering to allow writing new mom critical code. It's not there yet though and I can't imagine it will be for at least 5 years. It just doesn't have enough support for variety of platforms C does. Unless you abandon majority of them like Neovim did, it might work. I wouldn't personally even try to do that.

Rust is new and seems shiny and simpler but as you mentioned yourself a lot of it already shows the age. Necessity to wrote unsafe code and battling with borrows checker is far from perfect experience. C++ allows you to have a borrows checker mechanism, custom garbage collector and whatever else you need, it's a matter of agreeing on style. Sure you can write unsafe code and screw up big bit so you can with Rust as well. ABI between C and Rust is just not there and is so painful it's not worth it. Mixing two is a bad idea.

Collapse
 
tsturzl profile image
Travis Sturzl • Edited

I disagree quite a bit. The default for C++ is unsafe, the default for Rust is safe where you explicitly define something as being unsafe. You can argue that as a semantic difference, but I truly think it changes the way people actually write and think about code. C++ lacks any kind of synonymous solution to the Send/Sync traits (that I'm aware of) which avoid a multitude of threading issues. I agree that C++ has implemented many of the features of Rust, it doesn't feel fully there yet, but I'm consistently impressed with the feature set of C++ every time that I come back to it. As someone who spends a good amount of time doing system programming in Rust I will tell you the FFI between C and Rust is absolutely serviceable and dare I say even pretty damn good. I'm really curious what your exact criticisms of it are. The compatibility between Rust and C++ is a bit more painful. However dealing with the C from Rust isn't really that difficult or confusing, nor is vice versa. In fact you can generate complete wrappings to C libraries with the bindgen tool. Mixing C and Rust works fairly well in my experience, and using Rust code from C is a lot nicer than comparatively using a C++ library from C. In fact once again you can use bindgen to do all the work for you and have it generate the C and C++ header files so you can easily write a Rust library that can be used from C or C++, the same is certainly not true for C++.

Honestly Rust's generics vs C++ templates is enough to convince me these days to opt for Rust in many cases. That said it seems like pointing out that Rust will someday age and be filled with quirks and rough edges is a strange argument. It's like saying my current car is old and doesn't start in the cold, and I shouldn't buy a new car because it'll someday be old and not start in the cold. It's kind of a bad argument to say not to embrace new technology because new technology is destined to be old eventually too. That seems like a bit of a fallacy.

Nonetheless I think your article still does a great job outlining how modern C++ can compare to Rust, and how it has made the effort to stay up to date. I don't think C++ is going anywhere soon, but I do think Rust will continue to grow in this space for good reason.

Thread Thread
 
3nd3rm4n profile image
3N3D3M4N • Edited

Coming from a security background, I can tell you that there is a provision for writing secure code in every programming language. It's the same argument people use to make for PHP in 2000s that PHP is bad. No Sir, PHP is not bad, It's just that whatever you are writing using PHP is bad.
I think a programming language should solve Engineering problems not academic problems. Rust will a hobby language for a long time. If you wanna create a todo app for your college project you can go with rust but if you wanna create a production ready CRM application, forget about using Rust.
World is running on C++,Java,C# right now. Because there are people who can develop secure code.

Thread Thread
 
tsturzl profile image
Travis Sturzl • Edited

That's objectively false. Rust is what Amazon is using Rust for 2 major hypervisors. They use it for Nitro which is EC2's main hypervisor now, and firecracker which is the hypervisor that backs all of AWS Lambda workloads. These are basically the backbone of their 2 most critical compute services. These aren't academic or hobby projects. You're comparing apples to oranges, no one is writing CRMs in C++ and Rust wouldn't be a good choice either. Plus CRMs are just outright bad examples of what a system language is useful for, because a CRM is just pure business logic, you're better suited that gives you high level representations of business logic (Java, C#). I know several companies using Rust for embedded on production robotics systems now (hint, I'm one of them). The world is running about 700 languages right now, the world is running COBOL that's not necessarily a strong endorsement for the use of COBOL.

Like you said there is a "provision for writing secure code in every programming language", and the reality is that doesn't really start or end at language semantics or idioms. A decent C++ developer who is also proficient in Rust should have a pretty good idea what's going on in either language with a similar understanding. Having a more pedantic compiler only serves as a benefit. Don't take my word for it go look at what the industry is doing. They're writing critical pieces of system software in Rust at many large companies, they're writing firmware, control systems, and databases in Rust. I'd urge you to do some more research.