Which Language Should You Choose To Build on the Internet Computer? ⌨️

Seb
Code & State
Published in
8 min readDec 7, 2022

Choosing a language when starting a new project or career is a tricky decision. In the case of a large project, taking the wrong decision can cost you months of hard work and can be one reason for failure.

The 5 languages that we will explore today: Motoko, Rust, TypeScript, Python, and WebAssembly!

In this article, we will explore and compare the languages that can be used to build on the Internet Computer so you can take the best possible decision for your project or career.

⚠️ Some details of this article are likely to evolve with future developments in the language ecosystem of the Internet Computer. I have done my research and spent a fair amount of time building on the Internet Computer but I strongly encourage you to complete this article by doing your own research.

WebAssembly

Let’s start our exploration with an important fact:

No matter which language you use, your code will end up compiled into a WebAssembly module (Wasm) that will be installed in your canister and is ultimately the code run by the Internet Computer.

A WebAssembly module (left) and a canister (right) which is ultimately a WebAssembly module and an associated memory.

WebAssembly is portable, safe, efficient & universal: any hardware in the world should be able to run a WebAssembly program in a safe and fast manner.

You can think of WebAssembly as an intermediary language between the code that you’ll write and the hardware of the computer it will run on.

Interesting fact: WebAssembly was co-designed by Andreas Rossberg who is also the architect behind the Motoko language.

WebAssembly is a technology that everyone aspiring developer should take at least a few hours to understand. It has been designed as a standard for years to come for any type of application(desktop, mobile, web…) and it is becoming more and more popular.

If WebAssembly is so fast, secure & efficient why don’t we all learn it and write our application directly with it?

WebAssembly is a low-level language that provides almost no abstraction and is close to how a computer process machine instruction — you don’t want to use it to write dApps. It’s not impossible but it is not realistic for any complex project. However, if you have a few hours to spare I encourage you to try to write a canister directly in WebAssembly (just for fun!). Here is what a simple canister written in WebAssembly looks like.

Time to look into other options!

Motoko

This new language was designed by the DFINITY foundation specifically for the Internet Computer.

Motoko directly integrates a lot of the features of the platform (actor model, query/update calls, asynchronous calls, stable variables, orthogonal persistence…) in the syntax which makes it generally easier to use for the Internet Computer than other languages.

It was also designed with safety in mind: the language is highly typed which makes it harder to mix different data types in your code, preventing one common type of error. It also incorporates safe arithmetic which makes it nearly impossible to encounter overflow, removing one other common type of error.

Motoko will benefit from continuous improvements by the DFINITY foundation as the language has been incorporated into the long-term roadmap.

As it’s a new language the ecosystem around it is still really small. Finding tutorials, packages, toolings, and Motoko developers is more difficult than with other languages. Efforts have been started in the community to provide better learning resources for Motoko or provide better tooling/packages (and I plan to do my fair part!).

A few major projects built with Motoko.

A major point to consider before starting to learn Motoko is that (for the time being) the language can only be used on the Internet Computer. If you consider starting learning Motoko make sure that you are committed to building on the Internet Computer.

If you are interested in learning Motoko here are a few resources to get started:

Rust

Rust is a powerful, modern, and low-level programming language that is a solid option to build on the Internet Computer. It enforces type and memory safety through its compiler. Like Motoko, it also compiles directly to WebAssembly.

Rust was introduced in 2010 by Mozilla as an alternative to C++. Being a mature language used by major companies ( Mozilla, Cloudflare, Dropbox) around the world with a thriving developer community there are toolings, documentation, and package available for almost all of your needs.

Rust can be used to build on other blockchains (Polkadot, Solana, Near…) and generally is becoming the top choice language for any project where performance matters or where you need to interact directly with the hardware (Embedded devices, game engine, virtual reality, cloud architecture…).

Most of the canisters written by DFINITY (ICP Ledger, Governance, Internet Identity…) and the core IC protocol have all been written in Rust.

However, Rust being a low-level language has a steep learning curve and it can be frustrating to deal with his compiler, especially as a beginner. It will take more time to learn Rust and become more productive with it than any other choice on the list. This can slow down your productivity as you have more things to take into account.

Another point to consider: even though you have a lot of Rust-based learning materials available outside of the Internet Computer ecosystem, the amount of Rust-specific resources for this ecosystem is still very limited ( There is no good introduction to “Rust on the Internet Computer”).

If you are starting your career as a developer on the Internet Computer and don’t have a lot of experience, I wouldn’t recommend starting directly with Rust.

If you are interested in learning Rust here are a few resources to get started:

A few major projects built using Rust.

While Rust and Motoko are (for now!) the two officially supported languages for the Internet Computer. In theory, any language that compiles to WebAssembly (or that has a runtime that compiles to WebAssembly) could be used to write canisters smart contracts.

Thanks to the community and the work of Demergent Labs we have development kits available for other popular languages!

TypeScript (JavaScript)

“Any application that can be written in JavaScript, will eventually be written in JavaScript.”

TypeScript is a superset of JavaScript that adds strict type-checking and other features to the language. If you already know JavaScript then moving to TypeScript is easy and can be done progressively.

A huge advantage of using TypeScript is that you will have access to the biggest developer community (more than 17.5 million developers worldwide) with probably the richest ecosystem of packages.

Another one is that for the frontend part of your application, you’ll have to use TypeScript (or JavaScript) anyway so assuming you are using TypeScript for the backend it means that you will only have one language to use for your whole stack!

The Typescript CDK (Azle) recently reached feature parity with the Rust & Motoko CDKs.

If you want to learn more about how to use Typescript to build on the Internet Computer I recommend browsing this repository and checking the official documentation.

Azle: The TypeScript SDK.

Python

Another CDK that Demergent Labs is working on is for the famous Python language.

Python is a high-level and general-purpose programming language that is often used as a first language to train new developers because it is relatively easy to use and readable. It is also one of the most used languages for data science, machine learning, and scripting.

Kybra is a Python CDK for the Internet Computer; it is still experimental as it hasn’t reached feature parity with other compilers.

If you want to learn more about Kybra (Python CDK), feel free to browse this repository; you can also join the DSCVR community.

Performances & benchmark

Unfortunately, at the time of writing this article, we don’t have a lot of benchmarks available to compare our different options.

What we do now is that:

  • Initial intuition: Rust & Motoko compiles directly to WebAssembly while Python & TypeScript have a runtime that is compiled to WebAssembly and is installed in the canister: this means that Rust & Motoko are likely to be the most efficient languages.
  • A first benchmark is showing results that confirm the initial intuition.
  • Performances of all languages are likely to evolve, and performances could be significantly improved for Azle and Kybra.

Recommendations

The following recommendations are based on my personal experience and the feedback of projects I’ve talked to.

If you are focused on the Internet Computer, don’t have a lot of experience with low-level language (C/C++/Rust), and wanna get started quickly I would recommend using Motoko.

The impact of quickly getting to one point where you can comfortably write dApps shouldn’t be underestimated. It’s better to learn Motoko and then move to Rust if you feel the need than directly trying to learn Rust but not making much progress and stopping out of frustration. The same would apply to a project with a smaller team that wants to move fast, if your first focus is to get to an MVP quickly then Motoko is probably the best option.

I would recommend Rust if you or your team are already familiar with the language or if you are designing products.

If you are unsure about which platform to build on, Rust is a better choice than Motoko because you always have the option to move to another ecosystem.

If you already know TypeScript/Python and wanna play around with the Internet Computer then definitely check out Azle/Kybra.

Conclusion

Because the Internet Computer is built on top of a fundamental & widespread technology (WebAssembly) the possibilities offered to developers in terms of languages and associated toolings for building on the Internet Computer are extremely diverse and will keep on growing over the next few years.

--

--