The Secret to Faster, More Accurate Code: Mental Code Proofs

2025-07-16

This article unveils a technique for writing code faster and more accurately: performing "online" proofs. Instead of interrupting your coding flow, mentally prove your code's correctness as you write. The author details several strategies to aid in this process, including focusing on code monotonicity, utilizing pre- and post-conditions, maintaining invariants, and isolating the impact of changes. Inductive reasoning for recursive functions and data structures is also highlighted, along with advocating for "proof-affinity" as a code quality metric. Finally, the author suggests practicing mathematical proofs to sharpen your code-proving skills.

Read more
Development code proof

Baking the Y Combinator from Scratch: Part 1 - The Fixpoint Combinator

2025-04-09

This post delves into the Y combinator, a mathematical construct that implements recursion in functional languages without explicit self-reference. It begins by explaining fixed points, then progressively derives the formula for the Y combinator, explaining its self-replicating mechanism. Through analysis of the Ω combinator, the author shows how the Y combinator avoids infinite nesting by self-replication at runtime. The post also briefly introduces lambda calculus and formal systems, laying the groundwork for a deeper understanding of the Y combinator in later parts.

Read more
Development Y combinator

Solving Labyrinth's Goblin Riddle with Boolean Algebra

2025-03-06

This article demonstrates solving the classic Knights and Knaves logic puzzle from the movie *Labyrinth* using Boolean algebra. The author models the problem, using A for the answer, Q for the correct answer to the question, and G for whether the goblin is lying, deriving A = G⊕Q. By cleverly crafting the question to incorporate the other goblin's lying status, the equation simplifies, revealing the solution. The author argues that the formalized approach clarifies the steps and highlights the usefulness of formal systems as reasoning tools.

Read more