Monday, April 15, 2019

I saw David Pine speak on WebAssembly at the Twin Cities Code Camp Saturday.

This was the second of five talks I saw at this event. Both a Microsoft MVP (Most Valuable Professional) and a Google Developer Expert, David probably knows what he's talking about when he asserts its worth wondering if WebAssembly is "the new endgame" and I indeed found myself less dismissive of Blazor (the name comes from Browser + Razor) which will supposedly allow me to pen a SPA app with .NET Core's MVC and Razor markup only, free from any JavaScript! I've met enough C# people who hate JavaScript to assume Blazor would be a failed attempt to get those characters a viable terrarium uncontaminated with JS, however David Pine offered that the central argument for less JavaScript is that our development as developers is in a straightjacket if we are forced to author exclusively in JavaScript alone and not, for example, C, C++, C#, R, Go, and Rust, which may all be ported to a common format, Wasm (the W for Web and the asm for Assembly). You still have to have a little bit of JavaScript at the browser to reach out to a .wasm file and turn it on, so there really is no escape from JavaScript, but you may do your primary work and the vast majority of your work in a different language. (You probably don't want to have a hodgepodge of WebAssembly and JavaScript where you are crosstalking between the two as such will be performance expensive. Use JavaScript minimalistically as the door in and nothing more.) The world is wide and the web should reflect it. That is the central philosophy herein. To make it work the typical AST (abstract syntax tree) approach to walking keywords in code is used to compile the other languages down to WebAssembly, a binary instruction format. I think the Clang compiler may get used for the applicable languages. WebAssembly utilizes a stack-based virtual machine in a push/pop paradigm. Can I use? is a site here that has breakdowns of what is supported by what browser and if you search for WebAssembly it's looking pretty accessible for just about everything but old IE (Internet Explorer). In terms of what it is not, it is not some sort of instruction set like x86. It runs in the same sandbox as JavaScript itself and is not an outsider like the plugins for Google Chrome which do not. Emscripten is a toolchain (like a toolbelt only the tools are getting used sequentially in stages) that takes LLVM (Low Level Virtual Machine) bitcode in .wasm files and converts it to .wat (WebAssembly text) files which are human readable in a strictest sense though you won't really want to spend time reading the code it makes compared to your own code that compiled down there to begin with. I think WasmExplorer, WasmFiddle, and ijs.runtime (i for International) are tools to help you work and a Steve Sanderson one of the guys behind Blazor. The Uno Platform will let you make WebAssembly/XAML/UWP apps. The Mono runtime which implements the ECMA common language runtime is in the mix here too. Your .dll goes through Mono to the web as suggested here:

One thing that floored me in all of this is that the .dll nonetheless comes up to the browser as part of the deliverable instead of just being the kickoff point for compiling other stuff to ultimately exposition. This allows you to debug inside of your own .dll through the browser with Google Chrome Developer Tools. This also leads to the biggest problem, fat files sizes. The typical SPA application is three megabytes in size while a silly hello world app that David showed us was six. The powers that be are working on a way to treeshake the .dlls.

No comments:

Post a Comment