Context: Odin’s Most Misunderstood Feature

Dev says Odin’s “context” is for hijacking libs — chaos ensues

TLDR: Odin’s “context” exists to override third‑party behavior like logging and memory use, not to save typing. The community split hard: critics call it sneaky global magic, fans call it a lifesaver for fixing bad libraries without edits, with “printf‑gate” fueling memes and misunderstandings.

Odin’s creator just dropped a spicy clarification: the mysterious “context” isn’t a shortcut or a magic global — it’s a sneaky power plug to hijack third‑party code so you can swap out things like memory use and logging on the fly. Cue the comment orgy. One camp screamed “spooky global state!”, calling it “dynamic scoping cosplay” and insisting “just pass parameters like a normal language.” The other camp clapped back: this is a superpower, letting you fix bad libraries without touching their code. Testers bragged about flipping allocators mid‑run; systems folks called it “middleware without the middleware.”

The flashpoint? Printing. Newcomers hit Odin’s fmt functions and grumble about having to set a default context, while veterans say that’s exactly how you hook loggers and streams. “printf-gate” birthed the meme of the week: Schrödinger’s Context — both needed and not needed until you intercept it. Some confused it with Go’s Context (that’s for timeouts, folks), sparking explainers and eye-rolls. DI (dependency injection) fans argued you can solve this with clean APIs; Odin fans retorted most libraries aren’t clean, and context is the duct tape you keep for the mess. Read the docs if you dare: Odin and docs

Key Points

  • Odin’s implicit `context` variable is passed by pointer with the Odin calling convention and exists to intercept third‑party code behavior.
  • Default `context` values are defined in `package runtime` and are compiler-specific; the `Context` struct reveals its fields.
  • Marking procedures as “contextless” or “c” is discouraged because the need for context is by design not always obvious.
  • `core:fmt` printing requires context because `fmt.printf` wraps `wprintf` and uses a generic `io.Stream`, enabling interception and tracking.
  • The context provides two allocators (`context.allocator` and `context.temp_allocator`), and APIs can expose or be overridden to control allocation.

Hottest takes

“It’s just global state in a trench coat” — nullpointerdad
“It lets me fix your bad library without forking it” — alloc8r
“Schrödinger’s Context: required only when you touch it” — printfPanic
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.