The VikiD Truth

Knowledge base / Computing

Read This! | | Quick Links | Algorithms | AssemblyLanguage | BASH | C-Programmming | CommonLisp | Computer Security | Databases | Emacs | Exploitation | Functional Programming | Firewalls | Git | Haskell | Javascript | Julia | Linux | Machine Learning | Metasploit |Machine Learning | Networking | Operating Systems |Open Data Science | Odin | Picolisp | Pharo Smalltalk | Purescript | Python | Racket | Scheme | Social Engineering | Unity | vim | V | Web Development | Windows WSL | Zig

Odin

Here is the truth Odin is built on: most programs are about transforming data, so the language should make data obvious and get out of the way. No classes, no hidden allocations, no garbage collector – just a clean, modern take on what C was trying to be.

What it is, in plain words

Odin is a general-purpose, compiled, statically typed systems language created by Ginger Bill (Bill Hall), first public in 2016. It aims at the same space as C, Zig and Jai: games, graphics, simulation tools, and anything where you want control over memory and performance without C’s footguns.

Its main ingredients:

It is used in production: JangaFX builds its real-time VFX tools (EmberGen and others) in Odin.

Why it matters

C is fifty years old and still everywhere, but its build model, header files, macros and undefined behaviour cost a lot of time. Odin keeps C’s mental model – structs, pointers, procedures, you know where every byte is – and removes the friction. If you enjoy knowing exactly what the machine is doing (the same instinct that draws people to PicoLisp’s tiny, transparent VM), Odin rewards it.

An everyday analogy: a well-organised workshop

C is an old workshop where every tool works but the drawers have no labels and some tools bite. C++ is that workshop with three more floors added over decades. Odin is a new workshop designed by someone who worked in the old one for years: same kinds of tools, labelled drawers, guards on the saws, and a big clean bench in the middle for the data you’re working on.

flowchart LR
  S["*.odin files in a directory = one package"] --> C["odin build ."]
  C --> L["LLVM backend"]
  L --> E["native executable"]
  C -. "context.allocator" .-> A["heap / arena / temp allocator"]

A hands-on example

Odin ships monthly dev-YYYY-MM releases (there is no 1.0 yet). Download one from odin-lang.org or GitHub, or build from source (needs LLVM and clang), then put odin on your PATH.

hello/main.odin:

package main

import "core:fmt"
import "core:strings"

Shape :: union { Circle, Rect }
Circle :: struct { r: f32 }
Rect   :: struct { w, h: f32 }

area :: proc(s: Shape) -> f32 {
    switch v in s {
    case Circle: return 3.14159 * v.r * v.r
    case Rect:   return v.w * v.h
    }
    return 0
}

divmod :: proc(a, b: int) -> (q, r: int, ok: bool) {
    if b == 0 do return 0, 0, false
    return a / b, a % b, true
}

main :: proc() {
    shapes := [?]Shape{ Circle{2}, Rect{3, 4} }
    for s in shapes do fmt.println(area(s))

    if q, r, ok := divmod(17, 5); ok {
        fmt.printf("17 = 5*%d + %d\n", q, r)
    }

    // Dynamic array, cleaned up when main returns
    words := make([dynamic]string)
    defer delete(words)
    append(&words, "void", "stump", "lisp")

    // Temporary allocator: scratch memory freed in one go
    joined := strings.join(words[:], ", ", context.temp_allocator)
    defer free_all(context.temp_allocator)
    fmt.println(joined)

    // Vector maths built in
    v := [3]f32{1, 2, 3}
    fmt.println(v * 2, v.zyx)
}
cd hello && odin run .

Note there’s no main.c-style header, no build script, no package manager: a directory is a package, and odin run . compiles it all.

Odin, C and Zig side by side

COdinZig
Memorymanual, malloc/freemanual, via context allocatorsmanual, allocators passed explicitly
Errorsreturn codes, errnomultiple returns, or_returnerror unions, try
Genericsmacrosparametric polymorphism ($T)comptime
Buildmake/cmakebuilt inbuild.zig
C interop–foreign import@cImport

Common misconceptions

Connections

Last edited · 1 revisions

Tags: #Computing