Design, Build and Optimize Systems Software in Odin
Introduction
- What This Book Is
- What This Book Is Not
- Who This Book Is For
- Prerequisites
- How to Read This Book
- Technical Conventions
- Acknowledging the Ecosystem
- What You Will Know After This Book
Chapter 1: Why Odin? The Design Philosophy
- The State of Systems Programming in 2026
- What Odin Is and Is Not
- Data-Oriented Design as First-Class Concern
- The Pragmatist’s Manifesto: Simplicity Over Power
- Comparison Landscape: C, C++, Rust, Go, Zig
- The Odin Promise
Chapter 2: Setting Up the Development Environment
- Installing the Odin Compiler
- Building from Source
- Your First Program: Hellope World
- The odin Command: Build, Run, Test, Check
- Editor and Language Server Setup with OLS
- Project Structure and Collections
- Verifying Your Setup
Chapter 3: Language Fundamentals: Declarations, Types and Values
- Statements, Expressions and Automatic Semicolon Insertion
- Variables: Declaration, Initialization and Zeroing
- Constants and Compile-Time Expressions
- Primitive Types: Integers, Floats, Booleans, Runes
- Distinct Types vs Aliases: Type Identity Matters
- Literals: Numbers, Strings and the Underscore Convention
- Summary
Chapter 4: Procedures: Functions with Intent
- Declaring and Calling Procedures
- Parameters, Named Results and Multiple Return Values
- Calling Conventions: odin, c, contextless and Beyond
- Variadic Procedures and Type Safety
- Defer and Scope-Guaranteed Cleanup
- Tail Calls and Recursion
- Summary
Chapter 5: Control Flow Without Hidden Complexity
- Range-Based For Loops
- If Statements and Ternary Expressions
- Switch: Exhaustive, No Fallthrough, Pattern-Match-Free
- The or Family: or_return, or_else, or_break, or_continue
- The When Statement: Compile-Time Branching
- Why No Goto and No Exceptions
- Summary
Chapter 6: Composite Types: Structs, Unions, Enums and Bit Sets
- Structs: Layout, Alignment, Padding and #packed
- Unions and #raw_union: Tagged vs Untagged
- Enums and Enumerated Arrays
- Bit Sets: Type-Safe Flag Management
- Fields, Tags and the Using Statement
- Aggregate Initialization and Partial Initialization
- Summary
Chapter 7: Memory Layout: From Bytes to Caches
- How the Compiler Lays Out Types
- Alignment, Packing and ABI Requirements
- Measuring Size and Offset with sizeof and alignof
- Cache Lines, Prefetching and Data Locality
- Struct Layout Optimization Techniques
- Matching C Layouts: Foreign Interop and Hardware Formats
- Summary
Chapter 8: Arrays, Slices and Dynamic Arrays
- Fixed Arrays: Stack-Bound and Sized
- Slices: Pointers with Length
- Dynamic Arrays: Growth, Allocation and Ownership
- Slice Operations: Append, Delete and Copy
- Array Arithmetic and Component-Wise Operations
- When to Use Each Array Type
- Summary
Chapter 9: Maps and String Handling
- The Map Type: Hash Table Semantics
- Map Keys: What Is Allowed
- Strings as Pointer Plus Length
- UTF-8, Runes and Character Encoding
- C Strings and Interop with External APIs
- String Interning and Pooling
- Summary
Chapter 10: Pointers, Memory Addresses and Ownership
- Single Pointers: ^T Semantics
- Multi-Pointers: [^]T for Typed Untyped-Length Access
- Rawptr and Type Erasure
- Pointer Arithmetic and Unsafe Access
- Memory Ownership: The Programmer’s Responsibility
- Common Pointer Mistakes and Corruption Patterns
- Summary
Chapter 11: The Context System and Memory Allocators
- What the Context Is and How It Flows
- Context Fields: Allocators, Logger, RNG and More
- new, make, free and delete
- The Temporary Allocator: Arena-Style Allocation
- Tracking Allocator: Debugging Memory Issues
- Custom Allocators and Context Overrides
- Summary
Chapter 12: Parametric Polymorphism: Generic Procedures and Types
- Explicit vs Implicit Parametric Polymorphism
- Where Clauses and Type Constraints
- Parametric Structs: Generic Data Structures
- Type Inference and Its Limits
- Type-Specific Code Paths (No Overloading)
- Comparison with Rust Traits and C++ Templates
- Summary
Chapter 13: Data-Oriented Design with Odin
- What Data-Oriented Design Means
- AoS vs SoA vs AoSoA: Memory Layouts for Performance
- The #soa Modifier: Odin’s Struct of Arrays
- SIMD Vectors: Native Support and Swizzling
- Matrix and Quaternion Types
- Designing Cache-Friendly Data Structures
- Summary
Chapter 14: Error Handling: Explicit by Design
- Why No Exceptions: Design Rationale
- Multiple Return Values for Success and Error
- The or_return Pattern
- Custom Error Types and Discriminated Unions
- Error Propagation Strategies
- Comparison with Go and Rust Approaches
- Summary
Chapter 15: Packages and the Module System
- Packages: Directories as Units of Compilation
- Import Names and Aliases
- Visibility: @(private), #+private and Export Control
- Core, Vendor and User Collections
- Foreign Import and Foreign Blocks
- Structuring Large Projects
- Summary
Chapter 16: Foreign Function Interface: Calling C and the OS
- Foreign Import: Linking to Libraries
- Foreign Blocks: Declaring External Symbols
- Type Mapping: Odin Types to C Types
- Calling Conventions and ABI Details
- String Interop: string vs cstring
- Working with System Libraries: Windows, POSIX, macOS
- Summary
Chapter 17: File I/O, Networking and the Operating System
- The New core:os v2: Design and API
- File Operations: Open, Read, Write, Seek
- Paths, Directories and Environment
- Networking with core:net: Sockets and DNS
- Non-Blocking I/O with core:nbio
- Resource Lifetimes and Cleanup
- Summary
Chapter 18: Concurrency and Threading
- Threads and the Operating System
- Creating and Managing Threads
- Thread Pools and Task Queues
- Mutexes, Read-Write Locks and Semaphores
- Atomic Operations and Lock-Free Programming
- Context in a Multi-Threaded World
- Summary
Chapter 19: Runtime Type Information and Reflection
- Typeid: Runtime Type Identifiers
- The Reflect Package: Inspecting Types
- Field Tags and Metadata
- Any Type and Type Erasure
- Use Cases: Serialization, Debugging and Tooling
- The Cost of RTTI
- Summary
Chapter 20: Inline Assembly and Intrinsics
- Intrinsics: Compiler-Hinted Operations
- SIMD Operations in core:simd
- The New Inline Asm Template System
- Writing Portable Assembly
- When to Use Assembly vs High-Level Code
- Profiling Assembly Output
- Summary
Chapter 21: Project 1 - A Command-Line Binary File Parser
- Requirements and Design Decisions
- Defining the File Format with Odin Types
- Parsing Logic and Error Handling
- Command-Line Argument Processing with core:flags
- Testing with Synthetic Input Files
- Packaging and Distribution
- Summary
Chapter 22: Project 2 - A Custom Memory Allocator
- Allocator Requirements and Interface
- Implementing an Arena Allocator
- Implementing a Pool Allocator for Fixed-Size Objects
- Integration with the Context System
- Performance Measurement and Comparison
- Debugging and Validation
- Summary
Chapter 23: Project 3 - A Data-Oriented Physics Simulation
- Simulation Requirements and Data Model
- Implementing SoA Particle Storage
- SIMD-Accelerated Force Calculations
- Fixed Time-Step Integration Loop
- Performance Analysis and Optimization
- Visualization Options
- Summary
Chapter 24: Project 4 - A Multithreaded Job System
- Design Requirements and Threat Model
- Thread Pool Implementation
- Work Queue and Scheduling
- Thread-Local Storage and Context Management
- Synchronization and Correctness Guarantees
- Testing for Races and Deadlocks
- Summary
Chapter 25: Project 5 - A TCP Networking Service
- Service Requirements and Architecture
- Socket Programming with core:net
- Connection Handling and Event Loop
- Handling Multiple Concurrent Connections
- Protocol Design and Message Framing
- Resource Management and Graceful Shutdown
- Security Considerations
- Performance and Scaling
- Summary
Chapter 26: Build Systems, Optimization and Tooling
- The Odin Build System
- Performance Optimization
- Profiling Tools
- Debugging
- Production Deployment
- Summary
Chapter 27: Testing, Debugging and Quality Assurance
- Odin’s Built-in Testing Framework
- Property-Based Testing
- Testing Patterns and Best Practices
- Advanced Debugging Techniques
- Static Analysis and Code Quality
- Continuous Quality
- Summary
Conclusion
- What Makes Odin Unique
- Skills You Gained
- Next Steps
- The Future of Odin
- Final Thoughts
Appendix A: Language Quick Reference
- Literals
- Types
- Procedures
- Control Flow
- Operators
- Memory
- Meta Operators
- Attributes
Appendix B: Compiler and Tool Reference
- odin build
- odinfmt
- Odin Language Server (OLS)
- Testing
- Useful Commands