I must be missing the point here, because this feels like bad advice. Calls like `panic` and `expect` and `assert` are there to uphold invariants, i.e. to deal with things that should never happen unless there is a logic error that invalidates the assumptions you hold about your program. It means "if you got here, I (the programmer) probably fucked up badly".
If an operation is fallible, it should return an error type and make it the job of the caller to deal with that. Silently returning default seems like a disaster waiting to happen, ala On Error Resume Next (which indeed was a disaster to deal with).
Now if this panic handler, instead of silently continuing in release mode, invoked some sort of "save your work and restart" handler such that the user doesn't lose anything and the program would restart in a known-good state, that seems like it would be a sensible way of doing things.
piker•3h ago
Actually that’s a fair point that should be clarified. These would be in places where practically panicking cannot happen, so you be tempted to swallow the Error and continue. But they should only be used where recovering with Default is okay.
[I added a note [NOTE: this strategy should only be used where returning early or default would be obvious to the user and be consistent with the upstream handling of an Err or None value.]]
dafelst•3h ago
If an operation is fallible, it should return an error type and make it the job of the caller to deal with that. Silently returning default seems like a disaster waiting to happen, ala On Error Resume Next (which indeed was a disaster to deal with).
Now if this panic handler, instead of silently continuing in release mode, invoked some sort of "save your work and restart" handler such that the user doesn't lose anything and the program would restart in a known-good state, that seems like it would be a sensible way of doing things.
piker•3h ago
[I added a note [NOTE: this strategy should only be used where returning early or default would be obvious to the user and be consistent with the upstream handling of an Err or None value.]]