>>28It forces you to handle the end of list case
A C compiler could also produce various NULL-related errors. I could give you that C doesn't have the types to cope with some situations and the compiler would probably have to emit a lot of useless errors.
it also prevents you from checking more than once
Really?
How is your code structurally different from, say, this C code:
if(result != NULL)
...;
else
...;
?
And 'forgetting' the NULL-check here is almost impossible when it's a linked list traversal (as was implied), since pretty much the first test run of such code would show absence of a NULL check. And when you don't test at all, Rust isn't gonna help you, either.
But let's go a little deeper here and imagine I wrote a list iterator for C. Would the issue still be there? Well, probably not because Rust did the exact same thing: they shifted the security check from the programmer to the library implementor. Forgetting to make it an
Option
in Rust is the exact same logical error as forgetting the
NULL
-check in C, except that the C style has to be done by the programmer, not the implementor.
And that leads us to a real C issue: lack of a high level library for things such as ADTs. But to be honest I'm not even sure that's really one of C's weaknesses: a lot of langs have come and gone and tried to fix this (probably starting with Java) and none of them replaced C. Not even C++, even though a lot of people claim that it's just a 'better' C.