Explores how to make illegal state transitions unrepresentable in a type system using a pizza builder as a model. Compares Python, Java, Kotlin, Rust, and Gleam, demonstrating that static typing is necessary but not sufficient — phantom types combined with extension functions (Kotlin), impl blocks (Rust), or constrained parameter types (Gleam) are needed to avoid combinatorial explosion of builder classes. Java lacks the mechanism to attach methods to specific generic types, making it a poor fit for smart builders. Kotlin and Gleam achieve linear code growth when adding new constraints, unlike Java's combinatorial growth.
Sort: