typestar

Language basics

27 steps in 9 sets of Odin.

Odin is a systems language in the spirit of Go's clarity and C's directness, built by Bill Hall (gingerBill) since 2016 for the joy of programming: no hidden control flow, data-oriented by temperament, and batteries like vector math and bit sets where game and tools programmers actually want them. It powers EmberGen and the rest of JangaFX's real-time VFX suite, which is exactly the work it was shaped by.

This tour covers the core as the current Odin compiles it: the three declaration operators, for as the only loop, switch with ranges, procedures with defaults and multiple named returns and explicit overload groups, fixed and dynamic arrays and maps, structs and enums and unions, defer, the or_return error idiom, the implicit context and its temp allocator, distinct types, parametric polymorphism, bit sets, and the core:strings, core:slice, and core:fmt packages. The encore ships complete programs. Every seed passes odin check and runs.

Start this tour

Values

  • The program shapeThe smallest Odin program: a package line, one import, and main bound with ::.
  • DeclarationsThree declaration forms: := infers, a plain : takes a type, :: binds a constant.
  • Basic typesSized integers and floats, a rune, and a bool for the lighthouse log.

Control flow

  • if and whenif with an init statement scopes the wind reading; when branches at compile time.
  • for loopsfor is Odin's only loop, wearing three costumes: range, C-style, and for-in.
  • switchTwo switches: one on a value with lists and ranges, one bare as an if-else ladder.

Procedures

  • ProceduresA tip calculator with a default parameter and named call-site arguments.
  • Multiple returnsBoxes and leftovers in one call: named results and the bare return that sends them.
  • Procedure groupsOverloading is explicit: a proc group lists exactly which procedures share a name.

Collections

  • Arrays and slicesA fixed week of temperatures and a slice borrowing three days of it.
  • Dynamic arrays[dynamic] grows on append and gives the memory back through delete.
  • MapsA harbor registry in a map: make, index, the ok idiom, and iteration.

Structs, enums & unions

  • StructsA kayak struct built by field name and by position, described by a plain proc.
  • EnumsA cargo enum, the .Name shorthand, and iteration over the type itself.
  • UnionsOne reading, two shapes: a temperature when the sensor works, a reason when not.

Idioms

  • deferCleanup declared next to the thing it cleans: defer runs at scope exit, in reverse.
  • or_return and or_elseOdin's error idiom: errors are ordinary values, and two operators shorten the plumbing.
  • The context systemEvery proc carries an implicit context; the temp allocator is its cheapest trick.

Types & generics

  • distinct typesCelsius and Fahrenheit share a layout but refuse to mix — distinct mints new types.
  • Parametric polymorphismOne largest() for ints and floats: $T takes the element type at compile time.
  • bit_setMarket days packed into bits: set literals, +=, membership, card, and complement.

The core library

  • core:stringsPrefix, search, and count on a workshop motto, split by a zero-allocation iterator.
  • core:slicemax, contains, and an in-place sort from the slice utility package.
  • core:fmt verbsThe printf verbs, Go-flavored: %d and %f, binary and hex, and %v for anything.

Encore

  • word_freq.odinA word-frequency table from a split iterator, a map, a sort, and a bar chart.
  • grade_report.odinQuiz scores fold into averages and letter grades, then a formatted class report.
  • temp_stats.odinA week of daily highs reduced to low, high and mean, with a scaled bar per day.

The other Odin tours