The one feature that the proposed Kotlin error types share with Java checked exceptions is that they can be collected in unions. However, the union feature for checked exceptions is pretty much useless without the ability to define higher order functions that are generic over such unions, which is why checked exceptions fell out of favor with the spread of functional APIs in Java 8.
Checked exceptions only make sense for errors that are relatively common (i.e., they aren't really exceptional), which calls for a different implementation entirely where both the happy path and the error path have around the same cost.
This is what modern languages like Rust and Go do as well (and I think Swift as well though don't quote me on that) where only actually exceptional situations (like accessing an array out of bounds) trigger stack unwinding. Rust and Go call these panics but they are implemented like exceptions.
Other errors are just values. They have no special treatment besides syntax sugar. They are a return value like any other and have the same cost. As they aren't exceptional (you need to check them for a reason), it makes no sense to use the exception handling mechanism for them which has massively skewed costs.
Depends on the software, huh.
I don't know about Rust, but a very important difference between Java exceptions and Go panics, is that a Go panic kills the entirely process (unless recovered), whereas a Java exception only terminates the thread (unless caught).
It's a little off-topic, but I wanted to clarify that for passer-bys who might not know.
Once they’re the standard error method then case every function has to intertwine branching for errors paths vs normal paths. Often the compiler has to generate unique code or functions to handle each instance of the Result type. Both add to code size and branching size, etc.
It’s because JB intends to make money on their investment, unlike the other two. This is the reason why Kotlin ecosystem is a half baked mess – JB tries to artificially replicate all successful ecosystems without having a community.
Seems to me like Kotlin Multiplatform has been quite successful actually. The weakest part is Kotlin/Native where they could have just used GraalVM Native Image but I talked to the Kotlin team about that at the time and it was more of an opportunistic move than anything else - a compiler team in St Petersburg had been let go by Intel and JB could acquire the whole team cheaply.
The Android ecosystem became Kotlin ecosystem because Google said so, not because it was successful. There was a small hype around Kotlin during 2016, because: cool lambdas! type inference! extension functions! null-aware by default! And all the other small improvements, but ultimately it was Google pushing Kotlin down the throat of everyone that made it "official".
Oracle v Google beef, Java moving at a snails pace, lack of mobile focus, all of this were far more major contributors than Kotlin's language features. And of course those who were screaming at the top of their lungs that Java will catch up and overtake Kotlin were right.
> The multiplatform stuff came out of organic demand for re-using code at first between JVM backend and browser (Kotlin/JS), and then for re-using code between JVM, JS, Android and sharing the business logic on iOS, and then finally for being able to reuse UI code on iOS too for cases where native Swift UI can't be justified (obscure apps, etc).
The multiplatform stuff came out because JetBrains understood that being Android-only is a death march for their language. And you can't monetize Android developers, they use free Android Studio. Kotlin/JS is dead in the water, there's literally no reason to use it and even JetBrains themselves scaled down their investment dramatically into it. The only main target they set for themselves was capturing iOS market when they saw Flutter literally consuming the niche with outstanding dev experience despite mediocre language at the time (Dart).
> Seems to me like Kotlin Multiplatform has been quite successful actually.
By which metric?
> where they could have just used GraalVM Native Image
On iOS?
> The Android ecosystem became Kotlin ecosystem because Google said so, not because it was successful
This is not how I remember events unfolding. I used Kotlin before Google ever talked about it and it was doing fine as a language for desktop and backend JVM apps. When Google started officially supporting it, it was just recognizing that Android developers were already organically adopting it at scale.
Which leads me to: why is Kotlin implementing this in a non-JVM compatible way, instead of introducing checked exceptions with better language support? All the problems stated above can be avoided while keeping the core idea of checked exceptions, which seems to be the same as this proposal.
From the GitHub discussion, I see this comment (https://github.com/Kotlin/KEEP/discussions/447#discussioncom...):
> The difference between checked exceptions from java and error unions in this proposal is how they are treated. Checked exceptions are exceptions and always interrupt the flow of execution. On the other hand, errors in this proposal are values and can be passed around as values or intentionally ignored or even aggregated enabling the ability to use them in async and awaitAll etc.
But is this a real difference or something that can be emulated mostly syntactically and no deeper than Kotlin's other features (e.g. nullables, getters and setters)? Checked exceptions are also values, and errors can be caught (then ignored or aggregated) but usually interrupt the flow of execution and get propagated like exceptions.