5 ms·
I enjoy Swift’s version of this, where you mark if a function can throw and you need to mark the callers up the chain until you handle those errors. There’s al
by cprecioso 5y ago
I enjoy Swift’s version of this, where you mark if a function can throw and you need to mark the callers up the chain until you handle those errors.
There’s also Haskell’s system, which IIRC uses an IO monad.
- inglor 5y agoHaskell's system (with the io monad + do not all monads or in general) is extremely similar to async/await and most languages with co-routines can simulate do notation in Haskell pretty well syntactically. The advantage of something like JavaScript's async/await over Haskell's "do" is the fact because async/await is more limited than `do` (or yield and coroutines in JS) it's a lot easier to create tooling for.
- kaba0 5y agoI would say it is a huge disadvantage -- do is just syntactic sugar for a monad expression of binds, which is a native part of the language, you can write a simple function to manipulate it however you like. While you would need to effectively parse AST in case of JS.
- inglor 5y ago`yield` is just syntactic sugar for the two-way generator communication protocol where the consumer calls `.next(value)` which returns a value in turn. This is as expressive and you can build `do` semantics on top of stuff like lists/either/state/io on top of it. No AST parsing needed.
- kaba0 5y agoAnd do syntax sugar is just nested calls of `bind` which is a function of the Monad trait. Lists are also a Monad, so do notation just works right now with lists, either, state everything in Haskell. I really don’t get how is Haskell “behind”.
- ImprobableTruth 5y ago> async/await is more limited than `do` (or yield and coroutines in JS) it's a lot easier to create tooling for. What kind of tooling are you referring to?
- inglor 5y agoBasically by limiting the scope significantly and limiting it to language-level Promises you can create things like zero-cost async stack traces, async-call aware flame graphs and more for analysis and better lint rules and more specific types for development.
- pjmlp 5y agoAn idea introduced by CLU, copied by Modula-2+, Modula-3, C++ and Java, and usually blammed on Java. https://www.academia.edu/71720554/A_Modular_Verifiable_Exception_Handling_Mechanism https://www.academia.edu/71720554/A_Modular_Verifiable_Excep...
- saagarjha 5y agoLink that doesn't suck: https://dl.acm.org/doi/pdf/10.1145/3318.3320 https://dl.acm.org/doi/pdf/10.1145/3318.3320
- pjmlp 5y agoThanks, it was a bit hard to find one on the phone.
- gpderetta 5y agoC++ had a dynamically typed variant that was useless and got deprecated (and eventually dropped) a few standards ago.
- pjmlp 5y agoIt was deprecated in C++11, and a removed in C++17, yet now they are discussing adding it back in a flavour similar to Swift, so apparently there is some value into it. So here you go, http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0709r4.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p070... As for being useless, well that is the usual argument from no exception, no RTTI folks, that would be better off using another language instead of messing up with C++'s design.
- gpderetta 5y agoI'm very much in favour of statically checked exceptions (and noexcept is sorta-kinda like that). It is the old dynamically typed style which was little more than an assertion that wasn't very useful.