Skip to content

Answers to Odin Questions ​

  1. How do you do anything asynchronously in Odin? if await/async isn't a thing, how do you do it? Odin lacks built-in async/await. Use threads from the thread package for concurrency, or implement custom coroutines. For I/O, rely on blocking operations or external libraries.

  2. What does a loop look like in Odin? Range-based: for i in 0..<10 { ... } C-style: for i := 0; i < 10; i += 1 { ... }

  3. How do you do a conditional in Odin?if condition { ... } else if other_condition { ... } else { ... }

  4. How do you do a function in Odin?proc name(params) -> return_type { body }

  5. How do you do a class in Odin? No classes; use structs with associated procedures: MyStruct :: struct { ... } and proc (s: ^MyStruct) method() { ... }

  6. How do you do a module in Odin? Each file is a module; import with import "path/to/module"

  7. How do you do a package in Odin? Declare at the top: package my_package;

  8. How do you do a library in Odin? Compile code into libraries using Odin's compiler (e.g., odin build -build-mode:static for static libs).

  9. How do you do a macro in Odin? No macros; use procedures, constants, or external build tools for code generation.

  10. How do you do a template in Odin? No templates; use parametric polymorphism (generics).

  11. How do you do a generic in Odin?proc name($T: typeid) (param: T) -> T { ... }

  12. How do you do a trait in Odin? No traits; use unions, any type, or runtime assertions for polymorphism.

  13. How do you define a type in Odin?MyType :: struct { ... } or MyType :: i32 (alias).

  14. How do you define a constant in Odin?MY_CONST :: 42

  15. How do you define a variable in Odin?var: int = 10 or var := 10 (type inferred).

  16. How do you define a pointer in Odin?ptr: ^int = &var

  17. How do you define an array in Odin?arr: [5]int = {1,2,3,4,5}

  18. How do you define a slice in Odin?slice: []int = arr[:] or slice = make([]int, len)

  19. How do you define a map in Odin?m: map[string]int (requires core:container or similar).

  20. How do you define a struct in Odin?Person :: struct { name: string, age: int }

  21. How do you define an enum in Odin?Color :: enum { Red, Green, Blue }

  22. How do you define an interface in Odin? No interfaces; use any type or unions with type assertions for dynamic behavior.