Comment

Comment by williamdclt

as so often, the really preferable solution would be to make it impossible to code the wrong thing from the start:

    - a sum type (or some wrapper type) `number | DIVISION_BY_ZERO` forces you to explicitly handle the case of having divided by zero
    - alternatively, if the division operator only accepted the set `number - 0` as type for the denominator you'd have to explicitly handle it ahead of the division. Probably better as you don't even try to divide by zero, but not sure how many languages can represent `number - 0` as a type.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton