Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In many ways yes, as C can be much more straightforward than JavaScript, which enforces spaghetti-programming by design (via callback hell). So anyone used to develop desktop apps, facepalming on trivial problems in JS like loading resources, can rejoice. And I expect other languages will be ported soon, like Java, C#, Scala, Python, Go, Rust etc. Imagine getting the whole Java stack of libraries, .NET or ML stack for Python running on top of WebAssembly with almost zero differences and at native speeds. Why not?


> 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 => {...}).


JavaScript doesn’t have “spaghetti-programming by design via callback hell”. Callbacks are a common approach to dealing with events and asynchronicity because nothing was built into the language (until it added promises and async/await, like how nothing was built into C# until it added tasks and async/await). There certainly isn’t anything built into C.


Rust has basic support today. We're working on making it even easier.

https://users.rust-lang.org/t/compiling-to-the-web-with-rust...

(This post is a bit old, it works on stable nowadays, but it gives you the basic idea)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: