4 ms·
There's more that it helps with. For one example Rust's Enums and richer types allow fewer mistakes -vs- confusion where pointers and integers degrade to a comm
by viraptor 5y ago
There's more that it helps with. For one example Rust's Enums and richer types allow fewer mistakes -vs- confusion where pointers and integers degrade to a common type. A random line: https://github.com/torvalds/linux/blob/122fa8c588316aacafe7e5a393bb3e875eaf5b25/include/crypto/aead.h#L283 https://github.com/torvalds/linux/blob/122fa8c588316aacafe7e...
> void crypto_aead_clear_flags(struct crypto_aead *tfm, u32 flags)
These are valid due to poor type usage, but make no sense:
crypto_aead_clear_flags(..., PAGE_SIZE)
crypto_aead_clear_flags(..., EBUSY)
crypto_aead_clear_flags(..., SOME_RANDOM_THING)
We can hope they would be caught in review if the code happens to do the right thing by accident, or use static analysis and hope it triggers in that case, or use a language with clearer types where it's much easier to use types preventing this issue.
- pjmlp 5y agoYou could the same with C++ or Ada, but naturally it will never be a thing in Linux.
- woodruffw 5y agoAda can do that, but C++ arguably makes things even worse than in C: apart from supporting a subset of C's misbehavior, it introduces implicit-by-default converting constructors. Those make API misuse very easy.
- pjmlp 5y agoExperience in Apple and Microsoft platforms, among others, shows otherwise. And for info, Android Treble drivers are mostly C++, although Java is also an option. Ah and Fuchsia is a mix of C++ and Rust at it lower layers.