Odin language
A data-oriented systems language with distinct typing: manual memory through explicit allocators, no classes or inheritance, built-in SOA and SIMD types, and a foreign system that binds C libraries directly.
Overview
Odin is an imperative, systems language positioned as an alternative to C: explicit allocators instead of a garbage collector, and deliberately no classes, methods, or exceptions. It exists so that high-performance code reads as the data it transforms, while the whole specification stays small enough for one person to memorize.
Code
import "core:fmt"
main :: proc() {
year := 2016 // untyped literal; defaults to int
mass: u32 // declared and unset: zero value is 0
fmt.println(year + 10, mass + 70) // operators consume: 2026 70
}
Vector3 :: struct { x, y, z: f32 }
Direction :: enum { North, East, South, West }
Flags :: bit_set[Direction] // one bit per enum member
main :: proc() {
xs := [?]int{2, 3, 5} // fixed array: length is in the type
sl := xs[1:] // slice: a view, not a copy
v := Vector3{1, 4, 9}
on := Flags{.North, .West}
assert(len(sl) == 2 && v.x + v.z == 10 && Direction.South not_in on)
}
import "base:intrinsics"
import "core:fmt"
sum :: proc(xs: $T/[]$E) -> E
where intrinsics.type_is_numeric(E) { // T and E bound from the argument
total: E
for x in xs { total += x }
return total
}
divide :: proc(a, b: int) -> (q, r: int) { return a/b, a%b }
main :: proc() {
q, r := divide(17, 5)
fmt.println(sum([]int{q, r}), q, r) // 5 3 2: calls consume the units
}
import "core:mem"
Particle :: struct { pos, vel: [3]f32 }
main :: proc() {
buf: [1 << 16]byte // the arena's backing store
arena: mem.Arena
mem.arena_init(&arena, buf[:])
context.allocator = mem.arena_allocator(&arena) // via the implicit context
defer mem.arena_free_all(&arena) // the whole region, one call
ps: #soa[dynamic]Particle // one array per field
append_soa(&ps, Particle{{0, 0, 0}, {1, 0, 0}})
for i in 0..<len(ps) { ps[i].pos += ps[i].vel } // array programming
}
#soa layout.Distinctive traits
- Memory is manual:
new,makeanddeletetake an allocator, and an arena frees a whole subsystem in one call. - Implicit context: allocator, logger and assert handler travel with every call, so third-party code can be redirected without editing it.
- Distinct typing:
distinct intis a new type and every width change is explicit, so no value widens silently. - Layout is a language feature:
#soatransposes a struct array into per-field arrays, and#simd[N]Tvectors map onto hardware registers. - Data and code stay separate — no classes, methods or exceptions; errors are ordinary return values forwarded with
or_return. - Also built in: tagged unions with exhaustive type switches, bit sets for flag sets, and a
foreignblock binding C libraries.
Status
Active but pre-1.0: the compiler is written in C++ and emits native code through LLVM (per the FAQ), shipping dated dev- builds with no 1.0 release. Compiler and libraries use the zlib licence.
History
In late July 2016 Ginger Bill began Odin out of frustration with C++, first as a Pascal clone before moving to C-like syntax; the repository went public on 23 November 2016. The documented influences are Pascal, C, Go, Oberon-2, Newsqueak and GLSL.
Sources & references
- Official siteodin-lang.org
- Overview of Odin — language documentation (Ginger Bill)odin-lang.org
- Frequently Asked Questions — Odin documentationodin-lang.org
- odin-lang/Odin — compiler, core library and vendor bindingsgithub.com
- Odin releases — earliest tag v0.0.3c (23 November 2016)github.com
- Odin licence (zlib)github.com
- Exceptions — And Why Odin Will Never Have Them (Ginger Bill, 2018)gingerbill.org