6 ms·
I don’t really get JavaScript. Isn’t this type of try/catch/finally method available on almost every other language? Is JavaScript behind the times or is this j
by matt_wulfeck 9y ago
I don’t really get JavaScript. Isn’t this type of try/catch/finally method available on almost every other language? Is JavaScript behind the times or is this just not a common use-case?
Personally I like the “defer” method, where closing actions can be clear and front-loaded in the function definition.
- BinaryIdiot 9y agoJavaScript does have a try / catch / finally in their exception handling. This update is for Promises which are a method of managing asynchronous code.
- deleted 9y ago[deleted]
- singularity2001 9y agoJavaScript invented a new concurrency model which IMHO is worse than the invention of 'goto', by putting async mechanisms on the callee side: `result=mayBePromiseOrResultWhoKnows()` instead of `go nowThisSyncMethodIsAsync()`
- deleted 9y ago[deleted]
- dboreham 9y agoDespite the downvoting this is spot on. File in the (very large, now bulging) "What were they thinking??" file.
- Touche 9y agoNo, the caller has control. result = await maybePromiseWhoCaresIUsedAwait(); You can use await without knowing if the function you called returns a promise or not. This works fine: result = await 3;
- singularity2001 9y agook and to be safe you ``` await every() await freakin() await function() ``` ? Or you may end up with obscure bugs, when you expect a sync method or worse, when a sync method changes to async in the next api version(happened in real world!)
- Touche 9y agoI'm not aware of any programming language where it is safe to use a function's return value without knowing what the return value is. This seems unrelated to async/await, if you are calling functions that are returning things other than what you expect, you are pretty much screwed.
- xfer 9y agoNo in typed language, this is not a problem because the compiler will refuse to compile. For uni-typed languages async/await is not the right model imho.
- Touche 9y agoAgain, this is unrelated to async/await. Normal functions might return a number or an object or undefined or whatever. Since JavaScript is a dynamic language it is unsafe to call a function without either 1) Trusting that the function returns what its API says it should return or 2) Checking the return type and acting appropriately. So, the grandparent's complaint is about JavaScript being a dynamic language, async/await doesn't fix this issue or make it any worse.
- singularity2001 9y agograndpa here. position accepted.
- cromwellian 9y agoJS didn't invent Promises/Futures nor did it invent Async/Await.
- singularity2001 9y agomostly true, but in which other language can you call async functions which you expect to be synchronous?
- cromwellian 9y agoNot sure what you mean, do you mean what other language has "await"? Many.