Is Dfinity not far from the line? New release of the Motoko programming language and the Canister SDK

In the three rounds of financing, the company won a $195 million public-chain platform Dfinity, and its development team today released its programming language Motoko and the Alpha version of the software development kit Canister SDK.

It is reported that Dfinity has been favored by first-line speculators such as Andreesen Horowitz and Polychain Capital. It was once considered a strong competitor of the “next generation” public chain, and the Chinese community called it “Tiffany”, and its own definition. It is becoming an "internet computer."

Canister SDK

(Image courtesy of Dfinity)

What is the so-called Internet computer?

Before we understand the products that Dfinity released this time, we need to understand two concepts, one is "Internet computer" and the other is "Canister".

So, what exactly do they mean? Let’s look at the explanation given by the official:

"For software services written in the Motoko language, Internet computers provide an abstraction of a single shared operating system hosting these services. Each service is a Canister, which consists of metadata, static content, and Wasm of the compiled Motoko software. The module (which can also be a Wasm module from another language) .

Each Canister on the Internet computer implements a microservice that guarantees interaction with other microservices through tamper-proof, asynchronous messaging, and strong communication.

At the bottom, the Internet computer is a network of networked computers that communicate securely, working together for registered users, developers, and other computers.

Unlike traditional public or private clouds (such as AWS, Google Cloud Platform, or Microsoft Azure), programs hosted on the Internet computer platform are distributed, and the platform itself is not owned and operated by a single private company.

Instead, its distributed architecture allows multiple computers to run as a powerful virtual machine. This virtual machine does not have a single point of failure, it runs independently of the traditional IT technology that is vulnerable. As a result, Internet computers provide a unique, open and unstoppable platform for hosting Motoko microservices. Well, in fact, Dfinity's vision and Ethereum are "one hairy", we can regard it as a competitive product.

Canister SDK and Motoko programming language

Simply put, the Canister SDK is designed to make it easy to build applications and services on the DFINITY platform.

According to the official information released by DFINITY, the current Canister SDK is only an Alpha version, which only supports macOS and Linux platforms for the time being, and developers will periodically check and try new features before releasing the official version .

Motoko, a modern programming language, is designed to give programmers who are familiar with modern object-oriented and functional programming idioms in JavaScript or other modern programming languages ​​such as Rust, Swift, TypeScript, C#, or Java. Easily use this language and contribute to the "DFINITY" platform.

The Motoko language allows programmers to use modern programming habits, including special programming abstractions for distributed applications. Each application consists of an actor that communicates with other actors without using a shared state, but instead uses (asynchronous) messaging.

The actor-based programming abstraction of the Motoko language allows for human-readable messaging patterns, and they force all network interactions to adhere to certain rules and avoid some common mistakes.

Specifically, the Motoko type system statically checks whether each motoko program is safely executed on all possible inputs without an internal type error. Therefore, it excludes programming trap classes that are common in other languages, including null pointer errors, parameter and result type mismatches, and many other trap types.

Motoko language highlights

1, native Canister support

actor Counter { var value = 0; public func inc() : async Nat { value += 1; return value; }; } 

The Motoko language has native support for the Internet computer software Canister, which is represented as an actor, an autonomous object that encapsulates its state and communicates via asynchronous messages.

2, coding in direct style order

 actor Factorial { var last = 1; public func next() : async Nat { last *= (await Counter.inc()); return last; } } 

On Internet computers, the software Canister calls other Canisters asynchronously, but the Motoko language allows you to program your system in direct style order.

Asynchronous messages are function calls that return a future, and the await structure allows link calls as if they were synchronous.

3, Modern type system

 type Tree<T> = { #leaf : T; #branch : {left : Tree<T>; right : Tree<T>}; }; 

Func iterTree<T>(tree : Tree<T>, f : T -> ()) { switch (tree) { case (#leaf(x)) { f(x) }; case (#branch{left; right }) { iterTree<T>(left, f); iterTree<T>(right, f); }; } }

The design of the Motoko language is very intuitive for those familiar with Javascript and other popular programming languages, but it has modern language features such as complete structure types, generics, variant types, and verification pattern matching.

4, automatically generate IDL files

 service Counter : { inc : () -> (nat); reset : () -> (); } 

The SDK will export your interface definitions, so other Canister, browser resident code, and licensed smartphone apps can call your function. The Motoko compiler also reads and writes interface definition files, allowing Motoko to seamlessly interact with Canister, written in other programming languages.

5, Orthogonal persistence (Orthogonal persistence)

 import Dict = "mo:dict"; 

Actor Registry { type Id = Nat64; let dict = Dict<Id>(); public func register(name : Text, id : Id) { dict.insert<Id>(name, id); }; public func lookup(name : Text, id : Id) : async ?Id { dict.lookup<Id>(name); }; }

The Internet computer will keep the register page that Canister runs. Therefore, the state of the participant and all its register data structures will exist indefinitely without the need to explicitly "save" them. Motoko provides a number of features to help you take advantage of this environment, including language features that allow you to implement self-migration when upgrading Canister software.

In addition, Motoko offers a lot of cool features, including deep support for WebAssembly virtual machines, which allows you to link to your Canister using modules written in other languages.

Want to learn more about the Dfinity SDK? You can read it here: https://sdk.dfinity.org/developers-guide/quickstart.html

About the Motoko language? You can see it here: https://sdk.dfinity.org/language-guide/index.html