|
|
|
|
|
by ProstetnicJeltz
2324 days ago
|
|
We tried to use a result type in C# for cases like this. For example, we want to save an object, returning the updated object (on success), or an error on failure. Unfortunately in static languages this leads to an unholy amount of boilerplate: public Result<SomethingGood, SomethingBad> PerformUpdate(int goodThingId, UpdateForm form) {
...
return new Result<SomethingGood, SomethingBad>(error);
... return new Result<SomethingGood, SomethingBad>(obj);
} The type annotations were hell. Sometimes there were three cases we wanted to consider. We went back to using exceptions, and are keeping a keen eye on the new C# features. So ultimately - I agree with the author that throwing exceptions is fine, when things actually go wrong. It's also not that bad when things kinda went wrong, but sometimes the effort required to fix it isn't worth it. |
|
F# is a lot better at using result types. You don't even need to specify the return type.