by cmrdporcupine · 3y ago · 0 comments
But OCaml has had more momentum, and I don't know if anybody is even using SML anymore?
Interesting to look back with a bit of history now, too. Choices like having objects/classes and exceptions (instead of result types) added into OCaml were probably seen as modernizing and adding in features that people expected; but now the pendulum seems to have swung against those features. OOP hype has passed -- e.g. Rust and Go don't have 'classes' with inheritance. And exceptions are also lacking in Rust etc, in favour of Option/Result type + pattern matching, so that control flow is more explicit and easier to reason about.
For example, English-like syntax is out. Cobol has it because it was invented for its predecessor and Cobol's still around, SQL has it because its designers copied Cobol before we'd learned better, and that's it. We still use words in our syntax but explicit block structure with punctuation is now known to be easier to read.
Speaking of block structure: Line numbers are gone. Unrestricted use of goto (as in, using goto to go from anywhere in the program to anywhere else in the program) is also gone. These things aren't fashion: We've learned better. We're more likely to invent a different kind of structure than to go back to that.
Similarly, languages with absolutely no type system are also out: You can have the types on variables, like Haskell, or values, like Python, but choosing to have neither, like BLISS and BCPL, is no longer an option unless you're actually writing in assembly language.
Other things, like column-oriented formatting, are gone because technology moved on. Even Cobol abandoned that one.
If exceptions have a "comeback" (they have not gone away in mainstream languages like Java, C#, Python etc.) I hope they come back in a way where they're bundled with static analysis features that help with the reasoning process.
When I worked in Java, 10+ years ago, checked exceptions were considered an obnoxious "no-no", and bad style. Mostly because people just wrapped and rethrew them as runtime exceptions. But, like, runtime exceptions are awful, and almost every application I worked in had buckets of garbage in the logs which consisted of uncaught or "caught & logged" exceptions. Such exceptions are particularly troublesome in highly concurrent applications.
Exceptions should be exceptional. I think Rust has made the right call here. Handle the error, or panic. Don't make it somebody else's problem.
Still, the catch syntax was very verbose for handling common conditions. Exceptions were the wrong syntactical tool for the job.
Consider some kind of validator/parser class/function, with a public entrypoint and a bunch of private subroutines that can fail when they hit invalid input:
public parse() {
try {
this.parseX();
this.parseY();
this.parseFoo();
...
} catch (e) {
throw new Error(...)
}
}
private parseY() {
this.y = this.input.y.map(a => {
if (bad data) throw new Error("corrupt data");
...
})
}
It's common in such situations to want to have one central point to collect errors in order to produce a single error type result.It is possible to manually thread Results all the way through your logic, but that clutters the code with error handling. Rust's Try operator makes it easier but it's still awkward.
Exceptions allow us to concentrate on the two most important parts: where the exceptions are generated, and where they are handled (in this case, the root of the public interface).
I definitely agree that exceptions are not perfect. They have their own flaws, especially for public interfaces. But as control flow they are useful in many cases.
I like that in Java, units of work can continue after an unhandled exception because you know, sometimes, your software is used by many people in many input variants and say, if you re doing a trading backend, it's bad that you cant fill an order because of a silly parsing bug, but it d be way worse if you had to stop for the day until a dev wakes up and fix it.
Log it, and while you fix it the thing still runs for 99% of inputs. Maybe that s what you call "handling" the error ? But it's cool to bubble up the exception because you can share the handler amongst all your downstreams: you may dislike having to do the same exact semi-complex log building everywhere and having it just capture exception at the top most unit of work dispatcher to catch if one threw something to then log and alert your support team in one place, might make sense.
Ofc return types can do all that but you contaminate your whole program with handling for bugs you cant well predict the nature off... the only certain thing is that if your program is old and big enough, you'll screw up in innovative ways a general catch will allow to recover from, because you just dismiss the whole input and move to the next.
If it's an "expected" runtime condition that you can manage and recover from, then it's not "exceptional", is it? So don't use an exception. Pass the information to the caller that needs it, and adjust state accordingly.
That's my take these days. I've seen too many systems degrade in cascading failures because of misguided attempts to "recover." Deadlocks, partial failures, explosions, etc. Real fun to diagnose.
By this logic, it kind of seems like no function should ever return errors at all -- handle the situation or panic, right?
Sure, kicking the ball up the chain out of laziness is, well, laziness. But plenty of times, it's done out of the knowledge (or at least hope) that somebody up the chain has a better idea of how to handle the situation than you do.
I'd love that too, i'm very much in love with it.
We’ll see the Zigs, Nims and Rusts of the world mature along with special languages for things like tensor processing units. AI will make it much easier for humans to work using those languages.
Ah, yeah, it's been worked on before, just found a paper: https://people.cs.uchicago.edu/~jhr/papers/2020/ifl-smlnj-ll...
That and the community around it was so enamoured with Deep Intellectual Ponderings and Very Novel Arcanities. That was good, sure, but ... hard.