3 ms·
I've always thought of Java as being extra verbose, in part because there's try catch blocks everywhere.
by fxtentacle 7y ago
I've always thought of Java as being extra verbose, in part because there's try catch blocks everywhere.
- mjevans 7y agoI've thought of it as being extra tedious.
- tsimionescu 7y agoWherever there is a try/catch block in Java, you would have at least a few if err return/goto cleanup in C/Go/other error-code languages. This is especially true when you have a function which performs multiple operations that return the same kind of error (e.g. multiple HTTP calls, or multiple file-based operations). In general, in Java you need a single try/catch block for all of these (which may well be in another function), but you need an if err return for each one in C. Rust has a more interesting approach, where the sue of Macros gets rid of the verbose if-based pattern, but the code also avoids non-local return. I haven't written Rust yet, but it seems like a very interesting approach.
- erik_seaberg 7y agoA lot of try blocks are only there because stdlib declared a lot of interface methods that forbid checked exceptions, requiring everyone to smuggle them out. This nonsense just goes away in Scala and Kotlin.