3 ms·
You are assuming that a missing item is a normal (as in "not exceptional") case, but that is entirely application-dependent. But then, the article doesn't give
by moring 4y ago
You are assuming that a missing item is a normal (as in "not exceptional") case, but that is entirely application-dependent. But then, the article doesn't give any context either -- it just throws an exception in every variant of the code, so the most likely assumption here is that missing items are exceptional.
- qprofyeh 4y agoTo be honest, the example given (a "read" method that wraps direct access and raises a custom exception) does not inspire confidence that the item is expected to be there more often than not. There's certainly too little context to assume anything. Expected or unexpected, either way there are two paths; I would return a Result/Option type.
- BoorishBears 4y agoExcept the article quite literally say None is an option, except <insert not great reasons>. That wasn't an assumption on my part. If the missing item wasn't exceptional they would have just said that. - Also if even if it were exceptional, you'd still served extremely well by a Result type. Instead of just guessing where the landmine is sitting the type system can help you. Python explicitly opted out of type hints for exceptions to avoid a Java-style "checked exceptions" world.