4 ms·
> You could avoid the whole for..of problem by writing ES5 JS code, but for many people that's apparently a worse option than dealing with Babel. The big reaso
by inferiorhuman 9y ago
> You could avoid the whole for..of problem by writing ES5 JS code, but for many people that's apparently a worse option than dealing with Babel.
The big reason I'm so excited about web assembly is that now we can escape the albatross of JS/ES. I've started playing with rust targeted to emscripten and it's such a breath of fresh air (both the language and toolchain).
- kbenson 9y agoI was just thinking the same thing while reading this article but, upon thinking about it, you'll likely have to ship the stdlib of whatever language you're targeting as well as your code (although I'm sure some interesting omissions of the stdlib can be automated determined based on the actual use). That's traditionally why Rust binaries are large (they statically compile in their standard library). Statically compiling a simple hello world C program results in a 700+ KB executable. By researching And adding various options to gcc to reduce size, I was able to get the binary down to just under 650 KB (277 KB gzipped), so progress! :/ There are undoubtedly smaller libc implementations[1], but I think I've illustrated the problem adequately. Having an entire runtime in the browser gives JS a fairly large advantage as I see it, at least currently. 1: https://en.wikipedia.org/wiki/Dietlibc https://en.wikipedia.org/wiki/Dietlibc
- cwzwarich 9y agoRust binaries are also large because they copy some of C++'s bad decisions: 1) Generics are instantiated and compiled separately with types for which the generics have identical behavior. 2) Functional abstraction is encouraged (not a bad thing!) and inlining heuristics are overly aggressive to compensate. 3) By default, almost every function call has to deal with the possibility that the callee might throw an exception. This is smaller than 1) and 2), but it still matters.
- inferiorhuman 9y agoExcept that rust doesn't have exceptions.
- cwzwarich 9y agoRust actually does have exceptions. Rust unwinding is implemented using LLVM/Dwarf exceptions, and can be caught using std::panic::catch_unwind: https://doc.rust-lang.org/std/panic/fn.catch_unwind.html https://doc.rust-lang.org/std/panic/fn.catch_unwind.html Idiomatic Rust doesn't use them for error handling, and they can be disabled entirely with a command-line option, but the implementation still has to deal with all of the issues that come with having exceptions.
- inferiorhuman 9y agoWell, damn.
- inferiorhuman 9y ago> you'll likely have to ship the stdlib of whatever language you're targeting as well as your code (alt True. However from my POV the code bloat is outweighed by the fact that rust tooling is simply that good. Javascript is, IMO, a nightmare to develop for both due to poor language choices and due to the really mediocre tooling. My new favorite JSism (thanks HN!) was this: ['1','2', '3'].map(parseInt)