3 ms·
> It's not a normal thing for code that needs that record that wasn't found. In many popular programming languages, the way to check whether some value has a c
by baddox 7y ago
> It's not a normal thing for code that needs that record that wasn't found.
In many popular programming languages, the way to check whether some value has a certain property is with an “if” statement. It would be very odd to replace every code path inside an “if” statement with exception control flow simply because that code path “needs” some condition to be met for it it to execute.
- erik_seaberg 7y agoIf a user doesn't exist, any code that relies on having a user is broken, and I want a guarantee that code can't be reached. Throwing does that, mapping an Option does that, but "if" doesn't.
- baddox 7y agoThat's just a matter of a specific language's syntax, type-checking, or linting. Pattern-matching in OCaml [0] will in most cases warn about non-exhaustive checks. It seems like TypeScript has something similar, although I haven't used it [1]. [0] https://www2.lib.uchicago.edu/keith/ocaml-class/pattern-matching.html#nonexhaustive https://www2.lib.uchicago.edu/keith/ocaml-class/pattern-matc... [1] https://dev.to/babak/exhaustive-type-checking-with-typescript-4l3f https://dev.to/babak/exhaustive-type-checking-with-typescrip...