Skip to content

Hello World

Create a folder odin_course and a file hello.odin inside it.

package hello

import "core:fmt"

main :: proc() {
    fmt.println("Hellope!")
}

You can run the program using the command odin run .

$ odin run .
Hellope!

Explanation

In each chapter, I will give a quick explanation of each line. As we go further along, we peel the onion layer by layer. Deepening our understanding and explanations.

package hello

Declare the package name hello. All Odin files should start with a package declaration and all Odin files in a folder should have the same package name.

import core::fmt

core is like a standard library of Odin. It contains utilities that we can use in our program. core:fmt has fmt.println. We use it to print a message on the screen.

main :: proc() {
  // do something here
}

main is a procedure (or function). It is the entry point of the program. When you run odin run . inside a folder, Odin looks for the main procedure in all files in that folder and runs whatever is inside.

There should be only one main procedure.

Understanding ::

:: is used to declare compile time constants. The compiler will copy paste all instances of main with whatever is on the right of ::.

For example:

LUCKY_NUMBER :: 7

main() :: proc() {
    fmt.println(LUCKY_NUMBER + 3)
}

The line fmt.println(LUCKY_NUMBER + 3) would be replaced by fmt.println(7 + 3).