Or even better, Haskell!
If you rewrote only part of a large C++ project in Haskell, is there a way to link it back in again?
https://stackoverflow.com/questions/3859340/calling-haskell-...
11–20 of 300 posts
Or even better, Haskell!
If you rewrote only part of a large C++ project in Haskell, is there a way to link it back in again?
https://stackoverflow.com/questions/3859340/calling-haskell-...
You can also rewrite to C++, OCaml, Go... Each language has benefits and drawbacks, and there is good reason for each them to exist. Would your project benefit a lot from algebric datatypes -> OCaml is a great fit! You want to port as soon as you can: C++ is your friend. You plan to write HTTPS service nodes: Go has the best standard library out there.
That changes the equation considerably, compared to something like Go where none of these benefits exists. For example, exporting code from Go not only requires the runtime and GC, there's also significant function call overhead because of the way Go maps goroutines to threads.
There are many other good languages, but few of them have these benefits. C++ is probably the option with the least amount of friction against C, but then you're also inheriting most of the unsafety of C.
It really is very straightforward to start inserting Rust into a C/C++ codebase. I did the Rust port of netcode.io[1] which started out by just calling C code for the portions that I didn't have working in Rust. Eventually the port was 100% Rust but I was really impressed with how seamless mixing C/Rust was.
Even now our unit tests run against the C code at a functional level so we know when the protocol diverges which lets us easily catch breaking changes from the reference C implementation.
Much like everything, don't apply an adage blindly and do a proper evaluation but I think if you're in the a space where memory or performance matters Rust is a very strong contender that plays well with existing ecosystems.
If you are really worried about the security of old C code, then the safest, most portable thing to do is re-write in modern C++. This is sane and doable in a short period of time. Rust is not.
Or just rewrite it in modern C. This is sane and doable in a short period of time. You just have to make sure it's modern C. (no true Scotsman)
What do you call modern C?
Or you know, why rewrite it at all? You could instead try and use a safe C implementation (such as gcc/clang with the sanitisers or something like https://staff.aist.go.jp/y.oiwa/FailSafeC/index-en.html), but to be frank if I was to rewrite my programs I would use a truly modern language like the ones that I mentioned above.
Earlier quoted context omitted.
If you rewrote only part of a large C++ project in Haskell, is there a way to link it back in again?
Call Haskell from C (not C++) seems pretty easy: - [Calling Haskell from C - HaskellWiki]( https://wiki.haskell.org/Calling_Haskell_from_C ) And the FAQ on the Haskell wiki directly addresses this too: - https://wiki.haskell.org/Introduction#I_already_have_a_large... . So apparently it is doable!
If you are really worried about the security of old C code, then the safest, most portable thing to do is re-write in modern C++. This is sane and doable in a short period of time. Rust is not.
A personal opinion from a person who loved C++ for quite some time, before diving deep enough to realize how dark is the abyss.
Not all security vulnerabilities are due to pointer arithmetic or out of bounds execution or pick-your-rust-is-better-idiom.
Heartbleed is a great example. It wasn't caused by an error with how C handles memory or strings or anything else. It was caused by failing to validate untrusted input. Rust isn't going to help you with that.
Could the affected parts be re-written in a way where the boundary checks would have worked? Yes. As they could have in C, C++, D, Fortran, or any number of other languages.
If memory safety and correctness was so truly valued above everything else, we'd be seeing a lot more Ada than we do today.
And this doesn't even cover the fact that not everything can be re-written in Rust, mainly due to compilation target restrictions.
Exasperated Edit: No, I'm not saying code should never be re-written. I'm not even saying that Rust is a bad tool if the decision to re-write is made. What I am saying is that Rust is not a silver bullet. Rust is not going to solve every problem ever. Rust is one of many choices for writing memory safe, C ABI compatible code.
The reasons provided by this article are insufficient to solely justify a re-write in Rust; the exact same arguments could be used as justification for rewriting everything in Ada. Or Haskell. Perhaps some thought will be put in the next "re-write everything in Rust" article that takes that into account.
Then again, none of the past articles have.
Earlier quoted context omitted.
Or just rewrite it in modern C. This is sane and doable in a short period of time. You just have to make sure it's modern C. (no true Scotsman)
> Or just rewrite it in modern C. This is sane and doable in a short period of time. What do you call modern C?