2 ms·
You can get all these benefits and not have any of the downsides if you have something like Result or Either, which requires generics. You only really compare G
by leshow 6y ago
You can get all these benefits and not have any of the downsides if you have something like Result or Either, which requires generics. You only really compare Go's solution against exceptions. That's not the only solution that exists.
- stefanchrobot 6y ago...or pattern matching in case of dynamically-typed languages: case some_operation() do {:ok, result} -> # do something with result {:error, error} -> # handle the error end
- leshow 6y agoYou lose the ability to make sure you've handled an error AOT, but sure, this feature is pretty much the same as a sum type except that it's structural. When I used to write typescript, there were plenty of times I was happy to have it's union types!