I’m thinking about some use cases of WebAssembly and would like to share them here. This could motivate the creation of new shards by the community and expand the Crystal language’s reach to more places. Please help me know if I missed some potential use cases:
Front-end web: running Crystal in the browser, maybe with DOM support.
Interop with Node or Deno: create Crystal “libraries” that can be loaded on those runtimes.
Writing Smart Contracts for blockchains that support WASM as a target (like the Internet Computer or Ethereum2).
Interop with Dart for writing Flutter apps.
Writing serverless apps with Cloudflare Workers.
Writing Istio plugins (Kubernetes Service Mesh).
What else is possible? What do you would like to be able to do with it?
Really, I want to do the entire front-end of my site in WASM. A custom IRC chat client, and Video player would fix so many issues if we didn’t have to fight CSS and browser compatibility. I think it could make testing these components a lot easier than spinning up browserstack instances on github and having no insight in to why android on samsung failed, but android on pixel worked fine.
I’ve never actually worked with WASM, but seeing your example that looked like Lucky HTML markup made me think we could have type-safety markup that can be formatted with the crystal formatter, and linted with ameba. The tool chain alone would catch so many things.
That’s more two separate cases really. The CSS issue we run in to right now is that each version of Android (on each different device) seems to handle HTML inputs differently, and also rendering slightly different. When it comes to a chat component, you’re appending a div to the bottom of a list, but then telling that whole list to move up a certain amount. Having that whole deal in just being an app instead (I’d imagine) would make that so much easier to work with.
Maybe it wouldn’t be HTML rendered from Crystal, but more of a “cocoa”-like structure? I have no clue…
But also having the ability to write out normal HTML for the bits that don’t need to be super low level would mean that I don’t have to write Vue anymore
div(class: "message") do
This doesn’t wouldn’t fix the issue of cross-device compatibility, but it would fix the issues that the crystal formatter and ameba would catch. Depending on how it all works, and if Spec could be used, maybe it could also be tested a lot easier.
describe ChatComponend do
it "renders hi" do
Using WASM or not won’t change the fact that you would have to deal with the browser’s HTML/CSS engine. The only way around it is to use a screen-sized canvas with WebGL and render everything. This is exactly what Flutter Web does and they achieve a quite good level of consistency among all platforms.
Aside from that, most frameworks have some level of polyfills and great tooling that help a lot with compatibility and testing. A Crystal framework with WASM can try to play a catch-up game with them but it will definitely be behind for a very long time.
Serverless functions with WebAssembly seem to have a bright future. We are implementing a WebAssembly platform here at Shopify, you already pointed out Cloudflare, and there are others such as Fermyon.
Based on my quick POC this week, Crystal has a much friendlier developer experience than other existing options like Rust.
I also want to clarify that I’m really excited for web assembly support and all it could bribg! I was just suggesting Elm or Mint because they already exist and are relatively stable. But my recommendation will definitely change in the future!