5 ms·
Is the closer C family of languages really reasonable for the web?
by 7373737373 10y ago
Is the closer C family of languages really reasonable for the web?
- andrepd 10y agoMuch better than the mess that is JS, IMO.
- bitL 10y agoIn 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?
- steveklabnik 10y agoRust has basic support today. We're working on making it even easier. https://users.rust-lang.org/t/compiling-to-the-web-with-rust-and-emscripten/7627 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)
- minitech 10y agoJavaScript 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.
- josephg 10y ago> 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 => {...}).
- tyingq 10y agoWASM does have the pieces needed for most languages on their roadmap. GC, polymorphic inline caching, direct access to DOM, threads, and so forth. No idea of what the timeline would be though.