logoalt Hacker News

Lvl999Noobtoday at 9:18 AM0 repliesview on HN

You don't. Assertions are assumptions. You don't explicitly write recovery paths for individual assumptions being wrong. Even if you wanted to, you probably wouldn't have a sensible recovery in the general case (what will you do when the enum that had 3 options suddenly comes in with a value 1000?).

I don't think any C programmer (where assert() is just debug_assert!() and there is no assert!()) is writing code like:

    assert(arr_len > 5);
    if (arr_len <= 5) {
        // do something
    }
They just assume that the assertion holds and hope that some thing would crash later and provide info for debugging if it didn't.