Re:Partial WebAssembly backend for the GNU toolchain
by josephg on Saturday March 04, 2017 @07:58PM
(#13793953)
> In many ways yes, as C can be much more straightforward than JavaScript, which enforces spaghetti-programming by design (via callback hell).
I don't think this is a fair criticism of javascript. In javascript if you want to you can define all your callbacks as top level functions and just pass a function pointer through, the same way you would in classic C or C++. But nobody does that because its an awful way to write your code. If you want to do async programming you need callbacks of some form, and putting the callback inline is better. (Hence lambda functions being added to C++ and java). Arguably await/defer is better still, and unlike C, javascript now supports await if you want to write code that way.
The only other decent way to write high performance code is to use lightweight threads and message passing (go or erlang). But again, (as far as I know) C and C++ make this sort of code really hard to write correctly because of the memory model. I'm looking forward to seeing that battle played out in rust, where both models can work side-by-side.
As for resource loading in JS, promises aren't perfect but they make deferring code execution on resources loading work great. Just bundle your resource loading into a promise and then require('./resources').then(whatever => {...}).
I don't think this is a fair criticism of javascript. In javascript if you want to you can define all your callbacks as top level functions and just pass a function pointer through, the same way you would in classic C or C++. But nobody does that because its an awful way to write your code. If you want to do async programming you need callbacks of some form, and putting the callback inline is better. (Hence lambda functions being added to C++ and java). Arguably await/defer is better still, and unlike C, javascript now supports await if you want to write code that way.
The only other decent way to write high performance code is to use lightweight threads and message passing (go or erlang). But again, (as far as I know) C and C++ make this sort of code really hard to write correctly because of the memory model. I'm looking forward to seeing that battle played out in rust, where both models can work side-by-side.
As for resource loading in JS, promises aren't perfect but they make deferring code execution on resources loading work great. Just bundle your resource loading into a promise and then require('./resources').then(whatever => {...}).