7 ms·
Our Vision for Rust and WebAssembly
- deleted 8y ago[deleted]
- kalessin 8y agoI would love to do frontend web development but the current high-churn Javascript ecosystem makes me dizzy; this is probably a naive question but will it be possible to do web-development without integrating in the Javascript ecosystem using WebAssembly and Rust someday?
- amelius 8y agoYou can already do frontend development pretty well, by just relying on the technologies that have proven to be backward-compatible (for instance: the JavaScript language, HTML, CSS).
- stupidcar 8y agoEventually there will be direct binding between WebAssembly and web APIs like that the DOM that will allow you to write performant web apps that circumvent JS entirely. There are already tools that https://webassembly.studio/ https://webassembly.studio/ that making writing wasm-based apps a reality, albeit still with a binding layer that goes through JS. However, such applications will still have the same constraints that drive the current JS ecosystem. As such, there's little reason to believe that frameworks like React, Angular, Vue.js, etc. won't have their wasm-based equivalents. And, if anything, I except more churn for quite a few years, as people use the freedom provided by wasm to build a new generation of frameworks in completely different languages. We may look back on the current era of web development as a relatively stable one compared to what's to come. So if the current churn is what turns you off web development, I wouldn't bet on wasm being a salve.
- giancarlostoro 8y agoAnother (non-Rust) but still interesting attempt towards this is being done by Microsoft: https://blogs.msdn.microsoft.com/webdev/2018/03/22/get-started-building-net-web-apps-in-the-browser-with-blazor/ https://blogs.msdn.microsoft.com/webdev/2018/03/22/get-start... In their case they compile a small enough subset of the .NET runtime to WebAssembly, and they got some JS to do the interop (I imagine till that glorious day of freedom comes). It's amazing what they've got working so far honestly.
- tenaciousDaniel 8y agoOh wow, I didn't realize that wasm did not currently have any direct bindings to the DOM. How does it interact with the page then? I saw a demo where they ported UE4 - how does something like that work without DOM access?
- steveklabnik 8y agoIt calls to JavaScript which manipulates the DOM for it.
- steveklabnik 8y agoThere already is, see https://github.com/DenisKolodin/yew https://github.com/DenisKolodin/yew for example. The "put Rust in your JS" workflow is the first one the working group is focusing on; once that's awesome, other ones will get some work as well.
- sanxiyn 8y agoMaybe, but this post is to tell you that such use cases are explicitly not the focus of Rust and WebAssembly working group.
- a-saleh 8y agoActually, if you addopt a mindset where you don't care about the ecosystem as much, you don't need to wait for rust-wasm to mature. For example, a friend of mine just shipped a web-app for a client, that wanted something to help them organize local chemists conference between few universities. He wrote it in Elixir. Didn't actually use Javascript, because it doesn't need to be a single-page-app, right? :) Few froms, nice theme. Ok, maybe there was few lines of jquery, where absolutely necessary. I remember once using Vaadin, just because I already know Java and didn't really care that nobody uses Vaadin anymore :D Or, if you don't actually have client to solve a problem for, but want to try out a cool tech, I would suggest playing around with PureScript. Inspired by Haskell, compiles to JS, has nice ecosystem and many of the libraries don't have JS dependencies. Or maybe Elm, if you want something simmilar, but more focused/lightweight? :-) Claudia Doppioslash has a nice overview of both: https://www.youtube.com/watch?v=9kGoaUqcq4A https://www.youtube.com/watch?v=9kGoaUqcq4A
- nostalgeek 8y ago> I would love to do frontend web development but the current high-churn Javascript ecosystem makes me dizzy; this is probably a naive question but will it be possible to do web-development without integrating in the Javascript ecosystem using WebAssembly and Rust someday? there are 2 different things, there is the DOM/Web API and the language, Javascript. Nobody forces you to use anything from the JavaScript ecosystem, not even node.js, in order to use the DOM. This complexity is totally unnecessary. I personally settled on Typescript, nothing more. Its compiler gives me Javascript WITH static typing, and converts my code to a version of JavaScript that will run on the majority of the browsers, even internet explorer 8/9 or old Android browsers. No need for React,Angular, Webpack, Babel and all that stuff... As I'm not writing games or photoshop in the browser I see no need to use Rust,C,C++ and the SDL just to write web apps. IMHO some people ultimately miss the true usefulness and use case for WASM: making existing C,C++,... libraries available to Javascript developers, not replacing JS with language X or Z.
- steveklabnik 8y agoWe agree that that use-case is useful, and that’s exactly why we’re focusing on it. Augment, not replace.
- anderspitman 8y agoI'm excited at the prospect of compiling TypeScript directly to wasm in the future (see for example [0]). Someday you may be able to recompile that TS project and get substantial gains for free. [0] https://github.com/AssemblyScript/assemblyscript https://github.com/AssemblyScript/assemblyscript
- acdha 8y ago> I would love to do frontend web development but the current high-churn Javascript ecosystem makes me dizzy Learn the actual web: HTML, CSS, and JavaScript are stable and don’t require any tooling in modern browsers. It’s pretty civilized these days with native support for ES6 classes, modules, arrow functions, data structures, spread & destructuring, fetch, async/await, etc. and things like CSS Grid for layout (head over to https://developer.mozilla.org https://developer.mozilla.org for anything unfamiliar in that list). Support for non-current browsers can wait, hopefully until someone is paying you, and that’s a great time to learn about polyfills and transpilers. The nice part about that is that it also plays great with WASM: you can write clean JS and call back and forth easily rather than trying to get dreadnaught-weight frameworks to work differently. I’m enjoying that right now since I see substantial gains swapping Rust-based hashing code to replace pure-JS alternatives.
- gameswithgo 8y agoYou can also just write plain, vanilla javascript and make a working web app. I have one, no npm is involved! It is nice.
- rl3 8y ago>So we are writing The Rust and WebAssembly Book. Awesome! What's there already is looking good. I wonder if it'll turn into an actual paper book some day like the second edition of TRPL did. [0] On that note, my copy just shipped today (or at least received a tracking number), so get yours now!* Alternatively TRPL is also free[1] of course, and there's a somewhat outdated PDF version[2] available. If you're motivated, you can just use that person's scripts to generate an updated copy probably. The advantage of those is that the online and unofficial PDF versions have colorized syntax; the no starch press edition does not last I checked. However, there's no reason not to buy it anyways if you're able. Personally nothing beats paper. [0] https://nostarch.com/Rust https://nostarch.com/Rust [1] https://doc.rust-lang.org/book/ https://doc.rust-lang.org/book/ [2] https://github.com/lise-henry/books https://github.com/lise-henry/books * = No conflict of interest exists here, Steve is just really nice to me on HN and I love Rust. :)
- steveklabnik 8y ago> my copy just shipped today Hooray! I got to actually hold one last week, it was... wonderful. I am biased though :p
- rl3 8y agoCongrats! You know I just realized, if there's ever a revised print edition it'll likely be sold as a second edition, and that'll make it the second edition of the second edition.
- steveklabnik 8y agoThanks! We’re changing the naming for this exact reason, the next iteration of the book is being called the “2018 edition” to match with the new edition scheme generally.
- ranit 8y agoThe linked nostarch page shows only 13 of 20 chapters as (AVAILABLE NOW). How is the printed book finished already?
- majewsky 8y ago> publish Rust code compiled to WASM on NPM leftpad-rs.js? :)
- fleetfox 8y agoAssuming you get better performance and less size something like lodash-rs would have been nice.
- jillesvangurp 8y agoIMHO things like WASM, web vr, and LLVM are all converging this year after years of cool demos, prototypes and gradual progress. Having Rust out there as a first class citizen is awesome. This year we should see the beginning of a minor revolution in front end development, where essentially anything targeting LLVM will be able to compile to WASM, be bundled as an NPM, and be usable in the context of web application for essentially anything done in javascript until now whether it is performance critical algorithms, manipulating the dom, writing to canvas, driving IO via web sockets, dealing with web gl and web vr, audio, etc. Breaking the monopoly Javascript has had on this space for close to 25 years is a good thing. Perhaps people will continue to use it but it will have to be on merits rather than just merely being the only game in town. In any case looking forward to having more choice in this space. IMHO, modern JS based frontend development is a combination of tedious, error prone, and backwards. If this honestly is the state of the art, then WTF. happened in the past 20 years.
- grey-area 8y agoThere is one huge change here (as compared to things like the golang wasm port) which makes this more likely to be adopted IMO: Rust compiled to WebAssembly doesn’t have a runtime. This results in small .wasm binary sizes that are proportional to the amount of Rust code that is being compiled to WebAssembly. Binary size is of huge importance since the .wasm must be downloaded over the network. The proportionality means you only pay (in code size) for what you use. In turn, that means it is feasible for existing JavaScript code bases to incrementally and partially adopt Rust. Great to hear they're taking this approach. I do think it'd be nice to have DOM access too though, as then you won't need JS at all - I do think long term the attraction of this is to replace JS as a front-end language, not just augment it, but it's nice they're taking an incremental approach.
- brighteyes 8y agoIt depends how you define "runtime", though. If you use Rust strings, you may get a large amount of code included to handle them. Also, if you use malloc, that adds a significant amount of code. It's true that languages like Rust have fewer runtime requirements than languages like Java but none of them are 100% proportional to the code you wrote.
- anderspitman 8y ago> In the most performance-sensitive contexts, JavaScript hinders rather than helps. Its dynamic type system and non-deterministic garbage collection pauses get in the way. Seemingly small code changes can result in drastic performance regressions if you accidentally wander off the JIT’s happy path. I'm seeing this repeated more and more as a compelling case for using WASM. I've even repeated it myself. Does anyone know of examples of JS optimized for one VM not performing well in others, leading to a significant cost? I ask this as a Rust/WASM fanboy. Not doubting; just curious. I feel like I've already read a couple anecdotes but can't remember.
- littlestymaar 8y agoI haven't done any performance-critical JavaScript for two years now and I know a lot a things have change with Turbofan, but I had been hitting slow paths of V8 so many times … The easiest to avoid were also the most painful when it comes to code organization : exception handling was so slow it was unusable. And it was affecting our ability to use modern JS, because the polyfil for `for of` or `async/await` had to use exception to comply with the spec. As a result we were stuck using ES5.1 for a really long time (because we needed to support mobile browsers, which are (or were at this point, at least) a new kind of IE6.