TheSilentDrifter on Nostr: Using `.unwrap()` is not "bad," per se. It is just frequently misused. Utilizing ...
Using `.unwrap()` is not "bad," per se. It is just frequently misused. Utilizing something like `match` or `if let` provides a more idomatic way of handling both expected and unexpected error-cases without causing your application to come to a grinding halt. One such example includes needing it to exit, but wanting to clean up artifacts. Another is creating and handling abstracted error types. Regardless, a good rule of thumb is only to use `.unwrap()` when you anticipate the desired failure outcome should be a panic.
Published at
2024-07-02 15:00:19Event JSON
{
"id": "f3fdea7224cf10d516471edb451f035d3464f65a2bfb234c8f5627bc76a23cc5",
"pubkey": "eb7246eb8e26b0c48dd4f9c2a822a0f4d5c84138937195090932b61a2d756051",
"created_at": 1719932419,
"kind": 1,
"tags": [
[
"e",
"24e80ccfc0320a258e45eeb0c2634fd77e18e9db667fa542d3364856031b58fb",
"",
"root"
],
[
"p",
"85d66f61ea7857db2a7216cea6f1004db9b73cd6b7f73201c079b8761ce1b87e"
]
],
"content": "Using `.unwrap()` is not \"bad,\" per se. It is just frequently misused. Utilizing something like `match` or `if let` provides a more idomatic way of handling both expected and unexpected error-cases without causing your application to come to a grinding halt. One such example includes needing it to exit, but wanting to clean up artifacts. Another is creating and handling abstracted error types. Regardless, a good rule of thumb is only to use `.unwrap()` when you anticipate the desired failure outcome should be a panic.",
"sig": "a3f6916df61eaa1f3b06dc4aa7c5ed543e2bce09cb6972d50415a7ecec0b614349066cfcbeed969508b5426c98f2846cb9584591e44bf6122a41048a78bee1d8"
}