The Grain programming language

For those of us interested in WebAssembly, a relatively new runtime that’s available in modern browsers and in Nodejs, it’s been interesting to watch the explosion of new programming languages that have come out targeting this platform. Lately I’ve been experimenting with AssemblyScript, a nice language with a very familiar syntax (basically it’s a subset of Typescript).

I’ve also been looking at Grain.

The Grain language looks like a more functionally oriented language than AssemblyScript (more like Elm, Purescript and Reason) but with a JavaScript like syntax mixed with more powerful functional concepts such as algebraic types, pattern matching, etc. The language is small and seems pretty quick to learn.

https://grain-lang.org/

Getting Started with AssemblyScript

AssemblyScript, in my opinion, is probably the best entrypoint into writing WebAssembly for web developers. It’s a programming language with a familiar syntax, basically it’s a subset of TypeScript, i.e. JavaScript with type annotation. From a JavaScript developers point of view its pretty straightforward, from a Typescript developers point of view, you’ll notice that it’s missing certain conveniences. There’s basically no smart type inferencing so you’ll need to give everything a type. There are no union types and no any types so it’s a lot stricter.

None of this is much of a hardship however and this gets you past WebAssembly’s own arcane Lisp-ish, FORTH-ish language syntax (which I kind of dig TBH) and also give you access to more advanced types such as strings and records. The basic WebAssembly language only handles integers and floats.

Implementing a Javascript-like language implies a lot of other things. Number one of those is memory management, automatic garbage collection and function closures. None of this exist WebAssembly and was therefore needed to be built into AssemblyScript.

The end result however is really nice. While still at an early stage of development compared with more C and Rust-based solutions. I think we have a good system to explore the power of WebAssembly without too much sacrifice. The problem domain for AssemblyScript at this stage is still very small and restricted to computationally heavy things like crypto and image processing but it holds out the promise of being able to completely eliminate all native code dependencies. I think it’s a good time for web developers to really start paying attention to this.

For a good introduction to Web Assembly see https://www.sitepen.com/blog/getting-started-with-assemblyscript/

⚡️ WAlt is an alternative syntax for WebAssembly text format.

⚡️ WAlt is an alternative syntax for WebAssembly text format. It’s an experiment for using JavaScript syntax to write to as ‘close to the metal’ as possible. It’s JavaScript with rules. .walt files compile directly to WebAssembly binary format.

Highlights:

Write “close to the metal” JavaScript!

No C/C++ or Rust required, just typed JavaScript.

Zero dependencies 100% written in JS.

Fast compilation, integrates into webpack.

https://github.com/ballercat/walt