3 ms·
I am rather fond of the jQuery style of chaining method calls, which doesnt work if methods return status codes. OTOH I dont like checked exceptions at all. M
by russell 15y ago
I am rather fond of the jQuery style of chaining method calls, which doesnt work if methods return status codes. OTOH I dont like checked exceptions at all. Mainly because development teams go overboard with an exception for every type of problem. I make a call to a subsystem and I immediately have to deal with half a dozen exception types so that I dont have to clutter up the signature of my method. Especially in other peoples code where the exceptions are just swallowed leaving behind "//TODO add logging".
The Either class looks like a reasonable alternative, although I would do it slightly differently.
Either<String> result = myMethod().
probably with a different.
result.getError();
would return some kind of error object
result.getValue();
would throw an exception if there were an error.
It looks promising. I think I will play with it in Java.
- masklinn 15y agoThe problem here is that you can't really statically check your stuff. With either and match completeness turned on, the compiler will force you to handle the error case, you have to "ignore" it very explicitly by doing nothing in its handling.