4 ms·
Genuine question: How to switch codes written in 2003 to Rust?
by rfoo 5y ago
Genuine question: How to switch codes written in 2003 to Rust?
- varajelle 5y agoMaybe this is not so much about switching individual existing projects to Rust, but about switching the "industry". Some new projects are still written in C.
- rfoo 5y agoYeah, this makes sense. I'm optimistic and would like to say we're already half-way there. From my PoV very few new projects were written in C in recent years, except those inherently-C (their purpose was to call some other libraries written in C, or libc) and/or embedded (code size and portability requirements).
- nix23 5y agoBy work? It's pure risk-management, do you need it? Is it worth the potential risk/work?
- howdydoo 5y agoSlowly and steadily.
- jandrese 5y agoThe same way you would write code written in 2021 over to Rust: by rewriting it from the ground up. Auto-translation won't work because Rust won't allow you to build it in the same way you would have built it in C. It requires a full up redesign of the code to follow the Rust development model.
- masklinn 5y ago> Auto-translation won't work because Rust won't allow you to build it in the same way you would have built it in C. That is not entirely true, but if you translate the C code to Rust, you get C code, in Rust, with similar issues (or possibly worse). Of course the purpose would be to clean it up from there on, but it's unclear whether that's a better path than doing the conversion piecemeal by hand. The C2Rust people certainly seem to think so, but I don't know if there are good "client stories" about that path so far, whereas the manual approach does have some (e.g. librsvg), though it's not for the faint of heart.
- lucb1e 5y ago> That is not entirely true, if you translate the C code to Rust, you get C code, in Rust, with similar issues (or possibly worse). thus it was basically true after all? Like, sure, Rust is turing-complete so you can simulate whatever C did and thus technically you can translate anything that C can do into Rust. But if it doesn't fix any problems, then have you really translated it into Rust?
- masklinn 5y ago> thus it was basically true after all? No? > Like, sure, Rust is turing-complete so you can simulate whatever C It's not simulating anything, and has nothing to do with turing completeness. > But if it doesn't fix any problems, then have you really translated it into Rust? Yeees? Unless your definition of "translated" has nothing to do with the word or the concept. You end up with a project full of rust code which builds using rust's toolchains. That sounds like a translation to me.
- saagarjha 5y agoThe jury's out on whether Rust code with unsafe around all of it is better than C. It's good that you can slowly reduce the unsafe, which is not something you can do with C, but the code is frequently harder to read and may have new bugs.
- masklinn 5y ago> The jury's out on whether Rust code with unsafe around all of it is better than C. The goal definitely isn't to keep it as is, the entire point of C2Rust is to provide a jumping point then not have to shuffle between the two as you perform the conversion.
- deleted 5y ago[deleted]
- masklinn 5y agolibrsvg 1.0 was in 2001. Federico Mena-Quintero started switching it to Rust in 2017 (well technically October 2016), the rewrite of the core was finished early 2019, though the test suite was only finished converting (aside from the C API tests) late 2020. So... carefully and slowly.
- rfoo 5y agoThanks, that's exactly what I'm seeking for. Before that I've never heard of projects which successfully did C to Rust transition, keeping its C API intact and could be used as a drop-in replacement. Glad to hear that there are already some success stories.
- JeremyBanks 5y agoNot quite the same, but maybe of interest: https://daniel.haxx.se/blog/2020/10/09/rust-in-curl-with-hyper/ https://daniel.haxx.se/blog/2020/10/09/rust-in-curl-with-hyp...
- deleted 5y ago[deleted]