News for hackers. Stuff that matters.
Re:From Rust to TypeScript by baq on Saturday September 12, 2020 @12:20PM (#24453530)
Checked exceptions are evil because they can cause transitive API breakage in cases a function or method doesn’t catch because it can’t or shouldn’t handle the condition.
Re:From Rust to TypeScript by kibwen on Saturday September 12, 2020 @12:49PM (#24453704)
Since this thread is also about Rust, and since I mention in another comment about how Rust libraries define their own error types, I should mention that Rust can avoid this problem by the combination of 1) adding a new way that a function can error only requires adding a new case to the library's error enum, leaving the function's type signature unchanged, 2) adding new cases to the error enum can be kept from being a breaking change via the use of the non_exhaustive attribute, which requires anyone manually handling the error to add a default case even if they handle all the other existing cases. Of course, if library consumers are just throwing a panic in that mandatory default case then you might be trading a compiler error for a runtime error, which can be controversial. The language design challenge of this decade is finding compromises between allowing libraries to change and evolve while mitigating the disruptiveness to downstream consumers.
Re:From Rust to TypeScript by flowerlad on Saturday September 12, 2020 @01:52PM (#24454139)
Sorry that doesn't make any sense to me. If a method can't or shouldn't hand a condition it then it needs to declare itself as throwing that exception (or a wrapper around it).
Re:From Rust to TypeScript by withinboredom on Saturday September 12, 2020 @02:45PM (#24454477)
They said transitive. To me, they meant if you have 3 layers of deps, A -> B -> C and C now throws something, B doesn’t catch it or mark as throws. So now you have a failure. Obvs, you’d fix this immediately, but it’s still work that you have to do when you could have been doing something productive.
Re:From Rust to TypeScript by ddek on Saturday September 12, 2020 @05:34PM (#24455980)
Here's Hejlsberg on why C# doesn't have checked exceptions: https://www.artima.com/intv/handcuffs.html.
Re:From Rust to TypeScript by flowerlad on Saturday September 12, 2020 @06:16PM (#24456348)
Hejlsberg is an awesome compiler maker. His Turbo Pascal compiler was incredible -- in approx 30KB he wrote a compiler, full screen editor and library. He's not that good as a language designer. C# is basically a clone of Java with broken exception handling.

Here's the problem with C# exceptions: https://web.archive.org/web/20041201011903/http://www.geocit...