jargon

Comparison

Option typevsResult type

Option type

the type says the value might not be there, so you cannot use it without saying what happens when it is not.

A type with two cases — a value or nothing — making absence explicit and forcing the caller to handle it. It is the type-system answer to the null reference, and it differs from a null object in being visible rather than invisible: an option makes the caller decide, a null object silently does nothing. Its cost is ceremony in a language without pattern matching or a decent option API.

Full entry →

Result type

the failure came back as a return value with the reason attached, and no exception was ever thrown.

A type with a success case and a failure case carrying an error value, making a failure part of the signature. It makes the possible failures visible and forces them to be handled or explicitly passed on, where an exception is invisible and travels until something catches it. The trade is that errors have to be threaded through by hand, which is what railway-oriented programming is a technique for.

Full entry →

Related comparisons