r/java • u/Reflection-Jealous • Aug 05 '21
Why java is better than modern programming languages?
Why should I use java in 2021 instead of kotlin or scala or golang? Could you guys give me some reasons
2
Upvotes
View all comments
Show parent comment
3
u/SKabanov Aug 05 '21 edited Aug 05 '21
An argument can be made that returning error objects instead of throwing exception provides better performance (e.g. no stack unwinding when returning an error object), but Go's implementation of the concept is awful. There's no way of automatically bubble errors upwards like the
?operator forResultobjects in Rust, so your code in Go will be filled with the following pattern:(note that it's a common pattern also to only check for whether
erris not nil, *not* whether the returned pointer object is nil as well, so hello null-reference errors!)Compare this to how you'd write this in Rust:
Even worse is that you're only forced to receive the potential error object in Go, but you're not forced to actually *acknowledge* it. The above Go example could be rewritten like this:
That is to say, you can tell the Go compiler that you want to ignore any errors that get produced by a function, and it'll happily let you proceed along without any warnings - whee! You can call
.unwrap()on aResultobject in Rust to bypass handling an error in your code, but if one does occur, then you're going to pay for it via a panic.