Live data from Hacker News

JavaScript to Rust and Back Again: A Wasm-Bindgen Tale

hacks.mozilla.org

21–30 of 79 posts

Re: JavaScript to Rust and Back Again: A Wasm-Bindgen Tale

#21
post #12

Earlier quoted context omitted.

Rust is also still very far from having eaten any significant chunk of C.

Do you see any reason why it won't eventually do so?

It's still too early. There's tons of good reasons to write C code today for many projects. Furthermore, there's so much C code out there that even if nobody wrote a single new line of C today, it'd be decades before it would go away.

It's really about growing the pie rather than replacement anyway, in my opinion.

Re: JavaScript to Rust and Back Again: A Wasm-Bindgen Tale

#22
post #10
post #7

Earlier quoted context omitted.

"Faster-than-JS DOM performance" That will be when the clock starts ticking on Javascript. Who'da thunk one language might eventually eat both a significant chunk of C and a significant chunk of Javascript someday? I'm not saying Rust will completely eat Javascript; there is no chance that all web developers would or even necessarily could switch to Rust. But the framework war will take a very interesting turn if Rus…

Is JS even the speed problem or is it banging on the DOM all the time?

It might help to think speed as lower power consumption.

So yes. As long as cellphones and laptops need a battery.

Re: JavaScript to Rust and Back Again: A Wasm-Bindgen Tale

#23
post #7

Earlier quoted context omitted.

"Faster-than-JS DOM performance" That will be when the clock starts ticking on Javascript. Who'da thunk one language might eventually eat both a significant chunk of C and a significant chunk of Javascript someday? I'm not saying Rust will completely eat Javascript; there is no chance that all web developers would or even necessarily could switch to Rust. But the framework war will take a very interesting turn if Rus…

Rust is also still very far from having eaten any significant chunk of C.

I think IoT will push embedded development towards Rust. As well as security critical desktop/server code. Especially when said code needs to be a loadable library (.dylib, .so, .dll).

While Rust certainly isn't the silver bullet, it demonstrably significantly reduces memory and concurrency related bugs.

Yeah, the last firmware I developed was in C and assembler. No, I could not have done it in Rust, mainly due to no Rust compiler available for the arch. Then again, I could not have done it in pure C either...

For future platform selection availability of a Rust compiler is already a factor. Even if we'd still end up using C/C++ for now.

Re: JavaScript to Rust and Back Again: A Wasm-Bindgen Tale

#24
post #6

Earlier quoted context omitted.

At our local Rust meetup we have someone who's gotten WASM running on a microcontroller, so maybe that's not entirely unrealisitic. :P

Wait, who was that?

This is somewhat related, although embedded here means embedding interpreted WASM into a CLI application.

Similar method might be doable on an MCU.

https://fosdem.org/2018/schedule/event/rust_embedding_wasm/

Then there's "WebAssembly interpreter in C":

https://github.com/kanaka/wac

Looks like it might be good enough for implementing WASM "scripting" support in smallish environments.

Re: JavaScript to Rust and Back Again: A Wasm-Bindgen Tale

#25
post #24

Earlier quoted context omitted.

Wait, who was that?

This is somewhat related, although embedded here means embedding interpreted WASM into a CLI application. Similar method might be doable on an MCU. https://fosdem.org/2018/schedule/event/rust_embedding_wasm/ Then there's "WebAssembly interpreter in C": https://github.com/kanaka/wac Looks like it might be good enough for implementing WASM "scripting" support in smallish environments.

https://crates.io/crates/parity-wasm is an interpreter in Rust; there's some really interesting stuff happening with it in various forms. One of the most... extreme is https://www.reddit.com/r/rust/comments/88sxah/nebulet_can_no... (There are some more production-aimed things as well.)

I think this idea has a lot of merit, overall, exactly as you say: kind of like a Lua.

Re: JavaScript to Rust and Back Again: A Wasm-Bindgen Tale

#26
post #16
post #7

Earlier quoted context omitted.

"Faster-than-JS DOM performance" That will be when the clock starts ticking on Javascript. Who'da thunk one language might eventually eat both a significant chunk of C and a significant chunk of Javascript someday? I'm not saying Rust will completely eat Javascript; there is no chance that all web developers would or even necessarily could switch to Rust. But the framework war will take a very interesting turn if Rus…

Rust isn't the only player here. Kotlin I think does webasm already. And I think Java and C# will also jump on the bandwagon eventually.

C# already jumped on the bandwagon with Blazor https://github.com/aspnet/Blazor

Re: JavaScript to Rust and Back Again: A Wasm-Bindgen Tale

#27
post #17

Earlier quoted context omitted.

>Who'da thunk one language might eventually eat both a significant chunk of C and a significant chunk of Javascript someday? Erm... PSA: Rust isn't the only language that is compiling to WASM. I'm glad for Rust developers (How exciting is for them to be able to target WASM), but what is really exciting is to have alternatives; even more exciting if they have nothing to do with javascript.

"Erm... PSA: Rust isn't the only language that is compiling to WASM." No, but Rust will still be sitting in a sweet spot, having many of those characteristics I named. For instance, Python compiling to WASM may be useful, but it won't have any of those advantages. Python running on WASM isn't hardly a threat to JS at all, because it won't do anything JS can't. Rust will conceivably be able to in the near term, and as…

IIRC wasm has no GC capabilities, so Python is an unlikely source language.

Re: JavaScript to Rust and Back Again: A Wasm-Bindgen Tale

#28
post #17

Earlier quoted context omitted.

"Erm... PSA: Rust isn't the only language that is compiling to WASM." No, but Rust will still be sitting in a sweet spot, having many of those characteristics I named. For instance, Python compiling to WASM may be useful, but it won't have any of those advantages. Python running on WASM isn't hardly a threat to JS at all, because it won't do anything JS can't. Rust will conceivably be able to in the near term, and as…

IIRC wasm has no GC capabilities, so Python is an unlikely source language.

In cases like that, you also compile the Python GC to wasm and use it. It ships with your app, adding bloat to your binary though. It does work!

Re: JavaScript to Rust and Back Again: A Wasm-Bindgen Tale

#29
post #20
post #12

Earlier quoted context omitted.

Do you see any reason why it won't eventually do so?

The other question is whether there actually is a reason that it will eventually do so. I personally have my doubts. C has found that perfect sweet spot between not getting in the way of doing things and running on almost any platform. Rust still has to achieve that status and judging from other competitors like C++/D it seems hard to get to that point. Heck, even Java was advertised as systems language on Java CPUs…

Well, Java is the systems language on Android that has full exposure to what app developers can actually use.

NDK is quite constrained, mostly as a means to implement Java native methods.

On Android Things they went one step further and the user space drivers are written in Java.

With Treble it is also possible to write drivers in Java thanks to the new micro-kernel like architecture.

Re: JavaScript to Rust and Back Again: A Wasm-Bindgen Tale

#30
post #16

Earlier quoted context omitted.

Rust isn't the only player here. Kotlin I think does webasm already. And I think Java and C# will also jump on the bandwagon eventually.

Rust has some significant advantages compared to languages like Kotlin, Java, and C# here. A really big one is binary sizes. To get those languages to work, you have to ship the entire runtime. For example, see https://www.infoq.com/news/2018/01/mono-cs-webassembly > (the "hello world" example is 10 megabytes) The "hello world" example in Rust is ~100 bytes . Some applications and some people can pay these costs, it'…

Java and .NET also have linkers, which can help bring down that size, even if not as much as Rust.
Post reply on HN