← Back to context

Comment by bjackman

1 day ago

Rust only stops you crashing the process in the "oh, I didn't realise this field can be null" case.

It doesn't help with the "yes, in theory it can be null, but in practice it never will be" case. Once you write .expect() you are crashing the service just as badly as a dereference when your assumptions turn out to be wrong.

The point is the language forces you to explicitly handle the null. You have to make the choice. Using `expect`, the programmer would understand that that is equivalent to a panic. Why would they intentionally panic?