Using AssemblyScript to write TypeScript that compiles to WASM.

Assembly and assembly-like languages are very powerful in the sense that they allow for fantastic performance given how close they are to their execution environment (i.e the Virtual Machine they run on and so on), but at the same time, they usually lack everything we love about programming languages: the actual high-level abstractions such as IF statements, FOR loops, CLASSES and what not.

So using these low-level languages has a very steep learning curve, given how different they are from other languages. And that is what happens with WebAssembly (or WASM as it is also known), which is an assembly-type language that browsers now support (or should I say, are starting to support). You can use it when you _really _need that performance boost, the problem? It looks like this:

(module
  (func (param $lhs i32) (param $rhs i32) (result i32)
    local.get $lhs
    local.get $rhs
    i32.add))

Now, don’t worry if you’re trying to interpret that code and you’re not getting anywhere, WASM’s purpose is not to be manually written but instead, compiled to from other languages. So, you could be using Rust code and compile it into WASM or even Go. This means you can write web-compatible code in other languages and have browsers execute it. What?! Yes, you read that right, that is WASM’s main goal, to have a low-level interface for any other programming language.

Then again, if you want to use WASM, you need to learn one of these languages that now have a compiler to WASM and one such language is TypeScript (or almost) thanks to WebAssemblyScript.

#typescript #web-development #javascript #webassembly #programming

TypeScript to WebAssembly: What, How And Why
3.75 GEEK