3 ms·
I'd say that Rust (and, to a smaller extent, Zig, and, AFAICT, Ada) allow to write code that is guaranteed to not allocate, and define the exact memory layout o
by nine_k 5y ago
I'd say that Rust (and, to a smaller extent, Zig, and, AFAICT, Ada) allow to write code that is guaranteed to not allocate, and define the exact memory layout of certain structures, all while offering much tighter protections than C.
Of course, there are things that cannot be expressed in safe code in either language. But marking fragments of code as unsafe, where C-like unconstrained access is allowed, helps a lot to minimize such areas and make them explicit.
There is definitely room for a more expressive and safe languages in the kernel-level space. We can look at Google Fuchsia or maybe at Redox OS, both are very real operating systems trying to use safer languages, with some success.
- zdragnar 5y agoI think stability plays a big role in C continuing to remain dominant. Rust and Zig arent there yet, and wrt Rust in particular the ownership model doesn't play nearly as nicely in non-deterministic environments (taking far more code to deal with hardware such as an external display or printer that might, for example, get randomly unplugged at any point in time works against the grain of a static memory ownership analysis).
- nine_k 5y agoI'd say it's a good example why more static checks like lifetimes are useful. With them, you can at least tell apart data structures that are fleeting and can disappear when a cable is ejected, and those which should stay put. This likely might help avoid another double-free or another freed pointer dereference.
- zdragnar 5y agoYou may be interested in this: https://way-cooler.org/blog/2019/04/29/rewriting-way-cooler-in-c.html https://way-cooler.org/blog/2019/04/29/rewriting-way-cooler-...
- int_19h 5y agoAda still has plenty of UB; it's just that the cases where it arises are usually more explicit.
- pjmlp 5y agoIf we don't adopt X because it doesn't solve 100% of the problems, then we will never improve.