Learn · 02
Why Ochre Exists & Design Philosophy
The engineering principles behind Ochre — explicit failure, local reasoning through value semantics, colorless concurrency, and zero-friction tooling.
Every programming language encodes a set of opinions about where bugs come from and where developers lose time. Ochre exists to answer a specific question: can a language feel as clean and direct as TypeScript or Go while catching the highest-impact runtime bugs before your code ever executes?
Principle 1: Make Absence and Failure Visible in Types
Null-pointer dereferences and forgotten exception handlers remain the most common sources of production crashes. Ochre removes null and untyped exceptions entirely:
- A value that might be absent has type
T?(Some(value)orNone). - An operation that can fail has type
T!E(Ok(value)orErr(error)).
You cannot accidentally treat a missing map lookup (map["key"]) as a string, because indexing a Map<K, V> always returns V?.
fn main() {
let config = #{ "host": "127.0.0.1", "env": "dev" }
let host = config["host"] ?? "localhost"
let port = config["port"] ?? "8080"
println("Listening on {host}:{port}")
}
Expected Output
Listening on 127.0.0.1:8080
Principle 2: Local Reasoning via Deep Immutability & Copy-on-Write
Shared mutable state is the root of aliasing bugs and data races. Rust solves this with ownership and borrow-checking lifetimes; garbage-collected languages allow pervasive shared mutation.
Ochre takes a third path optimized for ergonomics and local reasoning:
letbindings are deeply immutable. You cannot reassign aletvariable or mutate any nested list, map, or struct field reachable through it.varbindings use Copy-on-Write (Arc). Copying a collection is an O(1) reference-count bump; mutating a shared collection clones only when another reference exists.
fn main() {
var original = [1, 2, 3]
let snapshot = original
original[0] = 99
println("original={original}, snapshot={snapshot}")
}
Expected Output
original=[99, 2, 3], snapshot=[1, 2, 3]
Principle 3: Colorless Concurrency
In many ecosystems, introducing concurrency forces you to mark every caller async and duplicate standard libraries into sync and async variants. Ochre provides spawn { ... } tasks and typed Channel<T> queues backed by OS threads in the VM — any function can spawn work and join results without changing its signature.
Principle 4: One Binary, Zero Ceremony
Developers shouldn't have to assemble five third-party tools just to format code, run tests, or get editor diagnostics. The single ochre executable provides:
- Fast script execution (
ochre app.och) - Static checking (
ochre check) - Comment-preserving formatting (
ochre fmt) - Built-in test discovery (
ochre test) - Cranelift native compilation (
ochre build) - Language Server Protocol (
ochre lsp)
Common Mistake: Mutating a let Binding
Developers coming from JavaScript or Python often expect let to protect only the variable reference while still allowing element mutation. In Ochre, let protects the entire value:
fn main() {
let scores = [10, 20, 30]
scores[0] = 99
}
The type checker rejects this before execution with: cannot mutate immutable variable 'scores' and suggests declaring scores with var.
Exercise
Write a small function greeting(name: Str?) -> Str that returns "Hello, {n}!" when Some(n) is passed and "Hello, guest!" when None is passed.
Show Solution
fn greeting(name: Str?) -> Str {
let who = name ?? "guest"
return "Hello, {who}!"
}
fn main() {
println(greeting(Some("Ada")))
println(greeting(None))
}