3 mins read
Motoko is a programming language used for developing canisters on the Internet Computer Protocol (ICP). One of the best things about Motoko is its strong type system. This system helps us catch errors early, before our code runs, which means fewer bugs and more reliable applications.
Just like languages like Rust, TypeScript, and Swift, Motoko makes it easier to write safe, clean code and avoid common mistakes. This makes it a great choice for building secure, scalable apps that run on the Internet Computer.
Primitive types are the basic building blocks of data in Motoko. These types are built into the language itself and are used to store simple values. They include:
Bool: This represents a boolean value, either true or false.Nat: This is for natural numbers, meaning only non-negative integers (like 0, 1, 2, 10, etc.).Int: This is for integers, which can be both positive and negative (like -5, 0, or 7).Float: This type is for numbers with decimals (like 3.14 or -2.71).Text: This is used to store sequences of characters, or strings (like "Hello, Motoko!").These primitive types form the foundation of data handling in Motoko. They help ensure that your data is used correctly and efficiently.
actor Example {
let isReady: Bool = true;
let count: Nat = 10;
let temperature: Int = -5;
let pi: Float = 3.14;
let greeting: Text = "Hello, Motoko!";
}
Sometimes we need to work with more complex data than what primitive types can offer. That’s where non-primitive types come in. These include things like arrays, records, and tuples.