4 ms·
Many promise libraries (e.g. bluebird, Q, when) as well as some observable libraries (e.g. RxJS) successfully preserve stack traces.
by spion 12y ago
Many promise libraries (e.g. bluebird, Q, when) as well as some observable libraries (e.g. RxJS) successfully preserve stack traces.
- pron 12y agoIf by "preserve" you mean "recreate", just as they need to recreate exceptions and control flow. These techniques recreate imperative constructs using lambda-calculus concepts in languages that already have those constructs as fundamental building blocks. Hence, they create a full "shadow" language, that's not directly interoperable with the host language.
- spion 12y agoMy point is that the shadow language isn't really that much "second class". Would you also call using `Array#map` and `Array#filter` instead of `for` a shadow language? Not really. Well in this case e.g. with promises other than a few basic operations and if blocks the "shadow language" is really close with the "real language". Especially given the fact that the host language is pretty weak [1] and that it just got short lambda syntax that makes it less tedious to write this kind of code (arrow functions). [1]: No filtered exception handling? Just got halfway-decent `for..of` loops?
- pron 12y agoWell, I know very little JavaScript to comment, so you may well be right, and besides, as long as JS doesn't have threads, there's not much choice, really. Also, since there's no parallelism, the consequences of having side effects in monadic compositions (promises) are not as bad as in environments that do support parallelism. Still, if you can get some lightweight threads implemented in JavaScript (or green threads, in this case, as there is only no parallelism), I think you'd find them to be even better. Threads are just a better fit for imperative languages especially ones with unrestricted mutation.