News for hackers. Stuff that matters.
Re:On the proliferation of try, and soon, await (2020) by shadowgovt on Thursday August 26, 2021 @11:14AM (#28316007)
One of the interesting things (IMO) about programming language design is how the designer can choose to make some concepts harder or easier to express, and how those decisions shape the kind of programs that are easy to write with the language.

Here, Swift (it seems) makes an implicit suggestion that a developer keep their error handling tight and bounded. If you don't, the language softly penalizes you with the need to add keywords to be explicit about changed flow. Go does something similar in eschewing try / catch error handling for a single panic / recover system and very explicit error handling via return values (this was a very intentional design to address what the language creators perceived to be common failure modes in code they were maintaining at the time in other languages, see here [https://go.googlesource.com/proposal/+/master/design/go2draf...] for details). In Go, it's harder to make a certain category of mistake, but at the cost of the user writing more code to handle the error path (and assuming the implicit cost that every line of code could introduce a different mistake).

Every language feature in every language we use (static type declaration vs. implicit types with casting, variable predeclaration vs. implicit creation on first write or read, GOTO vs. function calls vs. try/catch vs. continuation passing, etc.) makes these tradeoffs.

Re:On the proliferation of try, and soon, await (2020) by Buttons840 on Thursday August 26, 2021 @01:26PM (#28317813)
What do you think of Java's declared exceptions (or whatever they're called)? They always seemed like a good idea to me, but were ruined by people being lazy or not understanding how to properly design exceptions.
Re:On the proliferation of try, and soon, await (2020) by earthboundkid on Thursday August 26, 2021 @01:54PM (#28318216)
With checked exceptions, if today my function can only throw a FileException, then tomorrow I cannot start throwing a URLException without breaking any callers depending on my function having only one possible exception type. The lead architect of C# cited this problem as one of his reasons for not adding checked exception to that language. https://www.artima.com/intv/handcuffs.html#part2

The solution to the problem with to have errors be dynamically typed (a trait in Rust, an interface in Go, etc.) and insist that callers be ready for an unknown error type to bubble up.

Re:On the proliferation of try, and soon, await (2020) by shadowgovt on Thursday August 26, 2021 @01:33PM (#28317909)
Personal opinion: I think they were a good idea but in practice they don't work great because they try to pretend exceptions work differently from how they really work.

They bump up against a reality of exceptions in a bad way: once you have a system for throwing exceptions, the set of types your code must handle becomes fundamentally unbounded because any of your dependencies can change at any time. If there are no exceptions and you have a function-call control flow, you can enforce that the only types the caller understands from the callee are the types in the signature. If your language supports thrown exceptions, then at the site of a function call, the value resulting from the call can be the values in the signature or any exception that can be generated by any function called by the callee (and in general, without control of the entire code stack, that set is unknowable).

That's a fundamental truth of thrown exceptions, and trying to constrain it by putting the thrown type in the signature left us in the state we're in now... People just throw and catch very abstract exceptions because they'll have to handle those exceptions anyway, since it's impossible to guarantee a dependency won't try to throw them.

Re:On the proliferation of try, and soon, await (2020) by pierrebai on Thursday August 26, 2021 @04:04PM (#28319911)
> "If there are no exceptions and you have a function-call control flow, you can enforce that the only types the caller understands from the callee are the types in the signature."

This has historically resulted in either ignoring errors from sub-functions, because their error return type don't map properly, or returning generic "i got an error" without any more information about what the error was.

And all this was historically patched over by having verbose log files that could be written to from anywhere and the user had to peruse and try to make sense of after the fact.

Some franework tried to create complicated error code (like Windows COM) but in the end there is no free lunch. Errors are hard.

Re:On the proliferation of try, and soon, await (2020) by cr212 on Thursday August 26, 2021 @02:01PM (#28318298)
some disadvantages:

i) There's RuntimeException which is an unchecked exception which could happen anywhere, so even the absence of a throws is not a guarantee of not throwing.

ii) In order to avoid many different throws specifiers, you end up with wrapping exceptions to a smaller set of exceptions (e.g. JNDI may throw a NamingException that wraps an IOException)

iii) IDEs offer to put try-catch { // todo } to avoid compiler errors. Developers often stop thinking then, where the right thing is more often to let it throw - e.g. I've seen FileNotFound being caught and logged (at debug) and not exposed to a caller, so a UI doesn't see it, with bad results.

Re:On the proliferation of try, and soon, await (2020) by jcranmer on Thursday August 26, 2021 @02:43PM (#28318857)
> iii) IDEs offer to put try-catch { // todo } to avoid compiler errors.

This is the thing that always pissed me off. The default catch block should be to wrap it in a RuntimeException and rethrow it.

Re:On the proliferation of try, and soon, await (2020) by sharikone on Thursday August 26, 2021 @11:48AM (#28316464)
I don't know why but for a moment I read this comment in horror imagining language developers implementing telemetry in the compilers and tooling themselves, then relying on them to "improve the experience" by changing the spec every six months.
Re:On the proliferation of try, and soon, await (2020) by shadowgovt on Thursday August 26, 2021 @11:52AM (#28316543)
Oh, they wouldn't have to do that.

... a scan of GitHub and feeding keywords and constructs into a couple hoppers would be all the ML you needed for that. ;)

(... I'm joking, but if you're a language designer, this is actually not a terrible idea for figuring out how people use your language "in the wild." What you do with that information will separate wisdom from knowledge).

Re:On the proliferation of try, and soon, await (2020) by pjc50 on Thursday August 26, 2021 @12:46PM (#28317322)
Microsoft dotnet has opt-out telemetry. I'm not sure for what.