Live data from Hacker News

Learn WebAssembly by writing small programs

github.com

31–40 of 87 posts

Re: Learn WebAssembly by writing small programs

#31

Earlier quoted context omitted.

I've been watching WASM from afar, and it's my understanding that it's not a JS killer because it doesn't have direct access to the DOM or to most DOM APIs. I'm curious if there's another reason I'm missing?

It doesn't have access to _anything_ (in the browser, in other runtimes there is WASI with POSIX functions). Everything has to be imported from or exported to JS. And currently using anything but C, C++ or Rust isn't feasible, as the runtime needed for a GC is way too big. A Haskell "Hello World" for example is about 1MB (even after running `wasm-opt` on the generated WASM binary).

In the browser, can it integrate with SharedArrayBuffer, worker's postMessage or transferrable offscreen canvas?

Re: Learn WebAssembly by writing small programs

#32
post #31

Earlier quoted context omitted.

It doesn't have access to _anything_ (in the browser, in other runtimes there is WASI with POSIX functions). Everything has to be imported from or exported to JS. And currently using anything but C, C++ or Rust isn't feasible, as the runtime needed for a GC is way too big. A Haskell "Hello World" for example is about 1MB (even after running `wasm-opt` on the generated WASM binary).

In the browser, can it integrate with SharedArrayBuffer, worker's postMessage or transferrable offscreen canvas?

WASM essentially can call javascript functions that were imported, and I believe javascript is able to read WASM's memory (a big help for transferring strings). If you're using something like Rust, all the glue code to call any JS APIs can be automatically generated for you with wasm-bindgen, so it really isn't a huge problem usability wise. It's just not great for performance.

Re: Learn WebAssembly by writing small programs

#33
post #31

Earlier quoted context omitted.

It doesn't have access to _anything_ (in the browser, in other runtimes there is WASI with POSIX functions). Everything has to be imported from or exported to JS. And currently using anything but C, C++ or Rust isn't feasible, as the runtime needed for a GC is way too big. A Haskell "Hello World" for example is about 1MB (even after running `wasm-opt` on the generated WASM binary).

In the browser, can it integrate with SharedArrayBuffer, worker's postMessage or transferrable offscreen canvas?

Depends what you mean by "integrate". It always has to import or export JS functions or memory. WASM (without WASI) has no direct connection to "the outside World", everything has to be routed via JS FFI. So you can import or export a SharedArrayBuffer to communicate with JS. https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScr...

But you need the WASM thread extension (for atomic access to the shared memory) to be able to use shared memory.

Re: Learn WebAssembly by writing small programs

#34

Pretty cool. I haven't really explored WASM hands-on (I'll give this guide a try) but, given that it's already been a few years, I think it's been hugely beneficial for web development. Not the "JavaScript killer" some where hoping for, though it was never meant to be one. Instead it integrates pretty nicely within the existing ecosystem, optimizing existing use-cases and allowing new ones when heavy computations are…

I've been watching WASM from afar, and it's my understanding that it's not a JS killer because it doesn't have direct access to the DOM or to most DOM APIs. I'm curious if there's another reason I'm missing?

Is being a "JS killer" even a goal of WASM? From what I understand, WASM's goal is to allow computationally heavy workloads (e.g., image and audio processing) to the browser by providing a compilation target for C code. This is how we get nice things like Figma or MS Office running in the browser.

Let WASM do the number crunching, let JS do the UI.

Re: Learn WebAssembly by writing small programs

#36

Earlier quoted context omitted.

I've been watching WASM from afar, and it's my understanding that it's not a JS killer because it doesn't have direct access to the DOM or to most DOM APIs. I'm curious if there's another reason I'm missing?

It doesn't have access to _anything_ (in the browser, in other runtimes there is WASI with POSIX functions). Everything has to be imported from or exported to JS. And currently using anything but C, C++ or Rust isn't feasible, as the runtime needed for a GC is way too big. A Haskell "Hello World" for example is about 1MB (even after running `wasm-opt` on the generated WASM binary).

I mean Microsofts Blazor framework can use WASM to run C#(and its runtime) in the browser.

Re: Learn WebAssembly by writing small programs

#37
post #16
post #11

This is great, thanks! One of my favorite ways to learn a new language or framework is via "koans"[1], which this reminds me of. It's a gentle ramp up from basic to advanced features, and the TDD-like workflow of seeing a test fail, understanding why, and fixing it, is really conducive to learning, while giving you that dopamine jolt from "a-ha!". [1]: https://github.com/ahmdrefat/awesome-koans/blob/master/koans...

sounds like a great way to learn a language "on your own". unfortunately, Rust is missing. can anyone propose a link?

It credits Rustlings at the end of the page linked to (https://github.com/EmNudge/watlings#credits).

Re: Learn WebAssembly by writing small programs

#38

Earlier quoted context omitted.

I've been watching WASM from afar, and it's my understanding that it's not a JS killer because it doesn't have direct access to the DOM or to most DOM APIs. I'm curious if there's another reason I'm missing?

It doesn't have access to _anything_ (in the browser, in other runtimes there is WASI with POSIX functions). Everything has to be imported from or exported to JS. And currently using anything but C, C++ or Rust isn't feasible, as the runtime needed for a GC is way too big. A Haskell "Hello World" for example is about 1MB (even after running `wasm-opt` on the generated WASM binary).

> And currently using anything but C, C++ or Rust isn't feasible

Someone should tell Anaconda that they can't do this, then: https://pyscript.net/

Post reply on HN