<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Alexandre Manhães Savio</title><link href="https://alexsavio.github.io/" rel="alternate"/><link href="https://alexsavio.github.io/feeds/all.atom.xml" rel="self"/><id>https://alexsavio.github.io/</id><updated>2026-10-19T00:00:00+02:00</updated><subtitle>Freelance Software, Cloud &amp; AI Engineer</subtitle><entry><title>C++ to Rust, Part 1: The Everyday Vocabulary</title><link href="https://alexsavio.github.io/cpp-to-rust-part-1-basics.html" rel="alternate"/><published>2026-10-19T00:00:00+02:00</published><updated>2026-10-19T00:00:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2026-10-19:/cpp-to-rust-part-1-basics.html</id><summary type="html">&lt;p&gt;A phrasebook for C++ developers moving to Rust, part 1 of 3. Types, variables, overflow, control flow, functions, strings, containers, structs, enums, and null, each mapped from the C++ idiom you know to the Rust idiom you want, with the traps that a pure syntax swap&amp;nbsp;hides.&lt;/p&gt;</summary><content type="html">&lt;h2 id="tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;Most everyday C++ has a direct Rust counterpart, but the translation is rarely one keyword for another. What changes is the &lt;strong&gt;defaults&lt;/strong&gt;. C++ allows almost everything and makes safety&amp;nbsp;opt-in: &lt;code&gt;const&lt;/code&gt;, &lt;code&gt;explicit&lt;/code&gt;, &lt;code&gt;-Wall&lt;/code&gt;, sanitizers. Rust forbids almost everything and makes permission&amp;nbsp;opt-in: &lt;code&gt;mut&lt;/code&gt;, &lt;code&gt;as&lt;/code&gt;, &lt;code&gt;pub&lt;/code&gt;, &lt;code&gt;unsafe&lt;/code&gt;. So code that looks the same often behaves differently, and the biggest takeaway is to translate the intent, not the&amp;nbsp;syntax.&lt;/p&gt;
&lt;div class="toc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-this-series-is-and-what-it-is-not"&gt;What this series is, and what it is&amp;nbsp;not&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-one-big-shift-the-defaults-flip"&gt;The one big shift: the defaults&amp;nbsp;flip&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#toolchain-and-project-layout"&gt;Toolchain and project&amp;nbsp;layout&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#primitive-types-and-conversions"&gt;Primitive types and&amp;nbsp;conversions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#variables-immutable-inferred-always-initialized"&gt;Variables: immutable, inferred, always&amp;nbsp;initialized&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#integer-overflow-from-undefined-to-defined"&gt;Integer overflow: from undefined to&amp;nbsp;defined&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#everything-is-an-expression"&gt;Everything is an&amp;nbsp;expression&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#functions-no-overloading-no-default-arguments"&gt;Functions: no overloading, no default&amp;nbsp;arguments&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#strings-two-types-and-a-byte-count"&gt;Strings: two types and a byte&amp;nbsp;count&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#containers"&gt;Containers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#structs-and-classes"&gt;Structs and&amp;nbsp;classes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#enums-the-enum-class-c-wanted"&gt;Enums: the enum class C++&amp;nbsp;wanted&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#null-option-instead-of-nullptr"&gt;Null: Option instead of&amp;nbsp;nullptr&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#references-a-first-look"&gt;References: a first&amp;nbsp;look&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#printing-and-formatting"&gt;Printing and&amp;nbsp;formatting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#cheat-sheet"&gt;Cheat&amp;nbsp;sheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#traps-for-c-developers"&gt;Traps for C++&amp;nbsp;developers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-comes-next"&gt;What comes&amp;nbsp;next&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#references"&gt;References&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 id="what-this-series-is-and-what-it-is-not"&gt;What this series is, and what it is&amp;nbsp;not&lt;/h2&gt;
&lt;p&gt;This is not a &amp;#8220;rewrite it in Rust&amp;#8221; sermon, and it is not a language reference. It is a phrasebook, ordered as a learning path, for people who already write C++ for a&amp;nbsp;living:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Part 1 (this post)&lt;/strong&gt;: the everyday vocabulary. Types, variables, control flow, functions, strings, containers, structs, enums, and&amp;nbsp;null.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Part 2&lt;/strong&gt;: ownership and abstraction. Moves, &lt;span class="caps"&gt;RAII&lt;/span&gt;, borrowing, smart pointers, sum types, templates, traits, operators, errors, closures, and&amp;nbsp;iterators.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Part 3&lt;/strong&gt;: the advanced material. Threads and locks, lifetimes, compile-time programming, macros, self-referential&amp;nbsp;data, &lt;code&gt;unsafe&lt;/code&gt;, &lt;span class="caps"&gt;FFI&lt;/span&gt;, and how teams migrate real C++ code&amp;nbsp;bases.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each section shows a C++ snippet, the idiomatic Rust, and the &lt;strong&gt;semantic gap&lt;/strong&gt; between them. Syntax is the easy part. The gap is where the bugs and the surprises&amp;nbsp;live.&lt;/p&gt;
&lt;p&gt;Every snippet in the series was compiled with &lt;strong&gt;rustc 1.99 (edition 2024)&lt;/strong&gt; and &lt;strong&gt;Apple clang 21&amp;nbsp;with &lt;code&gt;-std=c++23&lt;/code&gt;&lt;/strong&gt;. Each snippet carries&amp;nbsp;the &lt;code&gt;#include&lt;/code&gt; lines&amp;nbsp;or &lt;code&gt;use&lt;/code&gt; imports it needs. A Rust snippet whose first line&amp;nbsp;is &lt;code&gt;// does not compile&lt;/code&gt; is there to fail, and it fails with the error code it&amp;nbsp;names.&lt;/p&gt;
&lt;p&gt;Two free resources cover similar ground and make good companions: Brown University&amp;#8217;s &lt;a href="https://cel.cs.brown.edu/crp/"&gt;C++ to Rust Phrasebook&lt;/a&gt;, a lookup table organized by C++ concept, and Google&amp;#8217;s &lt;a href="https://google.github.io/comprehensive-rust/"&gt;Comprehensive Rust&lt;/a&gt;, a multi-day&amp;nbsp;course.&lt;/p&gt;
&lt;p&gt;This series differs from both in three&amp;nbsp;ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It is ordered as a learning&amp;nbsp;path.&lt;/li&gt;
&lt;li&gt;Every snippet is compile-checked on a named&amp;nbsp;toolchain.&lt;/li&gt;
&lt;li&gt;It ends with how to migrate a real code&amp;nbsp;base.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="the-one-big-shift-the-defaults-flip"&gt;The one big shift: the defaults&amp;nbsp;flip&lt;/h2&gt;
&lt;p&gt;Rust and C++ share more than either community likes to&amp;nbsp;admit:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;zero-cost&amp;nbsp;abstractions&lt;/li&gt;
&lt;li&gt;no garbage&amp;nbsp;collector&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;RAII&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;generics compiled by monomorphization (one copy of the code per concrete type, as with&amp;nbsp;templates)&lt;/li&gt;
&lt;li&gt;the same memory model for&amp;nbsp;atomics&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The real difference is not what you &lt;em&gt;can&lt;/em&gt; do. It is what happens when you say&amp;nbsp;nothing.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;When you write nothing&amp;#8230;&lt;/th&gt;
&lt;th&gt;C++&lt;/th&gt;
&lt;th&gt;Rust&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Mutability&lt;/td&gt;
&lt;td&gt;mutable&lt;/td&gt;
&lt;td&gt;immutable&amp;nbsp;(&lt;code&gt;mut&lt;/code&gt; opts in)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Visibility&lt;/td&gt;
&lt;td&gt;&lt;code&gt;struct&lt;/code&gt; public, &lt;code&gt;class&lt;/code&gt; private&lt;/td&gt;
&lt;td&gt;private to the module&amp;nbsp;(&lt;code&gt;pub&lt;/code&gt; opts in)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Numeric conversions&lt;/td&gt;
&lt;td&gt;implicit, narrowing included&lt;/td&gt;
&lt;td&gt;none&amp;nbsp;(&lt;code&gt;as&lt;/code&gt;, &lt;code&gt;From&lt;/code&gt;, &lt;code&gt;TryFrom&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Assigning a non-trivial type&lt;/td&gt;
&lt;td&gt;copies&lt;/td&gt;
&lt;td&gt;moves&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reading an uninitialized local&lt;/td&gt;
&lt;td&gt;undefined behavior&lt;/td&gt;
&lt;td&gt;compile error&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pointers&lt;/td&gt;
&lt;td&gt;can be null, and the type does not say so&lt;/td&gt;
&lt;td&gt;references are never&amp;nbsp;null; &lt;code&gt;Option&amp;lt;&amp;amp;T&amp;gt;&lt;/code&gt; opts in&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Signed integer overflow&lt;/td&gt;
&lt;td&gt;undefined behavior&lt;/td&gt;
&lt;td&gt;panics in debug builds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Out-of-bounds index&lt;/td&gt;
&lt;td&gt;undefined behavior&lt;/td&gt;
&lt;td&gt;panics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;switch&lt;/code&gt; / &lt;code&gt;match&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;falls through, may be incomplete&lt;/td&gt;
&lt;td&gt;no fallthrough, must be exhaustive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dangerous operations&lt;/td&gt;
&lt;td&gt;allowed anywhere&lt;/td&gt;
&lt;td&gt;only&amp;nbsp;inside &lt;code&gt;unsafe&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;C++ hands you a workshop with every power tool plugged in, plus a thick safety manual. Rust hands you the same workshop with the tools locked in a cabinet, and each key you take out goes on a sign-out sheet. You can still do dangerous things in Rust. You just have to say so in writing, in a place a reviewer&amp;nbsp;can &lt;code&gt;grep&lt;/code&gt; for.&lt;/p&gt;
&lt;p&gt;C++26, technically complete since March 2026, softens two rows of the C++&amp;nbsp;column:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Reading an uninitialized local becomes &lt;strong&gt;erroneous behavior&lt;/strong&gt; (a defined but wrong result that tools may diagnose) instead of undefined&amp;nbsp;behavior.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;hardened standard library&lt;/strong&gt; can trap on an&amp;nbsp;out-of-bounds &lt;code&gt;operator[]&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Compiler support is still arriving. Both changes turn silent corruption into defined behavior that implementations are encouraged to diagnose or trap, and neither one is a compile error. The rest of the table&amp;nbsp;stands.&lt;/p&gt;
&lt;p&gt;Almost every section below is one row of this&amp;nbsp;table.&lt;/p&gt;
&lt;h2 id="toolchain-and-project-layout"&gt;Toolchain and project&amp;nbsp;layout&lt;/h2&gt;
&lt;p&gt;Cargo is the build system, package manager, test runner, documentation generator, and lint driver in one tool. The &amp;#8220;which build system, which package manager&amp;#8221; decision that starts every C++ project does not&amp;nbsp;exist.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;cargo&lt;span class="w"&gt; &lt;/span&gt;new&lt;span class="w"&gt; &lt;/span&gt;inventory&lt;span class="w"&gt;       &lt;/span&gt;&lt;span class="c1"&gt;# Cargo.toml + src/main.rs&lt;/span&gt;
cargo&lt;span class="w"&gt; &lt;/span&gt;build&lt;span class="w"&gt; &lt;/span&gt;--release&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="c1"&gt;# optimized build in target/release&lt;/span&gt;
cargo&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="c1"&gt;# runs every #[test] function, no framework needed&lt;/span&gt;
cargo&lt;span class="w"&gt; &lt;/span&gt;clippy&lt;span class="w"&gt;              &lt;/span&gt;&lt;span class="c1"&gt;# lints, the clang-tidy of Rust&lt;/span&gt;
cargo&lt;span class="w"&gt; &lt;/span&gt;fmt&lt;span class="w"&gt;                 &lt;/span&gt;&lt;span class="c1"&gt;# formatting, the clang-format of Rust&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;C++&lt;/th&gt;
&lt;th&gt;Rust&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Translation unit&amp;nbsp;(&lt;code&gt;.cpp&lt;/code&gt; + headers)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Crate&lt;/strong&gt;: the whole library or binary is one compilation unit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;#include "parser.h"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mod parser;&lt;/code&gt; declares a&amp;nbsp;module, &lt;code&gt;use parser::Token;&lt;/code&gt; imports a name&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;namespace net { ... }&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mod net { ... }&lt;/code&gt;, or a&amp;nbsp;file &lt;code&gt;net.rs&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CMake, Meson, Bazel&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Cargo.toml&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;vcpkg, Conan&lt;/td&gt;
&lt;td&gt;crates.io,&amp;nbsp;through &lt;code&gt;Cargo.toml&lt;/code&gt; &lt;code&gt;[dependencies]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-O3&lt;/code&gt; / &lt;code&gt;-O0 -g&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;--release&lt;/code&gt; / the&amp;nbsp;default &lt;code&gt;dev&lt;/code&gt; profile&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GoogleTest, Catch2&lt;/td&gt;
&lt;td&gt;built-in &lt;code&gt;#[test]&lt;/code&gt; + &lt;code&gt;cargo test&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;clang-tidy, clang-format&lt;/td&gt;
&lt;td&gt;&lt;code&gt;cargo clippy&lt;/code&gt;, &lt;code&gt;cargo fmt&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;The gap:&lt;/strong&gt; there are no headers, so there are no include-order bugs, no forward declarations, and no One Definition Rule violations. Items in a module can refer to each other in any&amp;nbsp;order.&lt;/p&gt;
&lt;p&gt;The trade-off is that the crate, not the file, is the unit of compilation, so a big crate behaves like a unity build. Code generation inside one crate already runs in parallel, but parsing and type-checking a crate do not. When builds get slow, split the code into several crates in a &lt;strong&gt;workspace&lt;/strong&gt;: they type-check in parallel and rebuild&amp;nbsp;independently.&lt;/p&gt;
&lt;h2 id="primitive-types-and-conversions"&gt;Primitive types and&amp;nbsp;conversions&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;C++&lt;/th&gt;
&lt;th&gt;Rust&lt;/th&gt;
&lt;th&gt;Note&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;int8_t&lt;/code&gt; &amp;#8230; &lt;code&gt;int64_t&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;i8&lt;/code&gt; &amp;#8230; &lt;code&gt;i64&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;exact match&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;uint8_t&lt;/code&gt; &amp;#8230; &lt;code&gt;uint64_t&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;u8&lt;/code&gt; &amp;#8230; &lt;code&gt;u64&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;exact match&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;int&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;i32&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;on every mainstream platform; the standard only promises at least 16 bits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;long&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;i64&lt;/code&gt; &lt;em&gt;or&lt;/em&gt; &lt;code&gt;i32&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;64-bit on 64-bit Linux and macOS, 32-bit on Windows and 32-bit targets: choose the width you mean&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;size_t&lt;/code&gt;, &lt;code&gt;ptrdiff_t&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;usize&lt;/code&gt;, &lt;code&gt;isize&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;lengths and indices are&amp;nbsp;always &lt;code&gt;usize&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;__int128&lt;/code&gt; (extension)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;i128&lt;/code&gt;, &lt;code&gt;u128&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;standard in Rust&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;float&lt;/code&gt;, &lt;code&gt;double&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;f32&lt;/code&gt;, &lt;code&gt;f64&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;no implicit conversion to or from integers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;char&lt;/code&gt; (a byte)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;u8&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;char32_t&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;char&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;a 4-byte Unicode scalar value, not a byte&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;C++ converts between arithmetic types silently, narrowing included. The compiler may warn, but it will not stop you, unless you use brace initialization, where narrowing is an&amp;nbsp;error.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;cstdint&amp;gt;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;big&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;uint8_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;small&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;big&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// 44, silently&lt;/span&gt;
&lt;span class="kt"&gt;unsigned&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;-1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;          &lt;/span&gt;&lt;span class="c1"&gt;// 4294967295, silently&lt;/span&gt;
&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;3.9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="c1"&gt;// 3, silently&lt;/span&gt;
&lt;span class="kt"&gt;long&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;small&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c1"&gt;// integer promotions do the rest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Rust has no implicit numeric conversions at all, not even widening ones. You pick the conversion, and the name of the conversion tells the reader what can go&amp;nbsp;wrong.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;big&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i32&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// let small: u8 = big;          // error[E0308]: mismatched types&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;small&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;big&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="c1"&gt;// 44: `as` truncates, and now it says so&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;checked&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;try_from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;big&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// Err(TryFromIntError(PosOverflow))&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wide&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i64&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;big&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;       &lt;/span&gt;&lt;span class="c1"&gt;// From exists only when no value can be lost&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;3.9_&lt;/span&gt;&lt;span class="k"&gt;f64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;          &lt;/span&gt;&lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;huge&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1e20_&lt;/span&gt;&lt;span class="k"&gt;f64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="c1"&gt;// 2147483647: float-to-int `as` saturates&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// let total = i + small;        // error[E0308]: mismatched types, then E0277&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;small&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{small} {checked:?} {wide} {i} {huge} {total}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The gap:&lt;/strong&gt; pick the conversion by what can go&amp;nbsp;wrong:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;From&lt;/code&gt; when the conversion is&amp;nbsp;lossless.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;TryFrom&lt;/code&gt; when it can&amp;nbsp;fail.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;as&lt;/code&gt; only when you mean&amp;nbsp;&amp;#8220;truncate&amp;#8221;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;as&lt;/code&gt; is the one remaining sharp edge, so Clippy has&amp;nbsp;opt-in &lt;code&gt;pedantic&lt;/code&gt; lints&amp;nbsp;(&lt;code&gt;cast_possible_truncation&lt;/code&gt; and friends) to flag&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;One more difference hides in the last cast: a float-to-int conversion that is out of range is undefined behavior in C++, while&amp;nbsp;Rust&amp;#8217;s &lt;code&gt;as&lt;/code&gt; saturates to the nearest bound and&amp;nbsp;turns &lt;code&gt;NaN&lt;/code&gt; into &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="variables-immutable-inferred-always-initialized"&gt;Variables: immutable, inferred, always&amp;nbsp;initialized&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;C++&lt;/th&gt;
&lt;th&gt;Rust&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;const int x = 5;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;let x = 5;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;int x = 5;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;let mut x = 5;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;auto x = f();&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;let x = f();&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;constexpr std::size_t N = 64;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;const N: usize = 64;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;int x;&lt;/code&gt; (no initializer)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;let x: i32;&lt;/code&gt; is allowed only if every path assigns it before use&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;global &lt;code&gt;static int counter;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;static COUNTER: AtomicUsize&lt;/code&gt; (globals must be thread-safe; Part 3)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Reading an uninitialized local is a classic C++ bug. This compiles, and it reads garbage&amp;nbsp;when &lt;code&gt;verbose&lt;/code&gt; is&amp;nbsp;false:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;log_level&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;verbose&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="c1"&gt;// indeterminate value&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;verbose&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// undefined behavior when verbose == false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Rust tracks &lt;strong&gt;definite initialization&lt;/strong&gt; on every&amp;nbsp;path:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;// does not compile: E0381&lt;/span&gt;
&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;log_level&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;verbose&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i32&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;verbose&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// error[E0381]: used binding `level` is possibly-uninitialized&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The idiomatic fix is to stop declaring first and assigning later. In&amp;nbsp;Rust, &lt;code&gt;if&lt;/code&gt; is an expression, so the value is computed where the variable is&amp;nbsp;born:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;log_level&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;verbose&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i32&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;verbose&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Two more differences are worth knowing on day&amp;nbsp;one.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Shadowing.&lt;/strong&gt; Rust lets you declare a new variable with the same name in the same scope. That sounds like a bug factory to C++ ears, but it is the idiomatic way to give a transformed value its natural name, instead of&amp;nbsp;inventing &lt;code&gt;port_str&lt;/code&gt;, &lt;code&gt;port_trimmed&lt;/code&gt;,&amp;nbsp;and &lt;code&gt;port_num&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;" 8080&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="c1"&gt;// &amp;amp;str&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;u16&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// u16&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{port}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Mutability is deep.&lt;/strong&gt; In&amp;nbsp;C++, &lt;code&gt;const&lt;/code&gt; is part of the type, and it is shallow:&amp;nbsp;a &lt;code&gt;const&lt;/code&gt; object can hold a pointer to mutable data. That gives you the four-way puzzle&amp;nbsp;of &lt;code&gt;const T*&lt;/code&gt;, &lt;code&gt;T* const&lt;/code&gt;, and&amp;nbsp;friends.&lt;/p&gt;
&lt;p&gt;In Rust, mutability belongs to the binding and is &lt;strong&gt;inherited&lt;/strong&gt; by everything the binding owns.&amp;nbsp;A &lt;code&gt;let v = vec![1, 2]&lt;/code&gt; cannot be pushed to, its elements cannot be changed, and there is&amp;nbsp;no &lt;code&gt;const_cast&lt;/code&gt; to get around it. (Part 2 covers the controlled escape hatch, interior&amp;nbsp;mutability.)&lt;/p&gt;
&lt;h2 id="integer-overflow-from-undefined-to-defined"&gt;Integer overflow: from undefined to&amp;nbsp;defined&lt;/h2&gt;
&lt;p&gt;In C++, signed overflow is undefined behavior, so the optimizer is allowed to assume it never happens. Here is a real overflow check that clang 21&amp;nbsp;at &lt;code&gt;-O2&lt;/code&gt; compiles&amp;nbsp;to &lt;code&gt;return false&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;will_overflow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// "cannot happen", so the compiler deletes the check&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Unsigned arithmetic is the opposite: it is defined to wrap, and a lot of C++ code (hashes, checksums, ring-buffer indices) depends on&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;Rust treats &lt;strong&gt;every&lt;/strong&gt; overflow, signed or unsigned, as a bug, but never as undefined behavior. The &lt;a href="https://doc.rust-lang.org/reference/behavior-not-considered-unsafe.html#integer-overflow"&gt;Rust Reference&lt;/a&gt; splits the rule by&amp;nbsp;build:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When debug assertions are on, &amp;#8220;implementations must insert dynamic checks that panic on&amp;nbsp;overflow&amp;#8221;.&lt;/li&gt;
&lt;li&gt;Other builds &amp;#8220;may result in panics or silently wrapped values on overflow, at the implementation&amp;#8217;s discretion&amp;#8221;, always with two&amp;#8217;s complement&amp;nbsp;results.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cargo&amp;#8217;s defaults&amp;nbsp;are &lt;code&gt;overflow-checks = true&lt;/code&gt; in&amp;nbsp;the &lt;code&gt;dev&lt;/code&gt; profile&amp;nbsp;and &lt;code&gt;false&lt;/code&gt; in &lt;code&gt;release&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When you &lt;em&gt;want&lt;/em&gt; a specific overflow behavior, you name&amp;nbsp;it:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;hint&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;black_box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;MAX&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;black_box&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// hide the value from the compiler's constant checks&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;checked_add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="c1"&gt;// None&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;wrapping_add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="c1"&gt;// -2147483648&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;saturating_add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// 2147483647&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;overflowing_add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// (-2147483648, true)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// panics: debug build, "attempt to add with overflow"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{c}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The gap:&lt;/strong&gt; port a C++ hash function to Rust with&amp;nbsp;plain &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;*&lt;/code&gt;, and your debug build panics on the first input. That is not a Rust bug. That is Rust asking you to say &amp;#8220;yes, I want wrapping here&amp;#8221;.&amp;nbsp;Use &lt;code&gt;wrapping_*&lt;/code&gt; methods or&amp;nbsp;the &lt;code&gt;std::num::Wrapping&amp;lt;T&amp;gt;&lt;/code&gt; type.&lt;/p&gt;
&lt;p&gt;The opposite trap also exists: release builds wrap silently by default. If overflow would be a real bug in production,&amp;nbsp;set &lt;code&gt;overflow-checks = true&lt;/code&gt; in &lt;code&gt;[profile.release]&lt;/code&gt; and pay the small&amp;nbsp;cost.&lt;/p&gt;
&lt;h2 id="everything-is-an-expression"&gt;Everything is an&amp;nbsp;expression&lt;/h2&gt;
&lt;p&gt;In&amp;nbsp;Rust, &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;match&lt;/code&gt;, and plain blocks all produce values. The ternary operator does not exist,&amp;nbsp;because &lt;code&gt;if&lt;/code&gt; already does its job, and the last expression of a function body is its return&amp;nbsp;value.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;switch&lt;/code&gt; statement&amp;nbsp;becomes &lt;code&gt;match&lt;/code&gt;,&amp;nbsp;and &lt;code&gt;match&lt;/code&gt; must be &lt;strong&gt;exhaustive&lt;/strong&gt;. Here is the C++ version. It compiles, with&amp;nbsp;a &lt;code&gt;-Wswitch&lt;/code&gt; warning (on by default in clang, part&amp;nbsp;of &lt;code&gt;-Wall&lt;/code&gt; in &lt;span class="caps"&gt;GCC&lt;/span&gt;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;enum&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Shape&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Triangle&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Shape&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;Shape&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"circle"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;Shape&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"square"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// Triangle forgotten: a warning at best&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"unknown"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The same mistake in Rust is a hard error, not a&amp;nbsp;warning:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;// does not compile: E0004&lt;/span&gt;
&lt;span class="k"&gt;enum&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Shape&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Triangle&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kp"&gt;&amp;amp;&lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="nb"&gt;static&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Circle&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"circle"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Square&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"square"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// error[E0004]: non-exhaustive patterns: `Shape::Triangle` not covered&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;(&lt;code&gt;&amp;amp;'static str&lt;/code&gt; means &amp;#8220;a string slice that lives for the whole program&amp;#8221;, which is what a string literal&amp;nbsp;is.)&lt;/p&gt;
&lt;p&gt;&lt;code&gt;match&lt;/code&gt; also has no fallthrough, and its patterns do much more than compare constants: alternatives, ranges, guards, and&amp;nbsp;bindings.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;classify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;u16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kp"&gt;&amp;amp;&lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="nb"&gt;static&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;204&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"ok"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="o"&gt;..=&lt;/span&gt;&lt;span class="mi"&gt;399&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"redirect"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"server error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"other"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{} {} {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;classify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;204&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;classify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;302&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;classify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Loops translate almost one to one, with two&amp;nbsp;upgrades: &lt;code&gt;loop&lt;/code&gt; can return a value&amp;nbsp;through &lt;code&gt;break&lt;/code&gt;, and labeled breaks replace&amp;nbsp;the &lt;code&gt;goto&lt;/code&gt; you use to escape nested&amp;nbsp;loops.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;C++&lt;/th&gt;
&lt;th&gt;Rust&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;for (const auto&amp;amp; x : v)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;for x in &amp;amp;v&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;for (auto&amp;amp; x : v)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;for x in &amp;amp;mut v&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;for (int i = 0; i &amp;lt; n; ++i)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;for i in 0..n&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;index + element&lt;/td&gt;
&lt;td&gt;&lt;code&gt;for (i, x) in v.iter().enumerate()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;while (cond)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;while cond&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;for (;;)&lt;/code&gt; / &lt;code&gt;while (true)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;loop&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;goto found;&lt;/code&gt; out of nested loops&lt;/td&gt;
&lt;td&gt;&lt;code&gt;break 'label&lt;/code&gt;; with a value only&amp;nbsp;from &lt;code&gt;loop&lt;/code&gt; or a labeled block&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]];&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;found&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="na"&gt;search&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;                    &lt;/span&gt;&lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;'search&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nb"&gt;None&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{found:?}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// Some((1, 1))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="functions-no-overloading-no-default-arguments"&gt;Functions: no overloading, no default&amp;nbsp;arguments&lt;/h2&gt;
&lt;p&gt;Rust has neither function overloading nor default arguments. Both are deliberate. Overload resolution combined with implicit conversions is one of the most complicated parts of the C++ standard, and in Rust a function name always means exactly one&amp;nbsp;function.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;string&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;utility&amp;gt;&lt;/span&gt;

&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Conn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;timeout_ms&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;tls&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="n"&gt;Conn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;443&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;timeout_ms&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;tls&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;move&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;timeout_ms&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;tls&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// overload by type&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The Rust replacements, from simplest to most&amp;nbsp;flexible:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Different names&lt;/strong&gt; for different&amp;nbsp;things: &lt;code&gt;log_int&lt;/code&gt;, &lt;code&gt;log_str&lt;/code&gt;. Or one generic function over a trait&amp;nbsp;(&lt;code&gt;fn log(value: impl Display)&lt;/code&gt;), which Part 2&amp;nbsp;covers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;An options struct&amp;nbsp;with &lt;code&gt;Default&lt;/code&gt;&lt;/strong&gt;, plus &lt;strong&gt;struct update syntax&lt;/strong&gt;&amp;nbsp;(&lt;code&gt;..Default::default()&lt;/code&gt;) to override only some&amp;nbsp;fields.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A builder&lt;/strong&gt; when construction has rules or many optional&amp;nbsp;parts.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="cp"&gt;#[derive(Debug)]&lt;/span&gt;
&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;ConnectOptions&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;u16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;timeout_ms&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;tls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;impl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Default&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ConnectOptions&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;default&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Self&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="bp"&gt;Self&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;443&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;timeout_ms&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;tls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;true&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kp"&gt;&amp;amp;&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;ConnectOptions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;format!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{host}:{} tls={} timeout={}ms"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tls&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timeout_ms&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ConnectOptions&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"localhost"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ConnectOptions&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;tls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="nb"&gt;Default&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The options struct is more typing&amp;nbsp;than &lt;code&gt;= 443&lt;/code&gt;, but it ages better: the call site names every value it changes, and adding a new option does not break any&amp;nbsp;caller.&lt;/p&gt;
&lt;p&gt;To return several values, return a&amp;nbsp;tuple, &lt;code&gt;fn min_max(v: &amp;amp;[i32]) -&amp;gt; (i32, i32)&lt;/code&gt;, and destructure it&amp;nbsp;with &lt;code&gt;let (lo, hi) = min_max(&amp;amp;v);&lt;/code&gt;, like C++17 structured&amp;nbsp;bindings.&lt;/p&gt;
&lt;h2 id="strings-two-types-and-a-byte-count"&gt;Strings: two types and a byte&amp;nbsp;count&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;C++&lt;/th&gt;
&lt;th&gt;Rust&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::string&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;String&lt;/code&gt;: owned, growable, always valid &lt;span class="caps"&gt;UTF&lt;/span&gt;-8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::string_view&lt;/code&gt;, &lt;code&gt;const std::string&amp;amp;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;str&lt;/code&gt;: a borrowed view into &lt;span class="caps"&gt;UTF&lt;/span&gt;-8 text&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;const char*&lt;/code&gt; to or from C&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;CStr&lt;/code&gt; / &lt;code&gt;CString&lt;/code&gt;, only at &lt;span class="caps"&gt;FFI&lt;/span&gt; boundaries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::to_string(42)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;42.to_string()&lt;/code&gt;, &lt;code&gt;format!("{}", 42)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::stoi(s)&lt;/code&gt; (throws)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;s.parse::&amp;lt;i32&amp;gt;()&lt;/code&gt; (returns&amp;nbsp;a &lt;code&gt;Result&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;s.size()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;s.len()&lt;/code&gt;, in &lt;strong&gt;bytes&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;s[i]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;no direct equivalent; see below&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;s.substr(pos, n)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;s[pos..pos + n]&lt;/code&gt;, a byte range that must fall on character boundaries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;a + b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a + &amp;amp;b&lt;/code&gt; (consumes &lt;code&gt;a&lt;/code&gt;),&amp;nbsp;or &lt;code&gt;format!("{a}{b}")&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Function parameters that only read text should&amp;nbsp;take &lt;code&gt;&amp;amp;str&lt;/code&gt;, the same advice as&amp;nbsp;&amp;#8220;take &lt;code&gt;std::string_view&lt;/code&gt;&amp;#8221; in modern C++.&amp;nbsp;A &lt;code&gt;&amp;amp;String&lt;/code&gt; converts&amp;nbsp;to &lt;code&gt;&amp;amp;str&lt;/code&gt; automatically.&lt;/p&gt;
&lt;p&gt;A&amp;nbsp;Rust &lt;code&gt;String&lt;/code&gt; is guaranteed to hold valid &lt;span class="caps"&gt;UTF&lt;/span&gt;-8, where a character can take one to four bytes. So &amp;#8220;the i-th character&amp;#8221; cannot be both O(1) and correct, and Rust refuses to pretend&amp;nbsp;otherwise:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;// does not compile: E0277&lt;/span&gt;
&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"naïve"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// error[E0277]: the type `str` cannot be indexed by `{integer}`&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You say what you mean instead: bytes, characters, or a byte&amp;nbsp;range.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"naïve"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{} bytes, {} chars"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chars&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// 6 bytes, 5 chars&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chars&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;nth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// Some('ï')&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="c1"&gt;// "na"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// &amp;amp;s[0..3] would panic: byte 3 is in the middle of 'ï'&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i32&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"42"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;unwrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The second difference is lifetime.&amp;nbsp;A &lt;code&gt;std::string_view&lt;/code&gt; that outlives its string is a dangling pointer, and the compiler will not tell&amp;nbsp;you:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;print&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;string&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;string_view&amp;gt;&lt;/span&gt;

&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string_view&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;first_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string_view&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sc"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;first_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello world"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// the temporary dies at the ';'&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;                           &lt;/span&gt;&lt;span class="c1"&gt;// dangling view: undefined behavior&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The same code in Rust does not compile, because the borrow checker knows&amp;nbsp;that &lt;code&gt;w&lt;/code&gt; points into a&amp;nbsp;temporary:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;// does not compile: E0716&lt;/span&gt;
&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;first_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kp"&gt;&amp;amp;&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kp"&gt;&amp;amp;&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sc"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;unwrap_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;first_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hello world"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// temporary dropped here...&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{w}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;                                  &lt;/span&gt;&lt;span class="c1"&gt;// ...while `w` still borrows it&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This is your first look at the borrow checker. Part 2 is mostly about&amp;nbsp;it.&lt;/p&gt;
&lt;h2 id="containers"&gt;Containers&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;C++&lt;/th&gt;
&lt;th&gt;Rust&lt;/th&gt;
&lt;th&gt;Note&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;T[N]&lt;/code&gt;, &lt;code&gt;std::array&amp;lt;T, N&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[T; N]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;a value type,&amp;nbsp;like &lt;code&gt;std::array&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::vector&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Vec&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::span&amp;lt;T&amp;gt;&lt;/code&gt;, pointer + length&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;[T]&lt;/code&gt;, &lt;code&gt;&amp;amp;mut [T]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;a &lt;strong&gt;slice&lt;/strong&gt; always carries its length&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::deque&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;VecDeque&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;a ring buffer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::list&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;LinkedList&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;rarely the right choice, in either language&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::map&amp;lt;K, V&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;BTreeMap&amp;lt;K, V&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;ordered; a B-tree,&amp;nbsp;where &lt;code&gt;std::map&lt;/code&gt; is usually a red-black tree&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::unordered_map&amp;lt;K, V&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;HashMap&amp;lt;K, V&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;SipHash 1-3 by default: resists HashDoS, slower for small keys&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::set&lt;/code&gt;, &lt;code&gt;std::unordered_set&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;BTreeSet&lt;/code&gt;, &lt;code&gt;HashSet&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::priority_queue&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;BinaryHeap&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;both are max-heaps by default&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;v.push_back(x)&lt;/code&gt;, &lt;code&gt;v.emplace_back(args)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;v.push(x)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;no &lt;code&gt;emplace&lt;/code&gt;: see below&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;v[i]&lt;/code&gt; / &lt;code&gt;v.at(i)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;v[i]&lt;/code&gt; panics if out of range&amp;nbsp;/ &lt;code&gt;v.get(i)&lt;/code&gt; returns &lt;code&gt;Option&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;get_unchecked&lt;/code&gt; is&amp;nbsp;the &lt;code&gt;unsafe&lt;/code&gt; opt-out&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The most important container lesson is that in Rust, &lt;strong&gt;reading never writes&lt;/strong&gt;. In&amp;nbsp;C++, &lt;code&gt;operator[]&lt;/code&gt; on a map inserts a default value when the key is missing, even when all you wanted was to&amp;nbsp;look:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;map&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;print&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;string&amp;gt;&lt;/span&gt;

&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;&lt;span class="s"&gt;"apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}};&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"pears"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cm"&gt;/* ... */&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// inserts "pears" -&amp;gt; 0 as a side effect&lt;/span&gt;
&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In Rust, indexing a map with a missing key panics,&amp;nbsp;and &lt;code&gt;get&lt;/code&gt; returns&amp;nbsp;an &lt;code&gt;Option&lt;/code&gt;. When you want insert-or-update, the &lt;strong&gt;entry &lt;span class="caps"&gt;API&lt;/span&gt;&lt;/strong&gt; says so out&amp;nbsp;loud:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;collections&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;BTreeMap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;BTreeMap&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;([(&lt;/span&gt;&lt;span class="s"&gt;"apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)]);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// stock["pears"] would panic: indexing never inserts&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;pears&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"pears"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;copied&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;unwrap_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{pears} {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// 0 1&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"pears"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;or_insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{stock:?}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// {"apples": 3, "pears": 5}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The gap:&lt;/strong&gt; out-of-bounds access is a panic, not undefined behavior. The bounds checks are cheap and are often optimized out, especially when you iterate instead of indexing, which is the idiomatic style anyway (Part&amp;nbsp;2).&lt;/p&gt;
&lt;p&gt;There is also&amp;nbsp;no &lt;code&gt;emplace_back&lt;/code&gt;: a Rust move is a plain copy of the bytes that never runs user code, so there is no constructor to forward arguments to. You build the value&amp;nbsp;and &lt;code&gt;push&lt;/code&gt; it.&lt;/p&gt;
&lt;h2 id="structs-and-classes"&gt;Structs and&amp;nbsp;classes&lt;/h2&gt;
&lt;p&gt;A C++ class splits into two Rust pieces:&amp;nbsp;a &lt;code&gt;struct&lt;/code&gt; for the data and&amp;nbsp;an &lt;code&gt;impl&lt;/code&gt; block for the&amp;nbsp;functions.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;cstdint&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;string&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;utility&amp;gt;&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;explicit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;owner_&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;move&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;balance_&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;deposit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;int64_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;balance_&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;int64_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;balance_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;owner_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;int64_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;balance_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// private: visible in this module and its child modules&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;impl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Self&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="bp"&gt;Self&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;deposit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"ada"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to_string&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;deposit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{} has {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// fine: same module&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;C++&lt;/th&gt;
&lt;th&gt;Rust&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;constructor&lt;/td&gt;
&lt;td&gt;an ordinary associated function, by convention&amp;nbsp;called &lt;code&gt;new&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;overloaded constructors&lt;/td&gt;
&lt;td&gt;several named&amp;nbsp;functions: &lt;code&gt;new&lt;/code&gt;, &lt;code&gt;with_capacity&lt;/code&gt;, &lt;code&gt;from_parts&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;this-&amp;gt;field&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;self.field&lt;/code&gt;, always explicit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;const&lt;/code&gt; member function&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;self&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;non-&lt;code&gt;const&lt;/code&gt; member function&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;mut self&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;-qualified member function&lt;/td&gt;
&lt;td&gt;&lt;code&gt;self&lt;/code&gt;: the method takes ownership and consumes the object&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;static&lt;/code&gt; member function&lt;/td&gt;
&lt;td&gt;an associated function with&amp;nbsp;no &lt;code&gt;self&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;private:&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the default, but private to the &lt;strong&gt;module&lt;/strong&gt;, not to the type&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;friend&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;not needed: everything in the same module can see private fields&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;destructor&lt;/td&gt;
&lt;td&gt;&lt;code&gt;impl Drop&lt;/code&gt; (Part 2)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;inheritance&lt;/td&gt;
&lt;td&gt;traits and composition (Part 2)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;The gap:&lt;/strong&gt; a Rust constructor is not special. A struct literal must set every field, so there is no half-built object, no member initialization order puzzle, and no exception escaping from the middle of a&amp;nbsp;constructor.&lt;/p&gt;
&lt;p&gt;The price is that &amp;#8220;constructor&amp;#8221; is now a naming convention, and nothing forces callers to go&amp;nbsp;through &lt;code&gt;new&lt;/code&gt; except privacy. That is why privacy matters: a type with a private field can only be created inside its own module (or a child module), which is how you protect an&amp;nbsp;invariant.&lt;/p&gt;
&lt;h2 id="enums-the-enum-class-c-wanted"&gt;Enums: the enum class C++&amp;nbsp;wanted&lt;/h2&gt;
&lt;p&gt;A&amp;nbsp;C++ &lt;code&gt;enum class&lt;/code&gt; maps to a&amp;nbsp;Rust &lt;code&gt;enum&lt;/code&gt;, with explicit values when you need&amp;nbsp;them:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="cp"&gt;#[derive(Debug, Clone, Copy, PartialEq)]&lt;/span&gt;
&lt;span class="cp"&gt;#[repr(u8)]&lt;/span&gt;
&lt;span class="k"&gt;enum&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Level&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Debug&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Info&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Warn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;lvl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Level&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Info&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{:?} = {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;lvl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;lvl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// Info = 20&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// let bad = 7 as Level;               // error[E0605]: non-primitive cast&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Casting an enum to an integer is fine. The other way does not compile. In&amp;nbsp;C++, &lt;code&gt;static_cast&amp;lt;Level&amp;gt;(7)&lt;/code&gt; gives you a value that matches no enumerator, and&amp;nbsp;every &lt;code&gt;switch&lt;/code&gt; downstream has to deal with it. A Rust enum value is always one of its variants, so integer-to-enum conversions go through&amp;nbsp;a &lt;code&gt;TryFrom&lt;/code&gt; impl you write, and that impl can&amp;nbsp;fail.&lt;/p&gt;
&lt;p&gt;Rust enums can also &lt;strong&gt;carry data&lt;/strong&gt;, one payload per variant. That makes them tagged unions, the&amp;nbsp;job &lt;code&gt;std::variant&lt;/code&gt; does in C++, but built into the language and checked&amp;nbsp;by &lt;code&gt;match&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;enum&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Command&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Quit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Move&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i32&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Command&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;Command&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Quit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"bye"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to_string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;Command&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Move&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="fm"&gt;format!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"move to {x},{y}"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;Command&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Command&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Move&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Data-carrying enums are among the most used features in Rust. Part 2 compares them&amp;nbsp;with &lt;code&gt;std::variant&lt;/code&gt; and &lt;code&gt;std::visit&lt;/code&gt; in&amp;nbsp;detail.&lt;/p&gt;
&lt;h2 id="null-option-instead-of-nullptr"&gt;Null: &lt;code&gt;Option&lt;/code&gt; instead&amp;nbsp;of &lt;code&gt;nullptr&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;A C++ pointer can always be null, and nothing in the type tells the caller whether it might&amp;nbsp;be:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;string&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;vector&amp;gt;&lt;/span&gt;

&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;find_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;nullptr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// the caller must remember to check&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Rust references are never null. &amp;#8220;Maybe a value&amp;#8221; is a separate&amp;nbsp;type, &lt;code&gt;Option&amp;lt;T&amp;gt;&lt;/code&gt;, and you cannot reach the value inside without handling&amp;nbsp;the &lt;code&gt;None&lt;/code&gt; case:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;find_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kp"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Option&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="fm"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"ada"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;into&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}];&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// find_user(&amp;amp;users, 1).name  // error[E0609]: no field `name` on type `Option&amp;lt;&amp;amp;User&amp;gt;`&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;find_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nb"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"found {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nb"&gt;None&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"no such user"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;guest&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;find_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;as_str&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="n"&gt;unwrap_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"guest"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{guest}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;find_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// let-else: unwrap or leave early&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;|u| u.id == id&lt;/code&gt; is a &lt;strong&gt;closure&lt;/strong&gt;, Rust&amp;#8217;s lambda,&amp;nbsp;and &lt;code&gt;.iter().find(...)&lt;/code&gt; is the iterator form&amp;nbsp;of &lt;code&gt;std::find_if&lt;/code&gt;. Part 2 covers&amp;nbsp;both.&lt;/p&gt;
&lt;p&gt;This safety costs &lt;strong&gt;zero bytes&lt;/strong&gt;. The standard library &lt;a href="https://doc.rust-lang.org/std/option/index.html#representation"&gt;guarantees&lt;/a&gt;&amp;nbsp;that &lt;code&gt;Option&amp;lt;&amp;amp;T&amp;gt;&lt;/code&gt;, &lt;code&gt;Option&amp;lt;Box&amp;lt;T&amp;gt;&amp;gt;&lt;/code&gt;, and a few others have the same size as the bare pointer, because the compiler uses the forbidden null value to&amp;nbsp;encode &lt;code&gt;None&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;On this&amp;nbsp;machine, &lt;code&gt;size_of::&amp;lt;Option&amp;lt;&amp;amp;u64&amp;gt;&amp;gt;()&lt;/code&gt; is 8, the same as a pointer,&amp;nbsp;while &lt;code&gt;sizeof(std::optional&amp;lt;int*&amp;gt;)&lt;/code&gt; is 16. The type Rust uses to remove null pointers compiles back down to a null&amp;nbsp;pointer.&lt;/p&gt;
&lt;h2 id="references-a-first-look"&gt;References: a first&amp;nbsp;look&lt;/h2&gt;
&lt;p&gt;C++ references and Rust references look&amp;nbsp;alike. &lt;code&gt;const T&amp;amp;&lt;/code&gt; becomes &lt;code&gt;&amp;amp;T&lt;/code&gt;,&amp;nbsp;and &lt;code&gt;T&amp;amp;&lt;/code&gt; becomes &lt;code&gt;&amp;amp;mut T&lt;/code&gt;. One difference is visible right away, at the call&amp;nbsp;site:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;vector&amp;gt;&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// scale(data, 2.0);  -- nothing here says that `data` is modified&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kp"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nc"&gt;mut&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iter_mut&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kp"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="fm"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;3.0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// the call says it: `data` may change here&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The deeper difference is one rule, which the compiler checks everywhere: at any moment, a value has &lt;strong&gt;either any number&amp;nbsp;of &lt;code&gt;&amp;amp;T&lt;/code&gt; readers or exactly&amp;nbsp;one &lt;code&gt;&amp;amp;mut T&lt;/code&gt; writer&lt;/strong&gt;, never both. Add &amp;#8220;a reference can never outlive what it points to&amp;#8221;, and you have the core of the borrow&amp;nbsp;checker.&lt;/p&gt;
&lt;p&gt;Part 2 shows how this one rule removes iterator invalidation, dangling references, and a whole family of aliasing bugs, and what to do when it gets in your&amp;nbsp;way.&lt;/p&gt;
&lt;h2 id="printing-and-formatting"&gt;Printing and&amp;nbsp;formatting&lt;/h2&gt;
&lt;p&gt;C++20 &lt;code&gt;std::format&lt;/code&gt; and&amp;nbsp;C++23 &lt;code&gt;std::print&lt;/code&gt; use almost the same format-spec mini-language as&amp;nbsp;Rust&amp;#8217;s &lt;code&gt;format!&lt;/code&gt; and &lt;code&gt;println!&lt;/code&gt;, so this section is mostly good news.&amp;nbsp;The &lt;code&gt;!&lt;/code&gt; marks a &lt;strong&gt;macro&lt;/strong&gt;. Macros are how Rust checks the format string against the arguments at compile time, the job that&amp;nbsp;the &lt;code&gt;consteval&lt;/code&gt; format string does&amp;nbsp;for &lt;code&gt;std::format&lt;/code&gt; in&amp;nbsp;C++20.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;C++&lt;/th&gt;
&lt;th&gt;Rust&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::println("{} {}", a, b)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;println!("{} {}", a, b)&lt;/code&gt; or &lt;code&gt;println!("{a} {b}")&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::format("{:&amp;gt;8}", s)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;format!("{:&amp;gt;8}", s)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::cerr &amp;lt;&amp;lt; ...&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;eprintln!(...)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;operator&amp;lt;&amp;lt;&lt;/code&gt; or&amp;nbsp;a &lt;code&gt;std::formatter&lt;/code&gt; specialization&lt;/td&gt;
&lt;td&gt;&lt;code&gt;impl Display&lt;/code&gt; (Part 2)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;a debug dump of a struct&lt;/td&gt;
&lt;td&gt;&lt;code&gt;#[derive(Debug)]&lt;/code&gt; plus &lt;code&gt;{:?}&lt;/code&gt;,&amp;nbsp;or &lt;code&gt;{:#?}&lt;/code&gt; for pretty output&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="cp"&gt;#[derive(Debug)]&lt;/span&gt;
&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Point&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Point&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;3.14159&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"offset"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{label}: {p:?}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;// offset: Point { x: 3.14159, y: -2.0 }&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"[{:&amp;gt;8.2}]"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// [    3.14]&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="fm"&gt;eprintln!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{p:#?}"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// pretty, multi-line, to stderr&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The gap:&lt;/strong&gt; one trap hides in the &amp;#8220;almost&amp;#8221;. In&amp;nbsp;Rust, &lt;code&gt;{:.2}&lt;/code&gt; on a float means &lt;strong&gt;two digits after the decimal point&lt;/strong&gt;. In&amp;nbsp;C++, &lt;code&gt;{:.2}&lt;/code&gt; without a type letter uses the general format, where the precision counts &lt;strong&gt;significant digits&lt;/strong&gt;: &lt;code&gt;std::format("{:.2}", 3.14159)&lt;/code&gt; gives &lt;code&gt;3.1&lt;/code&gt;, and you&amp;nbsp;need &lt;code&gt;{:.2f}&lt;/code&gt; to&amp;nbsp;get &lt;code&gt;3.14&lt;/code&gt;. Port a format string without&amp;nbsp;the &lt;code&gt;f&lt;/code&gt; and your numbers change&amp;nbsp;quietly.&lt;/p&gt;
&lt;h2 id="cheat-sheet"&gt;Cheat&amp;nbsp;sheet&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;C++&lt;/th&gt;
&lt;th&gt;Rust&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;size_t&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;i32&lt;/code&gt;, &lt;code&gt;i64&lt;/code&gt;/&lt;code&gt;i32&lt;/code&gt; (choose), &lt;code&gt;usize&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;implicit conversion&lt;/td&gt;
&lt;td&gt;&lt;code&gt;From&lt;/code&gt; (lossless), &lt;code&gt;TryFrom&lt;/code&gt; (fallible), &lt;code&gt;as&lt;/code&gt; (truncating)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;const T x = v;&lt;/code&gt; / &lt;code&gt;T x = v;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;let x = v;&lt;/code&gt; / &lt;code&gt;let mut x = v;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;constexpr&lt;/code&gt; value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;const&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;auto&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;type inference&amp;nbsp;with &lt;code&gt;let&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;uninitialized variable&lt;/td&gt;
&lt;td&gt;compile error until every path assigns it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;signed overflow (undefined behavior)&lt;/td&gt;
&lt;td&gt;panic in debug, wrap in&amp;nbsp;release; &lt;code&gt;checked_&lt;/code&gt;, &lt;code&gt;wrapping_&lt;/code&gt;, &lt;code&gt;saturating_&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;unsigned wraparound&lt;/td&gt;
&lt;td&gt;&lt;code&gt;wrapping_*&lt;/code&gt; or &lt;code&gt;Wrapping&amp;lt;T&amp;gt;&lt;/code&gt; (plain &lt;code&gt;+&lt;/code&gt; panics in debug)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;c ? a : b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;if c { a } else { b }&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;switch&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;match&lt;/code&gt;: exhaustive, no fallthrough, patterns and guards&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;range-for&lt;/td&gt;
&lt;td&gt;&lt;code&gt;for x in &amp;amp;v&lt;/code&gt; / &lt;code&gt;for x in &amp;amp;mut v&lt;/code&gt; / &lt;code&gt;for x in v&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;goto&lt;/code&gt; out of loops&lt;/td&gt;
&lt;td&gt;labeled &lt;code&gt;break 'outer&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;overloads&lt;/td&gt;
&lt;td&gt;distinct names, or generics with traits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;default arguments&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Default&lt;/code&gt; + &lt;code&gt;..Default::default()&lt;/code&gt;, or a builder&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::pair&lt;/code&gt;, structured bindings&lt;/td&gt;
&lt;td&gt;tuples, &lt;code&gt;let (a, b) = ...&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::string&lt;/code&gt; / &lt;code&gt;std::string_view&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;String&lt;/code&gt; / &lt;code&gt;&amp;amp;str&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;const char*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;CStr&lt;/code&gt;, &lt;code&gt;CString&lt;/code&gt; (&lt;span class="caps"&gt;FFI&lt;/span&gt; only)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::stoi&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;s.parse::&amp;lt;i32&amp;gt;()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::array&lt;/code&gt; / &lt;code&gt;std::vector&lt;/code&gt; / &lt;code&gt;std::span&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[T; N]&lt;/code&gt; / &lt;code&gt;Vec&amp;lt;T&amp;gt;&lt;/code&gt; / &lt;code&gt;&amp;amp;[T]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::map&lt;/code&gt; / &lt;code&gt;std::unordered_map&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;BTreeMap&lt;/code&gt; / &lt;code&gt;HashMap&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;m[k]&lt;/code&gt; (inserts)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;m.get(&amp;amp;k)&lt;/code&gt; (reads), &lt;code&gt;m.entry(k).or_insert(v)&lt;/code&gt; (writes)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;v.at(i)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;v[i]&lt;/code&gt; (panics)&amp;nbsp;or &lt;code&gt;v.get(i)&lt;/code&gt; (&lt;code&gt;Option&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;class&lt;/code&gt; with constructor&lt;/td&gt;
&lt;td&gt;&lt;code&gt;struct&lt;/code&gt; + &lt;code&gt;impl&lt;/code&gt; + &lt;code&gt;fn new&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;const&lt;/code&gt; /&amp;nbsp;non-&lt;code&gt;const&lt;/code&gt; method&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;self&lt;/code&gt; / &lt;code&gt;&amp;amp;mut self&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;private:&lt;/code&gt; + &lt;code&gt;friend&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;module&amp;nbsp;privacy, &lt;code&gt;pub&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;enum class&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;enum&lt;/code&gt; (&lt;code&gt;#[repr(u8)]&lt;/code&gt; for a fixed layout)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::variant&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;enum&lt;/code&gt; with data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;T*&lt;/code&gt; that can be&amp;nbsp;null, &lt;code&gt;std::optional&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Option&amp;lt;&amp;amp;T&amp;gt;&lt;/code&gt;, &lt;code&gt;Option&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;const T&amp;amp;&lt;/code&gt; / &lt;code&gt;T&amp;amp;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;T&lt;/code&gt; / &lt;code&gt;&amp;amp;mut T&lt;/code&gt; (explicit at the call site)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;std::println&lt;/code&gt;, &lt;code&gt;std::format&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;println!&lt;/code&gt;, &lt;code&gt;format!&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;operator&amp;lt;&amp;lt;&lt;/code&gt; for printing&lt;/td&gt;
&lt;td&gt;&lt;code&gt;impl Display&lt;/code&gt;, &lt;code&gt;#[derive(Debug)]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="traps-for-c-developers"&gt;Traps for C++&amp;nbsp;developers&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Unsigned arithmetic panics in debug builds.&lt;/strong&gt; Hashes and checksums&amp;nbsp;need &lt;code&gt;wrapping_*&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Release builds wrap on overflow by default.&lt;/strong&gt; Turn&amp;nbsp;on &lt;code&gt;overflow-checks&lt;/code&gt; in release if overflow would be a real&amp;nbsp;bug.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;as&lt;/code&gt; truncates silently.&lt;/strong&gt;&amp;nbsp;Prefer &lt;code&gt;From&lt;/code&gt; and &lt;code&gt;TryFrom&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;s.len()&lt;/code&gt; counts bytes&lt;/strong&gt;, and string slices panic if a range cuts a character in&amp;nbsp;half.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Map indexing never inserts.&lt;/strong&gt; It panics on a missing key.&amp;nbsp;Use &lt;code&gt;get&lt;/code&gt; to read&amp;nbsp;and &lt;code&gt;entry&lt;/code&gt; to&amp;nbsp;write.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;{:.2}&lt;/code&gt; means decimals in Rust&lt;/strong&gt; and significant digits in C++&amp;nbsp;(without &lt;code&gt;f&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Privacy is per module.&lt;/strong&gt; Code in the same module, and in its child modules, can see private&amp;nbsp;fields.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Immutability is deep.&lt;/strong&gt; There is&amp;nbsp;no &lt;code&gt;const_cast&lt;/code&gt;; Part 2 shows the legal escape&amp;nbsp;hatch.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="what-comes-next"&gt;What comes&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;The syntax swap takes an afternoon. The defaults take longer, because each one removes something your C++ habits relied on: the implicit conversion, the uninitialized variable, the overflow that &amp;#8220;never happens&amp;#8221;, the null that is &amp;#8220;always&amp;nbsp;checked&amp;#8221;.&lt;/p&gt;
&lt;p&gt;In your first weeks, read every Rust compile error as a C++ assumption that someone finally wrote down. Most of the time the assumption was fine. Sometimes it was a bug that had been waiting in your C++ code all along, and in Rust it stops the build instead of reaching&amp;nbsp;production.&lt;/p&gt;
&lt;p&gt;Part 2 takes on the biggest default flip of all: &lt;strong&gt;ownership&lt;/strong&gt;. It covers moves without moved-from objects, &lt;span class="caps"&gt;RAII&lt;/span&gt;&amp;nbsp;with &lt;code&gt;Drop&lt;/code&gt;, the borrow checker in depth, smart pointers, errors without exceptions, and how templates and virtual functions become generics and&amp;nbsp;traits.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/book/"&gt;The Rust Programming Language&lt;/a&gt;, the official&amp;nbsp;book&lt;/li&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/reference/behavior-not-considered-unsafe.html#integer-overflow"&gt;The Rust Reference: Integer overflow&lt;/a&gt;, overflow rules quoted&amp;nbsp;above&lt;/li&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/cargo/reference/profiles.html"&gt;Cargo Book: Profiles&lt;/a&gt;,&amp;nbsp;default &lt;code&gt;overflow-checks&lt;/code&gt; per&amp;nbsp;profile&lt;/li&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/std/option/index.html#representation"&gt;std::option: Representation&lt;/a&gt;, the null pointer optimization&amp;nbsp;guarantee&lt;/li&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/std/collections/struct.HashMap.html"&gt;std::collections::HashMap&lt;/a&gt;, default hasher (SipHash 1-3) and HashDoS&amp;nbsp;resistance&lt;/li&gt;
&lt;li&gt;&lt;a href="https://doc.rust-lang.org/std/fmt/"&gt;std::fmt&lt;/a&gt;, Rust format&amp;nbsp;syntax&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.cppreference.com/w/cpp/language/operator_arithmetic.html#Overflows"&gt;cppreference: Arithmetic operators, overflows&lt;/a&gt;, signed overflow is undefined&amp;nbsp;behavior&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.cppreference.com/w/cpp/container/map/operator_at.html"&gt;cppreference: std::map::operator[]&lt;/a&gt;, inserts when the key is&amp;nbsp;missing&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.cppreference.com/w/cpp/utility/format/spec.html"&gt;cppreference: Standard format specification&lt;/a&gt;, precision with and without a type&amp;nbsp;letter&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cel.cs.brown.edu/crp/"&gt;C++ to Rust Phrasebook&lt;/a&gt;, Brown University, a good companion to this&amp;nbsp;series&lt;/li&gt;
&lt;li&gt;&lt;a href="https://google.github.io/comprehensive-rust/"&gt;Comprehensive Rust&lt;/a&gt;, Google&amp;#8217;s free Rust&amp;nbsp;course&lt;/li&gt;
&lt;li&gt;&lt;a href="https://rust-lang.github.io/rust-clippy/master/index.html"&gt;Clippy lints&lt;/a&gt;,&amp;nbsp;including &lt;code&gt;cast_possible_truncation&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://herbsutter.com/2026/03/29/c26-is-done-trip-report-march-2026-iso-c-standards-meeting-london-croydon-uk/"&gt;Herb Sutter: C++26 is done! Trip report, March 2026&lt;/a&gt;, C++26 status, erroneous behavior, and library&amp;nbsp;hardening&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.cppreference.com/w/cpp/compiler_support/26.html"&gt;cppreference: C++26 compiler support&lt;/a&gt;, which compilers ship which C++26&amp;nbsp;features&lt;/li&gt;
&lt;/ol&gt;</content><category term="Engineering"/><category term="rust"/><category term="cpp"/><category term="programming-languages"/><category term="tutorial"/><category term="memory-safety"/></entry><entry><title>MIT’s AI Report: Protect the Struggle, Not the Grade</title><link href="https://alexsavio.github.io/mit-ai-report-protect-the-struggle-not-the-grade.html" rel="alternate"/><published>2026-10-05T00:00:00+02:00</published><updated>2026-10-05T00:00:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2026-10-05:/mit-ai-report-protect-the-struggle-not-the-grade.html</id><summary type="html">&lt;p&gt;&lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s &lt;span class="caps"&gt;AI&lt;/span&gt; committee says &lt;span class="caps"&gt;AI&lt;/span&gt; broke the proxies we use to measure learning. It rejects detectors and one campus-wide rule, and asks for &lt;span class="caps"&gt;AI&lt;/span&gt;-aware courses and&amp;nbsp;assessment.&lt;/p&gt;</summary><content type="html">&lt;h2 id="tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;On 13 August 2026, &lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s &lt;strong&gt;Ad Hoc Committee on &lt;span class="caps"&gt;AI&lt;/span&gt; Use in Teaching, Learning, and Research Training&lt;/strong&gt; published its final report after five months of meetings, surveys, and listening sessions. Asked for an &lt;span class="caps"&gt;AI&lt;/span&gt; use policy, it came back with a bigger claim: generative &lt;span class="caps"&gt;AI&lt;/span&gt; can already produce credible answers to almost any written assignment in &lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s undergraduate curriculum, so problem sets, take-home exams, and essays no longer prove that anyone learned anything, and students can skip the &lt;strong&gt;productive struggle&lt;/strong&gt; where the learning actually happens. The committee rejects a single campus-wide &lt;span class="caps"&gt;AI&lt;/span&gt; rule, &lt;span class="caps"&gt;AI&lt;/span&gt; detectors, and grade rationing, and recommends instead a four-option course policy menu with a stated rationale, more oral and project-based assessment, in-person social learning, protected research apprenticeships, and permanent machinery to keep revising all of&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;The outside evidence, much of it from short trials and preprints, points the same way. In the largest field experiment, a chatbot that handed out answers raised practice scores and lowered unassisted exam scores. Trials of &lt;span class="caps"&gt;AI&lt;/span&gt; that makes students explain and think found gains instead, more than double in one Harvard physics study. The biggest takeaway: &lt;span class="caps"&gt;AI&lt;/span&gt; did not break learning by itself. It broke the &lt;strong&gt;proxy&lt;/strong&gt; we used to measure learning, and used as an answer machine, it lets students skip the learning&amp;nbsp;too.&lt;/p&gt;
&lt;h2 id="what-this-report-is-not"&gt;What this report is&amp;nbsp;not&lt;/h2&gt;
&lt;p&gt;This is not a &amp;#8220;university bans ChatGPT&amp;#8221; story, and it is not an &lt;span class="caps"&gt;AI&lt;/span&gt; cheerleading memo either. The committee explicitly argues against policing: no reliance on &lt;span class="caps"&gt;AI&lt;/span&gt; detectors, no lockdown browsers for now, no grade rationing. It also does not ask anyone to stop using &lt;span class="caps"&gt;AI&lt;/span&gt;. Some courses, it says, should &lt;em&gt;require&lt;/em&gt;&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;What it is: a five-month attempt by students, faculty from every school, and staff (including the &lt;span class="caps"&gt;MIT&lt;/span&gt; Libraries and the Teaching and Learning Lab) to answer a harder question than &amp;#8220;is this cheating?&amp;#8221; The question is what an education is for when a chatbot can produce the deliverables. If you lead an engineering team that hires juniors, most of this report applies to you&amp;nbsp;too.&lt;/p&gt;
&lt;h2 id="ai-broke-the-proxy-first"&gt;&lt;span class="caps"&gt;AI&lt;/span&gt; broke the proxy&amp;nbsp;first&lt;/h2&gt;
&lt;p&gt;A problem set was never the point. It was evidence. You struggled through it, the struggle built understanding, and the answers you handed in were a cheap way for an instructor to check that the struggle had happened. That chain held for decades because there was no way to get the answers without doing the&amp;nbsp;work.&lt;/p&gt;
&lt;p&gt;Now there is. In the report&amp;#8217;s words, these technologies &amp;#8220;can produce credible solutions and provide reasonable responses to almost any written assignment in our undergraduate curriculum, including essays, math and science problems, proofs, and coding assignments.&amp;#8221; Using a chatbot to do your problem set is like sending a robot to the gym on your behalf. The logbook fills up. Your muscles do not&amp;nbsp;change.&lt;/p&gt;
&lt;p&gt;That is not only a metaphor. In a field experiment with nearly 1,000 Turkish high school students (&lt;a href="https://doi.org/10.1073/pnas.2422633122"&gt;Bastani et al., &lt;span class="caps"&gt;PNAS&lt;/span&gt; 2025&lt;/a&gt;), access to &lt;span class="caps"&gt;GPT&lt;/span&gt;-4 during practice sessions raised practice grades by 48%. On the unassisted exam that followed, the same students scored 17% lower than classmates who never had access. A second version of the chatbot, told to give teacher-designed hints instead of answers, raised practice grades by 127% and only erased the harm: no gain on the exam. The proxy went up while the learning went&amp;nbsp;down.&lt;/p&gt;
&lt;pre class="mermaid"&gt;
flowchart LR
    classDef work fill:#1e66f5,color:#ffffff,stroke:#1e4ed8,stroke-width:2px;
    classDef learn fill:#2f7a20,color:#ffffff,stroke:#1f5216,stroke-width:2px;
    classDef skip fill:#d20f39,color:#ffffff,stroke:#a10c2d,stroke-width:2px;
    subgraph Before["Before: the answers are evidence"]
        A1[Problem set]:::work --&gt; S1[Productive struggle]:::work
        S1 --&gt; L1[Learning]:::learn
        S1 --&gt; O1[Answers handed in]:::work --&gt; G1[Grade]:::work
    end
    subgraph After["With unrestricted AI"]
        A2[Problem set]:::work --&gt; C2[Chatbot]:::skip --&gt; O2[Answers handed in]:::work --&gt; G2[Grade]:::work
        A2 -.-&gt; L2[Learning skipped]:::skip
    end
&lt;/pre&gt;

&lt;p&gt;Why does skipping the struggle cost so much? Because the struggle is where the learning happens, and that is not a romantic idea. A meta-analysis of 53 studies found that students who wrestle with a problem before they are taught the solution learn more than students who are taught first (Hedges&amp;#8217; g of 0.36), as long as instruction follows the struggle (&lt;a href="https://doi.org/10.3102/00346543211019105"&gt;Sinha and Kapur, 2021&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The committee names the failure mode &lt;strong&gt;cognitive surrender&lt;/strong&gt;: falling back on &lt;span class="caps"&gt;AI&lt;/span&gt; at the first hint of struggle. Students told the committee the temptation peaks when they fear missing a deadline. Getting the right answer from a chatbot, the report warns, &amp;#8220;can create the illusion of&amp;nbsp;learning.&amp;#8221;&lt;/p&gt;
&lt;p&gt;The preprint behind that term puts numbers on it (&lt;a href="https://doi.org/10.31234/osf.io/yk25n_v1"&gt;Shaw and Nave, 2026&lt;/a&gt;). Across three preregistered experiments with 1,372 people, participants solved reasoning puzzles with an &lt;span class="caps"&gt;AI&lt;/span&gt; assistant that was secretly wrong on some of them. In the first study, people who consulted it followed its wrong answers 79.8% of the time, and access to the &lt;span class="caps"&gt;AI&lt;/span&gt; raised their confidence by 11.7 percentage points. Persistence suffers too. In randomized trials with 1,222 people (&lt;a href="https://arxiv.org/abs/2604.04721"&gt;Liu, Christian and colleagues, &lt;span class="caps"&gt;COLM&lt;/span&gt; 2026&lt;/a&gt;), about ten minutes of &lt;span class="caps"&gt;AI&lt;/span&gt; help was enough. In the first trial, once the &lt;span class="caps"&gt;AI&lt;/span&gt; was taken away, participants had a solve rate of 0.57 against 0.73 for a control group, and they skipped more&amp;nbsp;problems.&lt;/p&gt;
&lt;p&gt;The damage is social as well as cognitive. In less than three years, the report says, &lt;span class="caps"&gt;AI&lt;/span&gt; has driven decreased attendance at office hours, reduced participation in online discussions, and, anecdotally, fewer in-person study groups. Meanwhile instructors feel like police, and students fear false accusations of cheating while resenting instructors who use &lt;span class="caps"&gt;AI&lt;/span&gt; to grade. The committee&amp;#8217;s phrase for this is memorable: &amp;#8220;an underground river of mutual&amp;nbsp;suspicion.&amp;#8221;&lt;/p&gt;
&lt;h2 id="eight-principles-before-any-rules"&gt;Eight principles before any&amp;nbsp;rules&lt;/h2&gt;
&lt;p&gt;Before it recommends anything, the report sets out eight principles. They are worth reading as a set, because they rule out most of the knee-jerk&amp;nbsp;responses.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Principle&lt;/th&gt;
&lt;th&gt;What it means in practice&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Be humble&lt;/td&gt;
&lt;td&gt;Generative &lt;span class="caps"&gt;AI&lt;/span&gt; became usable in late 2022, so public use is less than four years old. Expect course corrections.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Be bold&lt;/td&gt;
&lt;td&gt;No &amp;#8220;patches and duct tape&amp;#8221;. Redesign courses, assessments, and curricula.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Put humanity front and center&lt;/td&gt;
&lt;td&gt;Protect the community and its relationships, even when &lt;span class="caps"&gt;AI&lt;/span&gt; is faster or cheaper.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lean into learning&lt;/td&gt;
&lt;td&gt;Struggle is the process. The product of an education is the student, not the &lt;span class="caps"&gt;GPA&lt;/span&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Teach with intentionality&lt;/td&gt;
&lt;td&gt;Use &lt;strong&gt;backward design&lt;/strong&gt;: define what students should know, do, and value, then design assessments to match.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No one size fits all&lt;/td&gt;
&lt;td&gt;A poetry seminar, a proof course, and a design studio need different &lt;span class="caps"&gt;AI&lt;/span&gt; policies.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Augmentation not automation&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;AI&lt;/span&gt; should expand what students can think about, not do the thinking for them.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Think beyond the classroom&lt;/td&gt;
&lt;td&gt;Students carry the habits they learn here into work and society.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The &amp;#8220;augmentation not automation&amp;#8221; principle borrows from &lt;span class="caps"&gt;MIT&lt;/span&gt; economists Daron Acemoglu, David Autor, and Simon Johnson, who argue for &lt;strong&gt;pro-worker &lt;span class="caps"&gt;AI&lt;/span&gt;&lt;/strong&gt;: systems that make people more effective at existing tasks and help them learn new ones, instead of replacing them. The committee&amp;#8217;s version is &amp;#8220;pro-learner&amp;#8221; &lt;span class="caps"&gt;AI&lt;/span&gt;. It is the same stance Linus Torvalds took when he called &lt;span class="caps"&gt;AI&lt;/span&gt; &lt;a href="https://alexsavio.github.io/torvalds-ai-is-a-tool-not-a-replacement.html"&gt;a tool in the compiler lineage, not a replacement&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Recent randomized trials split along exactly this line. The same technology helps or hurts depending on whether it does the thinking or prompts&amp;nbsp;it:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Study&lt;/th&gt;
&lt;th&gt;Setup&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://arxiv.org/abs/2601.20245"&gt;Shen and Tamkin, Anthropic, 2026&lt;/a&gt; (preprint)&lt;/td&gt;
&lt;td&gt;52 mostly junior developers learn a new Python library, with or without &lt;span class="caps"&gt;AI&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;The &lt;span class="caps"&gt;AI&lt;/span&gt; group scored 50% on the follow-up quiz against 67% without &lt;span class="caps"&gt;AI&lt;/span&gt;, and was not significantly faster. Developers who only asked conceptual questions kept their learning; delegating the code is what hurt.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://arxiv.org/abs/2607.08849"&gt;Contractor and Reyes, 2026&lt;/a&gt; (preprint)&lt;/td&gt;
&lt;td&gt;211 undergraduates use off-the-shelf &lt;span class="caps"&gt;AI&lt;/span&gt; in one session, then are tested unaided a week later&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;AI&lt;/span&gt; raised test scores by 0.27 standard deviations, and the gains persisted. Essay gains a week later were larger for students who used &lt;span class="caps"&gt;AI&lt;/span&gt; to explain concepts; for students who used it to generate text, the short-run gains vanished once &lt;span class="caps"&gt;AI&lt;/span&gt; was removed.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://doi.org/10.1038/s41598-025-97652-6"&gt;Kestin et al., Scientific Reports 2025&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Harvard intro physics: a custom &lt;span class="caps"&gt;AI&lt;/span&gt; tutor built on teaching research vs an in-class active-learning lesson&lt;/td&gt;
&lt;td&gt;Median learning gains were more than double, with a median 49 minutes on task against a 60-minute class.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://arxiv.org/abs/2410.03017"&gt;Wang et al., Tutor CoPilot&lt;/a&gt; (preprint)&lt;/td&gt;
&lt;td&gt;900 human tutors and 1,800 K-12 students; the &lt;span class="caps"&gt;AI&lt;/span&gt; coaches the tutor, not the student&lt;/td&gt;
&lt;td&gt;Students were 4 percentage points more likely to master topics, and 9 points more for students of lower-rated tutors.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://doi.org/10.26300/y3f8-vh05"&gt;Liu et al., 2026&lt;/a&gt; (working paper)&lt;/td&gt;
&lt;td&gt;2,379 undergraduates at a large &lt;span class="caps"&gt;US&lt;/span&gt; public university; an &lt;span class="caps"&gt;AI&lt;/span&gt; tutor built into the course&lt;/td&gt;
&lt;td&gt;Tutor access lowered final grades by 0.27 to 0.37 standard deviations, with the clearest evidence among sections of the same course, and larger losses for first-generation students.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The last row is the warning label. Calling something a &amp;#8220;tutor&amp;#8221; does not make it one, and the students who lost the most were first-generation students, often the ones a free tutor is meant to help. What matters is whether the design makes the student do the thinking, and that is what the committee means by&amp;nbsp;augmentation.&lt;/p&gt;
&lt;p&gt;One caution on all of this evidence: most of these studies are short, several are preprints or working papers, and none was run on &lt;span class="caps"&gt;MIT&lt;/span&gt; courses. Read them as a direction, not a&amp;nbsp;dose.&lt;/p&gt;
&lt;h2 id="the-obvious-fix-is-a-trap"&gt;The obvious fix is a&amp;nbsp;trap&lt;/h2&gt;
&lt;p&gt;Here is the counter-intuitive part. When take-home work stops being trustworthy, the instinct is to move the weight of the grade into timed, in-class exams. Many instructors are already doing exactly&amp;nbsp;that.&lt;/p&gt;
&lt;p&gt;The committee argues this backfires. Students lose the incentive to invest in the difficult problem sets and projects that build mastery, and a time-limited exam caps how much thought anyone can put in. In the report&amp;#8217;s words, quick, high-stakes evaluations &amp;#8220;embody the opposite of the signal we want to convey.&amp;#8221; It also risks narrowing what an &lt;span class="caps"&gt;MIT&lt;/span&gt; degree has long signaled: that its graduates &amp;#8220;are capable of difficult, independent, and thought-intensive problem solving, not just acing exams on&amp;nbsp;paper.&amp;#8221;&lt;/p&gt;
&lt;p&gt;The same logic kills &lt;strong&gt;grade rationing&lt;/strong&gt;. Limit the number of A&amp;#8217;s, and students who want to protect their &lt;span class="caps"&gt;GPA&lt;/span&gt; get an even stronger reason to cut corners with &lt;span class="caps"&gt;AI&lt;/span&gt;. The committee goes further and floats a thought experiment: if &lt;span class="caps"&gt;MIT&lt;/span&gt; had no grades, many of the incentives behind &lt;span class="caps"&gt;AI&lt;/span&gt; cheating would&amp;nbsp;disappear.&lt;/p&gt;
&lt;p&gt;What it recommends&amp;nbsp;instead:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Assessments that resist &lt;span class="caps"&gt;AI&lt;/span&gt; and teach at the same time&lt;/strong&gt;: oral exams, semester portfolios, and out-of-class work paired with in-class conversations about&amp;nbsp;it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Process evidence&lt;/strong&gt;: platforms that record a version history, so a submission that appears minutes after the assignment opens stands out. Students also use these histories to reflect on how their thinking&amp;nbsp;evolved.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Experiential and project work&lt;/strong&gt;: in &lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s capstone software engineering class, students can now reasonably build near production-quality software in a single term with &lt;span class="caps"&gt;AI&lt;/span&gt; coding tools. Raise the ambition instead of fighting the&amp;nbsp;tools.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A regular in-person social component in every subject&lt;/strong&gt;: group work with check-ins, &lt;span class="caps"&gt;TA&lt;/span&gt;-guided problem sessions, graded&amp;nbsp;discussions.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="a-policy-menu-not-a-rule"&gt;A policy menu, not a&amp;nbsp;rule&lt;/h2&gt;
&lt;p&gt;Students told the committee that &lt;span class="caps"&gt;AI&lt;/span&gt; guidance is confusing and varies wildly between instructors. The committee still refuses a single campus rule, because any uniform rule would be too permissive for some courses and too strict for others. Its answer is a shared menu, chosen per course or per assignment, with a traffic-light icon for each&amp;nbsp;option:&lt;/p&gt;
&lt;pre class="mermaid"&gt;
flowchart TD
    classDef step fill:#1e66f5,color:#ffffff,stroke:#1e4ed8,stroke-width:2px;
    classDef green fill:#2f7a20,color:#ffffff,stroke:#1f5216,stroke-width:2px;
    classDef yellow fill:#df8e1d,color:#1e1e2e,stroke:#b5730f,stroke-width:2px;
    classDef red fill:#d20f39,color:#ffffff,stroke:#a10c2d,stroke-width:2px;
    G[Learning goals: what students should know, do, and value]:::step --&gt; A[Assessments that measure those goals]:::step
    A --&gt; P{Pick an AI policy per course or assignment}:::step
    P --&gt; U[Unrestricted use]:::green
    P --&gt; S[Support tool only]:::yellow
    P --&gt; R[Required use]:::green
    P --&gt; X[Strictly prohibited]:::red
    U --&gt; W[Post it in the syllabus, with the rationale]:::step
    S --&gt; W
    R --&gt; W
    X --&gt; W
&lt;/pre&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Policy&lt;/th&gt;
&lt;th&gt;Rule&lt;/th&gt;
&lt;th&gt;Best suited for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Unrestricted&lt;/td&gt;
&lt;td&gt;Any GenAI system, any purpose&lt;/td&gt;
&lt;td&gt;Courses assessed in class, or projects too ambitious for current tools&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Support tool only&lt;/td&gt;
&lt;td&gt;Tutor, editor, debugger; no full or substantial solutions&lt;/td&gt;
&lt;td&gt;Courses where independent problem solving is central&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Required&lt;/td&gt;
&lt;td&gt;Use the designated tools and workflow, document the interactions&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;AI&lt;/span&gt;-assisted programming, prompt engineering, critique of model outputs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Strictly prohibited&lt;/td&gt;
&lt;td&gt;No GenAI in any form&lt;/td&gt;
&lt;td&gt;Not stated; the committee warns it is hard to enforce outside class&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Two details make this work. First, every policy needs a &lt;strong&gt;rationale tied to the course&amp;#8217;s learning goals&lt;/strong&gt;. Declaring &lt;span class="caps"&gt;AI&lt;/span&gt; use to be cheating teaches nothing. Explaining that &lt;span class="caps"&gt;AI&lt;/span&gt; skips the exact skill the exam will test teaches students to think about their own learning. Second, the committee admits the middle option is the hardest: students and faculty disagree about whether an &lt;span class="caps"&gt;AI&lt;/span&gt;-written outline counts as&amp;nbsp;&amp;#8220;support&amp;#8221;.&lt;/p&gt;
&lt;p&gt;&lt;span class="caps"&gt;MIT&lt;/span&gt; is not alone in refusing a single rule. Brown&amp;#8217;s July 2026 committee report puts it plainly: &amp;#8220;There is no one-size-fits-all approach.&amp;#8221; Harvard&amp;#8217;s faculty also set policy course by course, but lean much harder toward restriction. In The Harvard Crimson&amp;#8217;s 2026 survey of Faculty of Arts and Sciences members, 64% said &lt;span class="caps"&gt;AI&lt;/span&gt; had a negative effect on their courses, and 24% now prohibit &lt;span class="caps"&gt;AI&lt;/span&gt; entirely, the one option &lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s committee calls hard to&amp;nbsp;enforce.&lt;/p&gt;
&lt;h2 id="no-detectors-and-not-these-lockdown-browsers"&gt;No detectors, and not these lockdown&amp;nbsp;browsers&lt;/h2&gt;
&lt;p&gt;The committee recommends against relying on &lt;strong&gt;&lt;span class="caps"&gt;AI&lt;/span&gt; detectors&lt;/strong&gt;. They miss mixed work, such as an &lt;span class="caps"&gt;AI&lt;/span&gt;-drafted outline. They invite an arms race with &amp;#8220;&lt;span class="caps"&gt;AI&lt;/span&gt; humanizers&amp;#8221;. And they can mistake the writing of non-native English speakers or neurodivergent students for &lt;span class="caps"&gt;AI&lt;/span&gt; output. Even &lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s Committee on Discipline does not consider detector output alone sufficient&amp;nbsp;evidence.&lt;/p&gt;
&lt;p&gt;The evidence is on the committee&amp;#8217;s side. In a 2023 peer-reviewed test of seven detectors of that time (&lt;a href="https://doi.org/10.1016/j.patter.2023.100779"&gt;Liang et al., Patterns 2023&lt;/a&gt;), the average false-positive rate on 91 &lt;span class="caps"&gt;TOEFL&lt;/span&gt; essays by non-native speakers was 61.22%, while essays by &lt;span class="caps"&gt;US&lt;/span&gt; eighth graders were classified almost perfectly. OpenAI withdrew its own &lt;span class="caps"&gt;AI&lt;/span&gt;-text classifier on 20 July 2023 &amp;#8220;due to its low rate of accuracy&amp;#8221;; at launch it caught 26% of &lt;span class="caps"&gt;AI&lt;/span&gt;-written text. A 2026 preprint from Notre Dame (&lt;a href="https://arxiv.org/abs/2608.11256"&gt;Karr et al.&lt;/a&gt;) shows the arms race in one result: after a humanizer pass, fewer than 4% of &lt;span class="caps"&gt;AI&lt;/span&gt; rewrites were still flagged, while light, guideline-style &lt;span class="caps"&gt;AI&lt;/span&gt; edits were flagged 38 to 80% of the time. Honest &lt;span class="caps"&gt;AI&lt;/span&gt; editing, the authors write, &amp;#8220;results in a higher sanction risk than humanizer-assisted evasion.&amp;#8221; Brown&amp;#8217;s report found the same consensus among its peers: of 13 Ivy Plus and Public Ivy institutions with medical schools, seven recommended against, discouraged, or did not endorse detection software, and none endorsed&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lockdown browsers&lt;/strong&gt; get a softer no. The committee asks &lt;span class="caps"&gt;MIT&lt;/span&gt; to study them, but calls the current generation &amp;#8220;buggy, error-prone and feels like surveillance.&amp;#8221; For now, in-person proctored exams are the better choice, which means &lt;span class="caps"&gt;MIT&lt;/span&gt; needs more physical space for&amp;nbsp;them.&lt;/p&gt;
&lt;p&gt;The report also turns the mirror on instructors. Students notice when an instructor uses &lt;span class="caps"&gt;AI&lt;/span&gt; for slides, feedback, or grading while restricting students, and they read it as a double standard. One refrain the committee heard: &amp;#8220;Why should I bother coming to class or doing the work if the teacher is just going to give an &lt;span class="caps"&gt;AI&lt;/span&gt;-generated lecture?&amp;#8221; The fix is disclosure: if &lt;span class="caps"&gt;AI&lt;/span&gt; generates course content or touches grading, say so and explain why. &lt;span class="caps"&gt;AI&lt;/span&gt; graders can still be useful, as a feedback tool handed to students along with the assignment, not as the final&amp;nbsp;judge.&lt;/p&gt;
&lt;h2 id="the-part-engineers-should-read-twice-apprenticeship"&gt;The part engineers should read twice:&amp;nbsp;apprenticeship&lt;/h2&gt;
&lt;p&gt;&lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s &lt;strong&gt;Undergraduate Research Opportunities Program (&lt;span class="caps"&gt;UROP&lt;/span&gt;)&lt;/strong&gt; started in 1969 and today directly engages 93% of undergraduates and 58% of faculty. In a listening session, the committee learned that some instructors were considering &lt;span class="caps"&gt;AI&lt;/span&gt; agents as research assistants instead of hiring&amp;nbsp;undergraduates.&lt;/p&gt;
&lt;p&gt;The committee&amp;#8217;s answer is blunt. &lt;span class="caps"&gt;UROP&lt;/span&gt; exists to educate, not to supply research labor. Learning by doing &amp;#8220;may produce seeming &amp;#8216;inefficiencies,&amp;#8217; but that&amp;#8217;s a feature, not a bug.&amp;#8221; Replace novices with agents and students lose more than research hours. They lose the path into a research community: joining a lab, presenting at group meetings, learning how credit is shared and how mistakes are&amp;nbsp;handled.&lt;/p&gt;
&lt;p&gt;The report does not say this, but every word transfers to software teams. The ticket a junior engineer needs three days to close is their apprenticeship. An agent can close it faster, and the sprint looks better for it. Do that for a few years and you have no mid-level engineers to promote, because nobody got the reps. The &amp;#8220;inefficiency&amp;#8221; was the training program. It is the same point I took from Torvalds: &lt;a href="https://alexsavio.github.io/torvalds-ai-is-a-tool-not-a-replacement.html"&gt;the skill gap does not close, it moves&lt;/a&gt;. If you already have the judgment, &lt;span class="caps"&gt;AI&lt;/span&gt; raises your ceiling. If you do not, it mostly raises your confidence. Shaw and Nave saw that second half in the lab: access to &lt;span class="caps"&gt;AI&lt;/span&gt; raised confidence on reasoning puzzles even though about half of its answers were&amp;nbsp;wrong.&lt;/p&gt;
&lt;p&gt;The labor data points the same way, though none of it proves that &lt;span class="caps"&gt;AI&lt;/span&gt; is the cause. Working from &lt;span class="caps"&gt;ADP&lt;/span&gt; payroll records, Stanford&amp;#8217;s Digital Economy Lab finds that employment of 22-to-25-year-olds in &lt;span class="caps"&gt;AI&lt;/span&gt;-exposed occupations now sits 19% below where it would be had it kept pace with less-exposed peers, while experienced workers show no comparable gap (&lt;a href="https://digitaleconomy.stanford.edu/news/canariesaug26/"&gt;Brynjolfsson, Chandar and Chen, August 2026 update&lt;/a&gt;). The authors call these early, descriptive indicators rather than causal estimates. The gap comes &amp;#8220;primarily through reduced hiring of young workers rather than increased separations&amp;#8221;: fewer people get onto the entry rung, while the people already on it stay. A Harvard working paper sees the same inside firms: after generative &lt;span class="caps"&gt;AI&lt;/span&gt; adoption, junior employment at adopting firms fell 7.7% relative to controls within six quarters, driven by slower hiring (&lt;a href="https://papers.ssrn.com/sol3/papers.cfm?abstract_id=5425555"&gt;Hosseini and Lichtinger, 2025&lt;/a&gt;). Software sits at the extreme. In Indeed&amp;#8217;s postings data, software development had the lowest entry-level share of any sector in Q1 2026, 4.5%, and the highest senior share, 69.3% (&lt;a href="https://hiringlab.indeed.com/2026/07/23/the-labor-market-is-tilting-toward-seniority/"&gt;Indeed Hiring Lab&lt;/a&gt;). Indeed itself lists remote work and interest rate hikes as competing explanations. Still, the direction matches the committee&amp;#8217;s &lt;span class="caps"&gt;UROP&lt;/span&gt;&amp;nbsp;worry.&lt;/p&gt;
&lt;p&gt;The survey data hints that students feel this already. In &lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s spring 2026 Quality of Life survey, undergraduates felt more replaceable than capable because of &lt;span class="caps"&gt;AI&lt;/span&gt; (40% vs 34%), while grad students, postdocs, and faculty leaned the other way by a wide margin. The only other group leaning replaceable was service and support&amp;nbsp;staff:&lt;/p&gt;
&lt;pre class="mermaid"&gt;
%%{init: {"themeVariables": {"xyChart": {"plotColorPalette": "#d20f39"}}}}%%
xychart-beta
    title "AI makes me feel more replaceable (% rating 1 or 2)"
    x-axis ["Total", "Admin", "Faculty", "Grads/Postdocs", "Undergrads", "Service/Support"]
    y-axis "% of respondents" 0 --&gt; 50
    bar [27, 24, 20, 26, 40, 36]
&lt;/pre&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Group&lt;/th&gt;
&lt;th&gt;More capable (4 or 5)&lt;/th&gt;
&lt;th&gt;More replaceable (1 or 2)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Total (n=8,207)&lt;/td&gt;
&lt;td&gt;40%&lt;/td&gt;
&lt;td&gt;27%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Admin (n=2,572)&lt;/td&gt;
&lt;td&gt;40%&lt;/td&gt;
&lt;td&gt;24%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Faculty/Instructors (n=701)&lt;/td&gt;
&lt;td&gt;46%&lt;/td&gt;
&lt;td&gt;20%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Grad Students/Postdocs (n=2,344)&lt;/td&gt;
&lt;td&gt;49%&lt;/td&gt;
&lt;td&gt;26%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Undergrads (n=1,360)&lt;/td&gt;
&lt;td&gt;34%&lt;/td&gt;
&lt;td&gt;40%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Service/Support (n=806)&lt;/td&gt;
&lt;td&gt;24%&lt;/td&gt;
&lt;td&gt;36%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;em&gt;Values read from the report&amp;#8217;s published chart. The report&amp;#8217;s text states the totals and the undergraduate 40% vs 34% split. Undergraduates and service and support staff are the only groups where the replaceable share is larger than the capable&amp;nbsp;share.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id="teach-ai-and-make-access-fair"&gt;Teach &lt;span class="caps"&gt;AI&lt;/span&gt;, and make access&amp;nbsp;fair&lt;/h2&gt;
&lt;p&gt;The committee wants &lt;span class="caps"&gt;AI&lt;/span&gt; skills taught on purpose, in three layers. &lt;strong&gt;Effective&lt;/strong&gt; use: how to specify a problem, how to verify an output, when a model is likely to hallucinate, and when not to reach for &lt;span class="caps"&gt;AI&lt;/span&gt; at all. &lt;strong&gt;Responsible&lt;/strong&gt; use: knowing the difference between augmentation and automation, and disclosing &lt;span class="caps"&gt;AI&lt;/span&gt;&amp;#8217;s contribution honestly. &lt;strong&gt;Ethical&lt;/strong&gt; use: training data provenance, bias, homogenized outputs, environmental cost, and authorship. Verification is the layer most people skip, and it is the one I keep coming back to when &lt;a href="https://alexsavio.github.io/so-you-want-to-build-an-llm-agent.html"&gt;building &lt;span class="caps"&gt;LLM&lt;/span&gt; agents&lt;/a&gt;. Order matters too: build the agent loop by hand before you reach for a framework, because you cannot debug what you do not understand. The report makes the same distinction: a first-year student &amp;#8220;building foundational skills and judgment&amp;#8221; stands in a different relationship to &lt;span class="caps"&gt;AI&lt;/span&gt; than a doctoral candidate speeding up a literature review in a field they already&amp;nbsp;know.&lt;/p&gt;
&lt;p&gt;The demand is real. In The Tech&amp;#8217;s fall 2025 survey, 70% of responding students agreed that &lt;span class="caps"&gt;AI&lt;/span&gt; proficiency will matter in their careers, but only 25% believed &lt;span class="caps"&gt;MIT&lt;/span&gt; is preparing students to use it professionally. The same survey found 46% of undergraduates use LLMs daily, and 90% are somewhat or very concerned about overreliance, 67% very&amp;nbsp;concerned.&lt;/p&gt;
&lt;p&gt;Access is the other half. Top-tier commercial plans cost as much as $200/month (as of June 2026), and some students pay it while their peers cannot. &lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s model-agnostic platform, &lt;strong&gt;Parley&lt;/strong&gt;, gives everyone up to $30/month in free credits across commercial and open models, and it added &lt;span class="caps"&gt;API&lt;/span&gt; access for coding tools in the summer of 2026. The committee wants it kept model-agnostic, with more access where courses need it. It also flags a problem every company running an internal &lt;span class="caps"&gt;LLM&lt;/span&gt; gateway should recognize: an &lt;span class="caps"&gt;MIT&lt;/span&gt;-run system can, in theory, see every prompt. People already use these tools for emotional support, as they did with &lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s own &lt;span class="caps"&gt;ELIZA&lt;/span&gt;, so &lt;span class="caps"&gt;MIT&lt;/span&gt; needs an explicit policy on logging and auditing before an incident forces&amp;nbsp;one.&lt;/p&gt;
&lt;h2 id="the-machinery-to-keep-revising"&gt;The machinery to keep&amp;nbsp;revising&lt;/h2&gt;
&lt;p&gt;Because the technology moves faster than any report, the committee asks for permanent&amp;nbsp;structures:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An &lt;strong&gt;ongoing &lt;span class="caps"&gt;AI&lt;/span&gt; and education committee&lt;/strong&gt; for strategy, monitoring, and&amp;nbsp;policy.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class="caps"&gt;AI&lt;/span&gt; Leads&lt;/strong&gt; in each school and the college, or in each&amp;nbsp;department.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class="caps"&gt;AI&lt;/span&gt; Fellows and an &lt;span class="caps"&gt;AI&lt;/span&gt; Implementation Team&lt;/strong&gt; to help instructors redesign courses, since the Teaching and Learning Lab is already at&amp;nbsp;capacity.&lt;/li&gt;
&lt;li&gt;An &lt;strong&gt;&lt;span class="caps"&gt;AI&lt;/span&gt; Pilot Fund&lt;/strong&gt; for &lt;span class="caps"&gt;AI&lt;/span&gt; credits, TAs, UROPs, and summer support, including funding for deliberately &lt;span class="caps"&gt;AI&lt;/span&gt;-free&amp;nbsp;experiences.&lt;/li&gt;
&lt;li&gt;Training built by &lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s own community, not &amp;#8220;checking the box&amp;#8221; with generic third-party&amp;nbsp;courses.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Metrics&lt;/strong&gt; on &lt;span class="caps"&gt;AI&lt;/span&gt; use, engagement, and student satisfaction, plus published estimates of what &lt;span class="caps"&gt;AI&lt;/span&gt; use costs in money and environmental&amp;nbsp;impact.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Theses get a concrete rule: every thesis should include a statement on how &lt;span class="caps"&gt;AI&lt;/span&gt; was used, and &lt;span class="caps"&gt;AI&lt;/span&gt; should never be listed as a co-author. The committee practices this itself. Its appendix states that none of the report&amp;#8217;s text was generated with &lt;span class="caps"&gt;AI&lt;/span&gt;. ChatGPT checked early drafts for redundant sections, Codex generated some of the survey graphs, and members used &lt;span class="caps"&gt;AI&lt;/span&gt; to synthesize data and reports, such as summaries of other schools&amp;#8217; published positions, for their&amp;nbsp;discussions.&lt;/p&gt;
&lt;p&gt;&lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s leadership has picked the report up. In a letter on 25 August 2026, President Sally Kornbluth wrote that the opportunities and risks generative &lt;span class="caps"&gt;AI&lt;/span&gt; poses for &lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s model of education and research &amp;#8220;now constitute such a watershed for &lt;span class="caps"&gt;MIT&lt;/span&gt;.&amp;#8221; She listed &amp;#8220;ensuring that every class has an &lt;span class="caps"&gt;AI&lt;/span&gt; use policy suited to its purpose&amp;#8221; among the practical changes ahead, and wrote that the Institute is &amp;#8220;aggressively developing guidance, instruction, models, pilot funding, and &amp;#8216;communities of practice&amp;#8217; to help meet the&amp;nbsp;moment.&amp;#8221;&lt;/p&gt;
&lt;h2 id="where-the-report-is-thin"&gt;Where the report is&amp;nbsp;thin&lt;/h2&gt;
&lt;p&gt;The diagnosis is sharp. A few parts deserve&amp;nbsp;pushback.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Its own data cuts against &amp;#8220;students are confused.&amp;#8221;&lt;/strong&gt; In the Quality of Life survey, 72% of undergraduates agreed &lt;span class="caps"&gt;MIT&lt;/span&gt; had given them adequate guidance on &lt;span class="caps"&gt;AI&lt;/span&gt;, and the report notes the other groups reported much lower levels. In The Tech&amp;#8217;s survey, 75% of undergraduates found faculty expectations clear. The bigger guidance gap may sit with instructors and staff, which is where the &lt;span class="caps"&gt;AI&lt;/span&gt; Leads and Fellows should&amp;nbsp;start.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The costs are named, not priced.&lt;/strong&gt; Oral exams, smaller classes, more TAs, and staffed lab spaces all cost money and instructor time. The report admits the redesign effort &amp;#8220;is likely to be significant&amp;#8221; but gives no&amp;nbsp;budget.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The committee&amp;#8217;s own survey is self-selected.&lt;/strong&gt; It received 1,632 responses, a 12% response rate. Treat its percentages as a signal, not a&amp;nbsp;census.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Graduate students want a seat at the table.&lt;/strong&gt; The Tech reports that &lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s Graduate Student Union has proposed contract language to stop &lt;span class="caps"&gt;MIT&lt;/span&gt; from using &lt;span class="caps"&gt;AI&lt;/span&gt; to replace graduate student labor, and argues that &lt;span class="caps"&gt;MIT&lt;/span&gt; &amp;#8220;can&amp;#8217;t have the right to unilaterally impose these changes on the graduate population without further discussion.&amp;#8221; Teaching and research assistants are apprentices too, so this is the &lt;span class="caps"&gt;UROP&lt;/span&gt; argument from the other&amp;nbsp;side.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="protect-the-struggle"&gt;Protect the&amp;nbsp;struggle&lt;/h2&gt;
&lt;p&gt;The line I would put on every syllabus, and in every engineering onboarding doc, is this one: the most important product of an education &amp;#8220;is not a &lt;span class="caps"&gt;GPA&lt;/span&gt; or a diploma but &lt;em&gt;themselves&lt;/em&gt;.&amp;#8221; Grades, problem sets, and closed tickets were always proxies for that growth. &lt;span class="caps"&gt;AI&lt;/span&gt; made the proxies cheap, so the committee wants &lt;span class="caps"&gt;MIT&lt;/span&gt; to defend the growth directly, with conversations, projects, mentors, and honest policies instead of detectors. Companies face the same choice with their juniors. Let an agent take every hard ticket and you save a sprint and lose a future senior engineer. Protect the struggle, not the&amp;nbsp;grade.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://aiandeducation.mit.edu/report/"&gt;Report of &lt;span class="caps"&gt;MIT&lt;/span&gt;&amp;#8217;s Ad Hoc Committee on &lt;span class="caps"&gt;AI&lt;/span&gt; Use in Teaching, Learning, and Research Training&lt;/a&gt;, &lt;span class="caps"&gt;MIT&lt;/span&gt;, 2026-08-13, Original source (&lt;a href="https://aiandeducation.mit.edu/files/2026/09/AI-Committee-Final-Report-Aug-13.pdf"&gt;&lt;span class="caps"&gt;PDF&lt;/span&gt;&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aiandeducation.mit.edu/appendices/"&gt;Appendices: committee process, sample &lt;span class="caps"&gt;AI&lt;/span&gt; policies for syllabi, and survey results&lt;/a&gt;, &lt;span class="caps"&gt;MIT&lt;/span&gt;, 2026-08-13, Original&amp;nbsp;source&lt;/li&gt;
&lt;li&gt;&lt;a href="https://facultygovernance.mit.edu/committee/ad-hoc-committee-ai-use-teaching-learning-and-research-training"&gt;Ad Hoc Committee on &lt;span class="caps"&gt;AI&lt;/span&gt; Use in Teaching, Learning, and Research Training&lt;/a&gt;, &lt;span class="caps"&gt;MIT&lt;/span&gt; Faculty Governance, the committee&amp;#8217;s&amp;nbsp;charge&lt;/li&gt;
&lt;li&gt;&lt;a href="https://doi.org/10.3102/00346543211019105"&gt;When Problem Solving Followed by Instruction Works: Evidence for Productive Failure&lt;/a&gt;, Tanmay Sinha and Manu Kapur, Review of Educational Research, 2021, meta-analysis of 53 studies (&lt;a href="https://www.research-collection.ethz.ch/handle/20.500.11850/490417"&gt;open copy&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://doi.org/10.1073/pnas.2422633122"&gt;Generative &lt;span class="caps"&gt;AI&lt;/span&gt; without guardrails can harm learning: Evidence from high school mathematics&lt;/a&gt;, Hamsa Bastani et al., &lt;span class="caps"&gt;PNAS&lt;/span&gt;, 2025 (&lt;a href="https://pmc.ncbi.nlm.nih.gov/articles/PMC12232635/"&gt;open copy&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://doi.org/10.31234/osf.io/yk25n_v1"&gt;Thinking, Fast, Slow, and Artificial: How &lt;span class="caps"&gt;AI&lt;/span&gt; is Reshaping Human Reasoning and the Rise of Cognitive Surrender&lt;/a&gt;, Steven D. Shaw and Gideon Nave, PsyArXiv preprint, 2026, the report&amp;#8217;s source for &amp;#8220;cognitive&amp;nbsp;surrender&amp;#8221;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2604.04721"&gt;&lt;span class="caps"&gt;AI&lt;/span&gt; Assistance Reduces Persistence and Hurts Independent Performance&lt;/a&gt;, Grace Liu, Brian Christian, Tsvetomira Dumbalska, Michiel A. Bakker, and Rachit Dubey, &lt;span class="caps"&gt;COLM&lt;/span&gt;&amp;nbsp;2026&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.brookings.edu/articles/building-pro-worker-ai/"&gt;Building pro-worker &lt;span class="caps"&gt;AI&lt;/span&gt;&lt;/a&gt;, Daron Acemoglu, David Autor, and Simon Johnson, Brookings, the &amp;#8220;pro-worker &lt;span class="caps"&gt;AI&lt;/span&gt;&amp;#8221;&amp;nbsp;argument&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2601.20245"&gt;How &lt;span class="caps"&gt;AI&lt;/span&gt; Impacts Skill Formation&lt;/a&gt;, Judy Hanwen Shen and Alex Tamkin, Anthropic, 2026 (&lt;a href="https://www.anthropic.com/research/AI-assistance-coding-skills"&gt;summary&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2607.08849"&gt;Experimental Evidence on the Learning Impact of Generative &lt;span class="caps"&gt;AI&lt;/span&gt;&lt;/a&gt;, Zara Contractor and Germán Reyes,&amp;nbsp;2026&lt;/li&gt;
&lt;li&gt;&lt;a href="https://doi.org/10.1038/s41598-025-97652-6"&gt;&lt;span class="caps"&gt;AI&lt;/span&gt; tutoring outperforms in-class active learning: an &lt;span class="caps"&gt;RCT&lt;/span&gt; introducing a novel research-based design in an authentic educational setting&lt;/a&gt;, Greg Kestin et al., Scientific Reports,&amp;nbsp;2025&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2410.03017"&gt;Tutor CoPilot: A Human-&lt;span class="caps"&gt;AI&lt;/span&gt; Approach for Scaling Real-Time Expertise&lt;/a&gt;, Rose E. Wang, Ana T. Ribeiro, Carly D. Robinson, Susanna Loeb, and Dora&amp;nbsp;Demszky&lt;/li&gt;
&lt;li&gt;&lt;a href="https://doi.org/10.26300/y3f8-vh05"&gt;The Effects of Course-Integrated &lt;span class="caps"&gt;AI&lt;/span&gt; Tutoring on Student Performance and Engagement: A Randomized University Trial&lt;/a&gt;, Jing Liu et al., EdWorkingPaper 26-1598,&amp;nbsp;2026&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tll.mit.edu/teaching-resources/course-design/where-to-start-backward-design/"&gt;Where to Start: Backward Design&lt;/a&gt;, &lt;span class="caps"&gt;MIT&lt;/span&gt; Teaching + Learning&amp;nbsp;Lab&lt;/li&gt;
&lt;li&gt;&lt;a href="https://provost.brown.edu/sites/default/files/GAITL_Committee_Report_FNL.pdf"&gt;Generative &lt;span class="caps"&gt;AI&lt;/span&gt; in Teaching and Learning (&lt;span class="caps"&gt;GAITL&lt;/span&gt;) Committee Final Report and Recommendations&lt;/a&gt;, Brown University, July&amp;nbsp;2026&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.thecrimson.com/article/2026/9/14/fas-2026-survey-AI/"&gt;More than 60 Percent of Harvard Faculty Say &lt;span class="caps"&gt;AI&lt;/span&gt; Harms Their Courses&lt;/a&gt;, The Harvard Crimson,&amp;nbsp;2026-09-14&lt;/li&gt;
&lt;li&gt;&lt;a href="https://doi.org/10.1016/j.patter.2023.100779"&gt;&lt;span class="caps"&gt;GPT&lt;/span&gt; detectors are biased against non-native English writers&lt;/a&gt;, Weixin Liang, Mert Yuksekgonul, Yining Mao, Eric Wu, and James Zou, Patterns,&amp;nbsp;2023&lt;/li&gt;
&lt;li&gt;&lt;a href="https://openai.com/index/new-ai-classifier-for-indicating-ai-written-text/"&gt;New &lt;span class="caps"&gt;AI&lt;/span&gt; classifier for indicating &lt;span class="caps"&gt;AI&lt;/span&gt;-written text&lt;/a&gt;, OpenAI, 2023, withdrawn on 2023-07-20 (&lt;a href="https://web.archive.org/web/20260929162626/https://openai.com/index/new-ai-classifier-for-indicating-ai-written-text/"&gt;archived copy&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2608.11256"&gt;Why &lt;span class="caps"&gt;AI&lt;/span&gt; Detection Fails for Academic Integrity&lt;/a&gt;, Jonathan A. Karr Jr., Grigorii Khvatskii, Ting Hua, and Nitesh V. Chawla, University of Notre Dame,&amp;nbsp;2026&lt;/li&gt;
&lt;li&gt;&lt;a href="https://urop.mit.edu/"&gt;Undergraduate Research Opportunities Program&lt;/a&gt;, &lt;span class="caps"&gt;MIT&lt;/span&gt; &lt;span class="caps"&gt;UROP&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://digitaleconomy.stanford.edu/publication/canaries-in-the-coal-mine-six-facts-about-the-recent-employment-effects-of-artificial-intelligence/"&gt;Canaries in the Coal Mine? Six Facts about the Recent Employment Effects of Artificial Intelligence&lt;/a&gt;, Erik Brynjolfsson, Bharat Chandar, and Ruyu Chen, Stanford Digital Economy Lab (&lt;a href="https://digitaleconomy.stanford.edu/news/canariesaug26/"&gt;August 2026 update&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://papers.ssrn.com/sol3/papers.cfm?abstract_id=5425555"&gt;Generative &lt;span class="caps"&gt;AI&lt;/span&gt; as Seniority-Biased Technological Change: Evidence from &lt;span class="caps"&gt;U.S.&lt;/span&gt; Résumé and Job Posting Data&lt;/a&gt;, Seyed M. Hosseini and Guy Lichtinger, Harvard, 2025 (&lt;a href="https://web.archive.org/web/20261002195414/https://papers.ssrn.com/sol3/papers.cfm?abstract_id=5425555"&gt;archived copy&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hiringlab.indeed.com/2026/07/23/the-labor-market-is-tilting-toward-seniority/"&gt;The Labor Market Is Tilting Toward Seniority&lt;/a&gt;, Indeed Hiring Lab,&amp;nbsp;2026-07-23&lt;/li&gt;
&lt;li&gt;&lt;a href="https://parley.mit.edu/"&gt;Parley&lt;/a&gt;, &lt;span class="caps"&gt;MIT&lt;/span&gt; &lt;span class="caps"&gt;IS&lt;/span&gt;&amp;amp;T&amp;#8217;s model-agnostic &lt;span class="caps"&gt;AI&lt;/span&gt;&amp;nbsp;platform&lt;/li&gt;
&lt;li&gt;&lt;a href="https://thetech.com/2025/11/25/llm-survey-results"&gt;Over a thousand &lt;span class="caps"&gt;MIT&lt;/span&gt; affiliates respond to The Tech&amp;#8217;s &lt;span class="caps"&gt;LLM&lt;/span&gt; usage survey&lt;/a&gt;, The Tech, 2025-11-25, the fall 2025&amp;nbsp;survey&lt;/li&gt;
&lt;li&gt;&lt;a href="https://qol.mit.edu/"&gt;2026 &lt;span class="caps"&gt;MIT&lt;/span&gt; Quality of Life Survey&lt;/a&gt;, source of the spring 2026 &lt;span class="caps"&gt;AI&lt;/span&gt;&amp;nbsp;questions&lt;/li&gt;
&lt;li&gt;&lt;a href="https://news.mit.edu/2025/explained-generative-ai-environmental-impact-0117"&gt;Explained: Generative &lt;span class="caps"&gt;AI&lt;/span&gt;&amp;#8217;s environmental impact&lt;/a&gt;, &lt;span class="caps"&gt;MIT&lt;/span&gt; News,&amp;nbsp;2025-01-17&lt;/li&gt;
&lt;li&gt;&lt;a href="https://orgchart.mit.edu/letters/ai-and-education-watershed-moment-mit"&gt;&lt;span class="caps"&gt;AI&lt;/span&gt; and education: A watershed moment for &lt;span class="caps"&gt;MIT&lt;/span&gt;&lt;/a&gt;, Sally Kornbluth, &lt;span class="caps"&gt;MIT&lt;/span&gt;,&amp;nbsp;2026-08-25&lt;/li&gt;
&lt;li&gt;&lt;a href="https://thetech.com/2026/09/17/ai-committee-report"&gt;&lt;span class="caps"&gt;MIT&lt;/span&gt; &lt;span class="caps"&gt;AI&lt;/span&gt; report takes first step towards an Institute-wide response&lt;/a&gt;, The Tech,&amp;nbsp;2026-09-17&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/torvalds-ai-is-a-tool-not-a-replacement"&gt;Torvalds on &lt;span class="caps"&gt;AI&lt;/span&gt;: It Is a Tool, and 100% of Your Code Was Always Written by Compilers&lt;/a&gt;, Related post on &lt;span class="caps"&gt;AI&lt;/span&gt; as a tool, not a&amp;nbsp;replacement&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/so-you-want-to-build-an-llm-agent"&gt;So You Want To Build An &lt;span class="caps"&gt;LLM&lt;/span&gt; Agent&lt;/a&gt;, Related post on why verification, not generation, is the hard&amp;nbsp;part&lt;/li&gt;
&lt;/ol&gt;</content><category term="Engineering"/><category term="ai"/><category term="llm"/><category term="education"/><category term="code-generation"/><category term="productivity"/></entry><entry><title>Jev: An AI Model That Returns Types, Not Text</title><link href="https://alexsavio.github.io/jev-system-one-models-types-not-text.html" rel="alternate"/><published>2026-09-28T00:00:00+02:00</published><updated>2026-09-28T00:00:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2026-09-28:/jev-system-one-models-types-not-text.html</id><summary type="html">&lt;p&gt;TypeSafe &lt;span class="caps"&gt;AI&lt;/span&gt;&amp;#8217;s Jev is a &amp;#8220;System One model&amp;#8221;: it takes state and typed questions and returns calibrated probabilities instead of text, in one parallel pass. The speed claims are self-tested, but its evals hide a better lesson: small typed questions glued together by code beat a bigger model with a longer&amp;nbsp;prompt.&lt;/p&gt;</summary><content type="html">&lt;h2 id="tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;On 15 September 2026, TypeSafe &lt;span class="caps"&gt;AI&lt;/span&gt;, a startup led by InstructGPT co-author Diogo Almeida, released &lt;strong&gt;Jev&lt;/strong&gt;, which it calls the first &lt;strong&gt;System One model&lt;/strong&gt;. Jev does not generate text. You send it some state and a set of typed questions (pick one of these options, rate this on a scale, is this statement true?) and it returns a probability for every possible answer, all computed in one parallel pass. Under the hood it most likely keeps the prompt-reading half of an &lt;span class="caps"&gt;LLM&lt;/span&gt; and drops the token-by-token writing half. Input costs $0.042 per million tokens, output is free, and TypeSafe quotes response times of 70 to 500 ms. The headline multipliers, 193.6x faster and 444.6x cheaper, come from TypeSafe&amp;#8217;s own evals, and TypeSafe itself calls them the high end. The more durable lesson sits in the same eval data: averaged over TypeSafe&amp;#8217;s four tasks, every model tested, cheap or frontier, got more accurate, cheaper, and faster when the task was split into small typed questions glued together by&amp;nbsp;code.&lt;/p&gt;
&lt;h2 id="what-jev-is-not"&gt;What Jev is&amp;nbsp;not&lt;/h2&gt;
&lt;p&gt;Jev is not a smaller &lt;span class="caps"&gt;LLM&lt;/span&gt;, and it is not &lt;span class="caps"&gt;JSON&lt;/span&gt; mode. Every major &lt;span class="caps"&gt;LLM&lt;/span&gt; &lt;span class="caps"&gt;API&lt;/span&gt; can already return &lt;span class="caps"&gt;JSON&lt;/span&gt; that matches a schema by masking invalid tokens during decoding. That is still text generation with a fence around it: one token at a time, each one billed, parsed and validated afterwards. Almeida argued in the Hacker News launch thread that this kind of &lt;strong&gt;constrained decoding&lt;/strong&gt; makes models dumber: if a model puts probability on an invalid token, it is already confused, and the mask only hides&amp;nbsp;that.&lt;/p&gt;
&lt;p&gt;Jev drops strings entirely. There is no decoder producing text, so there is nothing to constrain. Answers are values from a set you define up front, which means the model cannot return a malformed response or an option you did not list. That is the precise meaning behind the &amp;#8220;can&amp;#8217;t hallucinate&amp;#8221; marketing line, and we will get to where the line stops being&amp;nbsp;true.&lt;/p&gt;
&lt;h2 id="the-interface-state-in-typed-decisions-out"&gt;The interface: state in, typed decisions&amp;nbsp;out&lt;/h2&gt;
&lt;p&gt;A request has two parts. The &lt;strong&gt;state&lt;/strong&gt; is whatever the decision is about: a string, a &lt;span class="caps"&gt;JSON&lt;/span&gt; object, or an array of text. The &lt;strong&gt;questions&lt;/strong&gt; are typed, and there are three&amp;nbsp;types:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Primitive&lt;/th&gt;
&lt;th&gt;Asks&lt;/th&gt;
&lt;th&gt;Returns&lt;/th&gt;
&lt;th&gt;Maps to in code&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Choice&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Pick one option from a list&lt;/td&gt;
&lt;td&gt;the choice, a probability per option, a confidence&lt;/td&gt;
&lt;td&gt;&lt;code&gt;match&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Score&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Rate the state on an ordered rubric&lt;/td&gt;
&lt;td&gt;a score, a probability per level, a confidence&lt;/td&gt;
&lt;td&gt;sorting&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Noul&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Is this statement true?&lt;/td&gt;
&lt;td&gt;one probability between 0 and 1&lt;/td&gt;
&lt;td&gt;&lt;code&gt;if&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The last column is Almeida&amp;#8217;s own framing from the launch thread: &amp;#8220;choice maps to &amp;#8216;match&amp;#8217; statement, &amp;#8216;score&amp;#8217; maps to sorting, &amp;#8216;noul&amp;#8217; short for bernoulli maps to if-statements&amp;#8221;. That is the whole pitch in one line. Jev is a &lt;strong&gt;smart if-statement&lt;/strong&gt;: a branch condition that can read a support&amp;nbsp;ticket.&lt;/p&gt;
&lt;p&gt;Notice that you declare every possible answer before the model sees anything. The question schema is a contract between the model and your code. It is the same move I argued for in &lt;a href="https://alexsavio.github.io/first-principles-data-engineering"&gt;First Principles: Data Engineering and ETLs&lt;/a&gt;: make the agreement between producer and consumer explicit, and the gap between them becomes something you can&amp;nbsp;test.&lt;/p&gt;
&lt;p&gt;The official Python &lt;span class="caps"&gt;SDK&lt;/span&gt; makes the shape&amp;nbsp;obvious:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;typesafe_sdk&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Choice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;TypeSafeClient&lt;/span&gt;

&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;TypeSafeClient&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;system_one&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"document"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"I was charged twice. Please fix this ASAP."&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="n"&gt;questions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"category"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Choice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;instructions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"What is this ticket about?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;criteria&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"billing"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"technical"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"other"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"category"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;pre class="mermaid"&gt;
flowchart LR
    classDef input fill:#1e66f5,color:#ffffff,stroke:#1e4ed8,stroke-width:2px;
    classDef model fill:#8839ef,color:#ffffff,stroke:#6c2bd9,stroke-width:2px;
    classDef code fill:#40a02b,color:#ffffff,stroke:#2f7a20,stroke-width:2px;
    S[State&lt;br/&gt;ticket, account, policy]:::input --&gt; J
    Q[Typed questions&lt;br/&gt;Choice, Score, Noul]:::input --&gt; J
    J[Jev&lt;br/&gt;one parallel pass]:::model --&gt; C[Choice + probabilities]
    J --&gt; SC[Score + probabilities]
    J --&gt; N[Noul probability]
    C --&gt; M[match]:::code
    SC --&gt; SO[sort or threshold]:::code
    N --&gt; I[if]:::code
&lt;/pre&gt;

&lt;p&gt;Every question is evaluated in isolation against the same state, in the same pass. The docs say adding questions &amp;#8220;barely changes the response time&amp;#8221; and does not create context rot between them. That flips how you write prompts. Instead of one long instruction that tries to cover every case, you ask every question you might need, including speculative ones, and let your code ignore the answers that do not apply. TypeSafe calls this &lt;strong&gt;speculative fan-out&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id="how-it-works-under-the-hood"&gt;How it works under the&amp;nbsp;hood&lt;/h2&gt;
&lt;p&gt;TypeSafe has not published Jev&amp;#8217;s architecture. Almeida said on Hacker News that it is &amp;#8220;close to the chest for now&amp;#8221;. So this section keeps three kinds of evidence apart: what TypeSafe states, what outsiders measured against the live &lt;span class="caps"&gt;API&lt;/span&gt;, and what is an educated guess. Most of the measurements come from Archer Hume&amp;#8217;s &lt;a href="https://archerhume.com/posts/jevs-architecture-unmasked/"&gt;Jev&amp;#8217;s Architecture Unmasked&lt;/a&gt;, which&amp;nbsp;probed &lt;code&gt;jev-1.13.0&lt;/code&gt; with more than a thousand instrumented requests on 17 September 2026. Hume treated Jev as a sealed box and worked out its internal state from its external outputs alone: latency, token counts, and probabilities. That is the control-theory definition of observability I built on in &lt;a href="https://alexsavio.github.io/first-principles-software-observability"&gt;First Principles: Software Observability&lt;/a&gt;, applied to someone else&amp;#8217;s&amp;nbsp;model.&lt;/p&gt;
&lt;p&gt;The short version: &lt;strong&gt;Jev most likely keeps the reading half of an &lt;span class="caps"&gt;LLM&lt;/span&gt; and throws away the writing half.&lt;/strong&gt; An &lt;span class="caps"&gt;LLM&lt;/span&gt; processes your whole prompt in one parallel sweep, the &lt;strong&gt;prefill&lt;/strong&gt;. Then it spends most of its wall-clock time writing the answer one token at a time, the &lt;strong&gt;decode loop&lt;/strong&gt;. Jev stops after the sweep and reads the answer straight out of the model&amp;#8217;s internal&amp;nbsp;state.&lt;/p&gt;
&lt;pre class="mermaid"&gt;
flowchart LR
    classDef state fill:#1e66f5,color:#ffffff,stroke:#1e4ed8,stroke-width:2px;
    classDef branch fill:#8839ef,color:#ffffff,stroke:#6c2bd9,stroke-width:2px;
    classDef out fill:#40a02b,color:#ffffff,stroke:#2f7a20,stroke-width:2px;
    classDef skip fill:#d20f39,color:#ffffff,stroke:#a30826,stroke-width:2px;
    S[State tokens]:::state --&gt; PF[Prefill once&lt;br/&gt;pretrained transformer]:::state
    PF --&gt; KV[(Shared KV cache)]:::state
    PF -. skipped .-&gt; DEC[LLM decode loop&lt;br/&gt;one token at a time]:::skip
    subgraph BATCH[One batch: each branch sees the state, never the other branches]
        direction TB
        Q1[Question 1 + option list]:::branch --&gt; R1[Readout at the&lt;br/&gt;decision position]:::branch
        Q2[Question 2 + option list]:::branch --&gt; R2[Readout at the&lt;br/&gt;decision position]:::branch
        QN[Question N + option list]:::branch --&gt; RN[Readout at the&lt;br/&gt;decision position]:::branch
    end
    KV --&gt; Q1
    KV --&gt; Q2
    KV --&gt; QN
    R1 --&gt; SM[softmax: one probability&lt;br/&gt;per option slot]:::out
    R2 --&gt; SM
    RN --&gt; SM
    SM --&gt; J[Plain code: confidence&lt;br/&gt;arithmetic + JSON]:::out
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;What TypeSafe states.&lt;/strong&gt; Jev &amp;#8220;outputs all probabilities in parallel instead of autoregressively generating by token&amp;#8221;. Its &lt;span class="caps"&gt;AI&lt;/span&gt; primer draws &lt;span class="caps"&gt;RLCD&lt;/span&gt; as a post-training path that starts from a pretrained language model, and Almeida told the Latent Space podcast that even with a billion dollars he &amp;#8220;wouldn&amp;#8217;t pre-train&amp;#8221;. The docs say Jev &amp;#8220;ingests the state once and evaluates every question against it in parallel&amp;#8221;, with a budget of 64k tokens per request and 32k for the state plus the longest single&amp;nbsp;question.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What outsiders&amp;nbsp;measured.&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Extra questions are almost free, up to a point.&lt;/strong&gt; Server time stayed flat up to about 100 questions, and 1,500 questions came back in a median of 610&amp;nbsp;ms.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Questions cannot see each other.&lt;/strong&gt; A secret code placed in one question was invisible to a sibling question (probability 0.00). Moved into the state, the same probe found it at 0.90 to&amp;nbsp;0.92.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Options are read together.&lt;/strong&gt; Adding an irrelevant fifth option (&amp;#8220;bad weather caused it&amp;#8221;) changed the odds between two existing options in all ten test blocks. Fixed per-option scores behind an unchanged softmax cannot do that. Hume reads it as the options influencing each other, and leaves a list-dependent temperature open as the other&amp;nbsp;explanation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Order matters.&lt;/strong&gt; Reversing an option list moved one probability from about 0.84-0.89 to 0.93-0.96. Test permutations before you fix a&amp;nbsp;threshold.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;output_tokens&lt;/code&gt; is a billing number.&lt;/strong&gt; It is computed from the serialized response after inference, and latency does not follow&amp;nbsp;it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The tokenizer is not a public one.&lt;/strong&gt; It matched none of 192 public tokenizers; Qwen came closest, agreeing on 348 of 415&amp;nbsp;probes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Calibration looks good on average.&lt;/strong&gt; On a 1,200-item &lt;span class="caps"&gt;MMLU&lt;/span&gt; sample, the expected calibration error was 0.031. Most of that sample (990 items) sat above 0.9 confidence, and two sparse middle bins (28 and 6 items) were off by 13 and 30 points. Laya&amp;#8217;s &lt;span class="caps"&gt;README&lt;/span&gt; quotes third-party figures for Jev of 0.144 on its typed-decisions set and 0.246 in a comparison table that does not name the dataset. Calibration depends on the data you measure it&amp;nbsp;on.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="mermaid"&gt;
%%{init: {"themeVariables": {"xyChart": {"plotColorPalette": "#1e66f5"}}}}%%
xychart-beta
    title "Jev server time vs questions per request (median ms, short state)"
    x-axis "questions per request" ["1", "25", "50", "100", "175", "250", "375", "500", "625", "750", "875", "1000", "1125", "1250", "1375", "1500"]
    y-axis "median server time (ms)" 0 --&gt; 700
    line [86.5, 72, 81, 82, 99.5, 132, 162, 181, 213, 245.5, 315.5, 453.5, 358.5, 483, 395.5, 610]
&lt;/pre&gt;

&lt;p&gt;Data from Archer Hume&amp;#8217;s latency sweep: eight requests per size, one at a time, timed with the &lt;span class="caps"&gt;API&lt;/span&gt;&amp;#8217;s upstream service header. The x-axis is not to scale. The zigzag above 875 questions is probably load noise: the service was shared with other users, and the source does not explain&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The likely reconstruction.&lt;/strong&gt; Put those facts together and a plausible design falls&amp;nbsp;out:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A pretrained causal transformer (Hume bets on a sparse mixture-of-experts) runs the prefill on the state once and keeps its &lt;strong&gt;&lt;span class="caps"&gt;KV&lt;/span&gt; cache&lt;/strong&gt;, the stored keys and values that later tokens attend&amp;nbsp;to.&lt;/li&gt;
&lt;li&gt;Each question (instructions, the option list, and a decision position) runs as its own branch. It attends to the shared state but not to other branches, the same shared-prefix trick that &lt;a href="https://arxiv.org/abs/2402.05099"&gt;Hydragen&lt;/a&gt; makes fast. The documented limits fit this shape: 32k tokens per branch, 64k per request, with the state counted&amp;nbsp;once.&lt;/li&gt;
&lt;li&gt;At the decision position, a small &lt;strong&gt;readout&lt;/strong&gt; turns the hidden vector into one number per option slot, and a softmax turns those numbers into probabilities. The 255-option cap is 2^8 - 1. A Noul needs one number and a sigmoid. A Score is a distribution over levels, reported as its probability-weighted&amp;nbsp;average.&lt;/li&gt;
&lt;li&gt;Ordinary code writes the &lt;span class="caps"&gt;JSON&lt;/span&gt;. There is no decode loop, so there are no generated tokens to pay&amp;nbsp;for.&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;RLCD&lt;/span&gt; trains the backbone and the readout against outcomes, probably with a &lt;strong&gt;proper scoring rule&lt;/strong&gt; such as log loss, which rewards honest probabilities over confident&amp;nbsp;ones.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Confidence is not a second model either. TypeSafe&amp;#8217;s own adapter computes Choice confidence&amp;nbsp;as &lt;code&gt;(p_max - 1/K) / (1 - 1/K)&lt;/code&gt;: how far the top answer sits above a uniform guess&amp;nbsp;over &lt;code&gt;K&lt;/code&gt; options. Check it on the docs&amp;#8217; quick-start example: 0.85 for the top of three options gives 0.775, and the &lt;span class="caps"&gt;API&lt;/span&gt; returns&amp;nbsp;0.78.&lt;/p&gt;
&lt;h3 id="an-open-blueprint-laya"&gt;An open blueprint:&amp;nbsp;Laya&lt;/h3&gt;
&lt;p&gt;Jev was not the first model to answer with a probability instead of text. In March 2025, Nandakishor M published &lt;a href="https://arxiv.org/abs/2503.23303"&gt;SalesRLAgent&lt;/a&gt;, a reinforcement-learning model that reads a sales conversation and returns the probability that the sale converts. It works on frozen 3,072-dimension Azure OpenAI embeddings, trains on synthetic conversations generated with &lt;span class="caps"&gt;GPT&lt;/span&gt;-4o, and answers in 85 ms against 3,450 ms for &lt;span class="caps"&gt;GPT&lt;/span&gt;-4. A &lt;a href="https://arxiv.org/abs/2510.01237"&gt;September 2025 follow-up&lt;/a&gt; used confidence signals to route &lt;span class="caps"&gt;LLM&lt;/span&gt; queries before generation. That is Jev&amp;#8217;s core idea (a trained model that returns a number, reinforcement learning, synthetic data), but for one fixed question instead of any typed question you&amp;nbsp;write.&lt;/p&gt;
&lt;p&gt;Three days after Jev launched, the same author released &lt;strong&gt;&lt;a href="https://laya.convaiinnovations.com/"&gt;Laya&lt;/a&gt;&lt;/strong&gt;, an open model (Apache 2.0) with Jev&amp;#8217;s interface: Choice, Score, and Noul questions over any state. His Hacker News post, &amp;#8220;I built non-autoregressive decision models with &lt;span class="caps"&gt;RL&lt;/span&gt; a year ago&amp;#8221;, reached 1,360 points and became the place where the argument about who did it first played&amp;nbsp;out.&lt;/p&gt;
&lt;p&gt;Laya does not tell us how Jev works. What it does give us is one complete, working design for the same interface, in code short enough to read in an afternoon (&lt;a href="https://github.com/NandhaKishorM/laya/blob/9d955671415fc19f069b9cc998928075c1f255ec/laya/common.py"&gt;&lt;code&gt;laya/common.py&lt;/code&gt;&lt;/a&gt;):&lt;/p&gt;
&lt;pre class="mermaid"&gt;
flowchart LR
    classDef input fill:#1e66f5,color:#ffffff,stroke:#1e4ed8,stroke-width:2px;
    classDef model fill:#8839ef,color:#ffffff,stroke:#6c2bd9,stroke-width:2px;
    classDef out fill:#40a02b,color:#ffffff,stroke:#2f7a20,stroke-width:2px;
    classDef train fill:#df8e1d,color:#ffffff,stroke:#b8741a,stroke-width:2px;
    SEQ["One sequence per question&lt;br/&gt;[CLS] type + instructions [SEP]&lt;br/&gt;[MASK] opt 1 [MASK] opt 2 ... [SEP]&lt;br/&gt;state [SEP]"]:::input --&gt; ENC[Bidirectional encoder&lt;br/&gt;ModernBERT-large, 421M]:::model
    ENC --&gt; TE[+ question-type&lt;br/&gt;embedding]:::model
    TE --&gt; HEAD[2 extra&lt;br/&gt;transformer layers]:::model
    HEAD --&gt; G[Hidden state at each&lt;br/&gt;option's MASK marker]:::model
    G --&gt; SC[Small MLP:&lt;br/&gt;one logit per option]:::model
    SC --&gt; SM[softmax with a&lt;br/&gt;per-type temperature]:::out
    RW[Training reward: proper scoring rules&lt;br/&gt;log + spherical score,&lt;br/&gt;+ ranked probability score for Score]:::train -. scores these probabilities .-&gt; SM
&lt;/pre&gt;

&lt;p&gt;Three details are worth&amp;nbsp;stealing:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Options are tokens in the same sequence as the state.&lt;/strong&gt; Each option starts with a marker token, the model reads everything at once, and the answer for an option is read from its marker position. In Laya, this design is why options can influence each other. For Jev, it stays a guess: it is one of the two readouts Hume listed as&amp;nbsp;candidates.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The state is encoded again for every question.&lt;/strong&gt; In a bidirectional encoder the state&amp;#8217;s tokens also attend to the question, so there is no question-free prefix to cache. That is the price of this design. A causal backbone with a shared state cache, as in the reconstruction above, would avoid it. That would be consistent with Jev&amp;#8217;s flat latency up to about 100 questions, but it is not proof: Hume notes that his tests cannot tell a causal model from a bidirectional&amp;nbsp;one.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The reward is a proper scoring rule.&lt;/strong&gt; Log score plus spherical score, and a ranked probability score for ordered Score questions. It is a concrete example of what &amp;#8220;&lt;span class="caps"&gt;RLCD&lt;/span&gt;&amp;#8221; can&amp;nbsp;mean.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Laya&amp;#8217;s own numbers are self-reported by a competitor, so read them as such. They still make the most useful point in this whole story. On a set of 2,000 typed decisions across four workflows, zero-shot Laya scores 0.362: barely above random guessing (0.318) and below always picking the most common answer (0.461). Jev scores 0.727. Fine-tuned on that set&amp;#8217;s training split, Laya reaches 0.766. On Banking77, Laya scores 0.425 on 77 labels against 0.870 for Jev on 72 of them, and its &lt;span class="caps"&gt;README&lt;/span&gt; blames the shared 192 to 256-token budget for all&amp;nbsp;options.&lt;/p&gt;
&lt;p&gt;The even cheaper version of the trick needs no new model at all: put numbered options in a prompt to any open &lt;span class="caps"&gt;LLM&lt;/span&gt;, run one forward pass, read the logits of the option-label tokens, and softmax them. &lt;a href="https://sgnt.ai/p/jev/"&gt;Several open clones&lt;/a&gt; did exactly that within days of the launch. The early side-by-side tests collected there, most of them from one clone, show the clones trailing Jev by a little on easy yes/no sets and by a lot on harder multiple-choice&amp;nbsp;ones.&lt;/p&gt;
&lt;p&gt;Put Laya and the clones together and the lesson is clear. The interface and the single-pass readout are cheap: a 421M encoder and about four hours of fine-tuning on free Kaggle GPUs get you there. Zero-shot judgment on questions nobody trained you for is expensive. You pay for it either with a big pretrained backbone, which is what Jev appears to do, or with fine-tuning data from your own domain, which is what Laya asks of&amp;nbsp;you.&lt;/p&gt;
&lt;h2 id="calibration-is-the-product"&gt;Calibration is the&amp;nbsp;product&lt;/h2&gt;
&lt;p&gt;The training method is &lt;strong&gt;&lt;span class="caps"&gt;RLCD&lt;/span&gt;&lt;/strong&gt;, reinforcement learning for calibrated decisions. Set it next to the two methods you already know. &lt;span class="caps"&gt;RLHF&lt;/span&gt; trains a model to produce the text people prefer, which made chatbots. &lt;span class="caps"&gt;RLVR&lt;/span&gt; trains on tasks with checkable answers, which made reasoning models good at math and slow. &lt;span class="caps"&gt;RLCD&lt;/span&gt; trains the probabilities themselves: across many answers the model rates at 0.8, about 80% should turn out&amp;nbsp;right.&lt;/p&gt;
&lt;p&gt;That sounds academic until you try to automate something. The launch post puts it bluntly: &amp;#8220;If a model can do a task 95% of the time but doesn&amp;#8217;t say when it&amp;#8217;s in the 5%, it can&amp;#8217;t automate that task.&amp;#8221; A calibrated probability gives your code a second axis to branch on. The docs suggest a pattern like this one, where the bar to act rises with the cost of being&amp;nbsp;wrong:&lt;/p&gt;
&lt;pre class="mermaid"&gt;
flowchart LR
    classDef stop fill:#d20f39,color:#ffffff,stroke:#a30826,stroke-width:2px;
    classDef go fill:#40a02b,color:#ffffff,stroke:#2f7a20,stroke-width:2px;
    A[Choice answer&lt;br/&gt;+ confidence] --&gt; B{confidence&lt;br/&gt;below 0.5?}
    B -- yes --&gt; H[Route to a human]:::stop
    B -- no --&gt; C{Which action?}
    C -- check balance&lt;br/&gt;low stakes --&gt; S[Show balance]:::go
    C -- approve transfer&lt;br/&gt;high stakes --&gt; D{confidence&lt;br/&gt;above 0.9?}
    D -- yes --&gt; E[Confirm, then execute]:::go
    D -- no --&gt; F[Ask the user to confirm]:::stop
&lt;/pre&gt;

&lt;p&gt;In &lt;a href="https://alexsavio.github.io/first-principles-llm-agents"&gt;First Principles: &lt;span class="caps"&gt;LLM&lt;/span&gt; Agents&lt;/a&gt; I argued that probabilistic output cannot be trusted and must be verified. Calibration does not change that. It hands you a number to verify against, and a threshold is a policy you can review, test, and change in one&amp;nbsp;line.&lt;/p&gt;
&lt;p&gt;Almeida&amp;#8217;s framing for why chat-trained models are the wrong tool here comes from his essay &amp;#8220;The Bitterest Lesson&amp;#8221;: &lt;strong&gt;doing the right task &amp;gt; data &amp;gt; compute &amp;gt; algorithms&lt;/strong&gt;. He learned it on InstructGPT, where &lt;span class="caps"&gt;GPT&lt;/span&gt;-2-sized models, over 100x smaller than &lt;span class="caps"&gt;GPT&lt;/span&gt;-3, beat &lt;span class="caps"&gt;GPT&lt;/span&gt;-3 because they were trained on what people actually wanted. &lt;span class="caps"&gt;RLHF&lt;/span&gt; was the right task for chat. His bet is that it is the wrong task for&amp;nbsp;automation.&lt;/p&gt;
&lt;h2 id="the-receipts-and-the-fine-print"&gt;The receipts, and the fine&amp;nbsp;print&lt;/h2&gt;
&lt;p&gt;TypeSafe built four business workflows (security alert triage, agent trace review, invoice processing, customer service) and ran every model through each one. The overall averages, from the &lt;a href="https://evals.typesafe.ai/"&gt;evals site&lt;/a&gt;:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model (vendor)&lt;/th&gt;
&lt;th&gt;Mode&lt;/th&gt;
&lt;th&gt;Accuracy&lt;/th&gt;
&lt;th&gt;Cost per case&lt;/th&gt;
&lt;th&gt;Time per case&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Jev (TypeSafe)&lt;/td&gt;
&lt;td&gt;workflow&lt;/td&gt;
&lt;td&gt;67.8%&lt;/td&gt;
&lt;td&gt;$0.0004&lt;/td&gt;
&lt;td&gt;0.4 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;luna (OpenAI)&lt;/td&gt;
&lt;td&gt;workflow&lt;/td&gt;
&lt;td&gt;66.8%&lt;/td&gt;
&lt;td&gt;$0.0033&lt;/td&gt;
&lt;td&gt;12.9 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;terra (OpenAI)&lt;/td&gt;
&lt;td&gt;workflow&lt;/td&gt;
&lt;td&gt;67.9%&lt;/td&gt;
&lt;td&gt;$0.0304&lt;/td&gt;
&lt;td&gt;10.1 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;sol (OpenAI)&lt;/td&gt;
&lt;td&gt;workflow&lt;/td&gt;
&lt;td&gt;74.1%&lt;/td&gt;
&lt;td&gt;$0.0836&lt;/td&gt;
&lt;td&gt;23.3 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Opus 5 (Anthropic)&lt;/td&gt;
&lt;td&gt;workflow&lt;/td&gt;
&lt;td&gt;73.1%&lt;/td&gt;
&lt;td&gt;$0.1761&lt;/td&gt;
&lt;td&gt;37.8 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Opus 5 (Anthropic)&lt;/td&gt;
&lt;td&gt;prompt&lt;/td&gt;
&lt;td&gt;64.8%&lt;/td&gt;
&lt;td&gt;$0.3417&lt;/td&gt;
&lt;td&gt;70.5 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Haiku 4.5 (Anthropic)&lt;/td&gt;
&lt;td&gt;workflow&lt;/td&gt;
&lt;td&gt;53.6%&lt;/td&gt;
&lt;td&gt;$0.0195&lt;/td&gt;
&lt;td&gt;12.5 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Haiku 4.5 (Anthropic)&lt;/td&gt;
&lt;td&gt;prompt&lt;/td&gt;
&lt;td&gt;18.1%&lt;/td&gt;
&lt;td&gt;$0.0363&lt;/td&gt;
&lt;td&gt;21.2 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Read it carefully. Jev is not the most accurate model on the chart: sol and Opus 5 beat it by 6.3 and 5.3 points. What Jev does is match &lt;span class="caps"&gt;GPT&lt;/span&gt;-5.6 Terra&amp;#8217;s accuracy for roughly 75x less money and 25x less time per case. It owns the cheap end of the frontier, not the top of&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;Now the fine print, most of which TypeSafe discloses&amp;nbsp;itself:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No ground truth.&lt;/strong&gt; Reference labels are the average of &lt;span class="caps"&gt;GPT&lt;/span&gt;-6 Astra&amp;#8217;s and Fable 5.1&amp;#8217;s answers. Accuracy here means &amp;#8220;agrees with the two biggest&amp;nbsp;models&amp;#8221;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Home-grown tasks.&lt;/strong&gt; TypeSafe&amp;#8217;s own team wrote the four workflows and admits &amp;#8220;some bias could&amp;nbsp;exist&amp;#8221;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Self-reported multipliers.&lt;/strong&gt; The 193.6x and 444.6x figures come from these workflows, and TypeSafe expects them to be &amp;#8220;on the higher end of real world&amp;nbsp;gains&amp;#8221;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A 0% error rate by construction.&lt;/strong&gt; Jev&amp;#8217;s 0% structured-output and tool-call error rate is a guarantee of the output format, not a measurement. The &lt;span class="caps"&gt;LLM&lt;/span&gt; rates next to it (up to 45.5% for Haiku 4.5 structured outputs) come from OpenRouter traffic, which TypeSafe says is&amp;nbsp;biased.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Closed box.&lt;/strong&gt; No public benchmarks by policy, no architecture paper, no&amp;nbsp;weights.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Early outside reports lean positive but not uniformly. TechCrunch reported that a Vercel engineer replaced OpenAI&amp;#8217;s Luna 5.6 command-safety classifier with Jev and got results 5 to 18 times faster, with better accuracy. Bryo &lt;span class="caps"&gt;AI&lt;/span&gt;&amp;#8217;s &lt;span class="caps"&gt;CTO&lt;/span&gt; found Gemini slightly more accurate for classifying business emails, but 10 to 20 times more&amp;nbsp;expensive.&lt;/p&gt;
&lt;h2 id="the-surprising-part-structure-beats-model-size"&gt;The surprising part: structure beats model&amp;nbsp;size&lt;/h2&gt;
&lt;p&gt;This is the finding I would keep even if Jev disappeared tomorrow. Every &lt;span class="caps"&gt;LLM&lt;/span&gt; in the evals ran each task twice: once as a &lt;strong&gt;workflow&lt;/strong&gt; (small typed questions, with code making the final call) and once as a &lt;strong&gt;prompt&lt;/strong&gt; (the whole policy in one prompt, reasoned through in chain-of-thought). Averaged over the four workflows, every single model was more accurate, cheaper, and faster as a&amp;nbsp;workflow.&lt;/p&gt;
&lt;p&gt;The gaps are not small. Haiku 4.5 goes from 18.1% as a prompt to 53.6% as a workflow. Opus 5, one of the strongest models on the chart, scores 64.8% when handed the prompt, below Jev running the workflow at 67.8%, at roughly 850x the cost per&amp;nbsp;case.&lt;/p&gt;
&lt;p&gt;One honest caveat: the reference labels come from running the workflow&amp;#8217;s questions through Astra and Fable, so the workflow mode plays at home. A prompt that reads an ambiguous policy differently gets scored as wrong. The rule is also an average. Per task, 5 of the 96 workflow-versus-prompt comparisons go the other way: &lt;span class="caps"&gt;DS&lt;/span&gt; v4 flash (DeepSeek) and &lt;span class="caps"&gt;DS&lt;/span&gt; v4 pro each scored higher as a prompt on one task, and Opus 5, sol, and Haiku 4.5 each ran faster as a prompt on one task. Even so, the direction matches what I have seen building agents. As I wrote in &lt;a href="https://alexsavio.github.io/so-you-want-to-build-an-llm-agent"&gt;So You Want To Build An &lt;span class="caps"&gt;LLM&lt;/span&gt; Agent&lt;/a&gt;, generation is the easy part and verification is the part that breaks. It is also plain software design. In &lt;a href="https://alexsavio.github.io/first-principles-software-design"&gt;First Principles: Software Design&lt;/a&gt; I described design as choosing how to decompose one transformation into parts small enough to hold in your head. A typed question is one of those parts. Small typed questions are verification-shaped. Each one can be logged, tested against examples, and thresholded on its&amp;nbsp;own.&lt;/p&gt;
&lt;h2 id="where-it-breaks"&gt;Where it&amp;nbsp;breaks&lt;/h2&gt;
&lt;p&gt;To TypeSafe&amp;#8217;s credit, its docs publish a list of nine known failure modes for Jev 1.13. The ones that matter most in&amp;nbsp;practice:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Math, counting, and dates.&lt;/strong&gt; Jev reads numbers and dates as text. Keep arithmetic and date comparisons in code and ask Jev only for the&amp;nbsp;judgment.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Big, noisy state.&lt;/strong&gt; Accuracy falls as the state fills with irrelevant detail. Filter&amp;nbsp;first.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inputs it cannot read.&lt;/strong&gt; Confidence cannot warn you when a model cannot read the input. Laya&amp;#8217;s 51-language test shows it best: its English checkpoint scored 0.000 accuracy on Khmer at 0.952 mean confidence. Jev&amp;#8217;s docs say English is its primary training language and that other languages &amp;#8220;are handled but not equally well&amp;#8221;. Test your own languages before you trust a&amp;nbsp;threshold.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Adversarial content.&lt;/strong&gt; Text in the state that argues for its own classification &amp;#8220;can move the answer&amp;#8221;. Test prompt injection&amp;nbsp;yourself.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No structural guarantees.&lt;/strong&gt; Ask &amp;#8220;is the customer asking for a refund?&amp;#8221; as a Noul and you get 0.22. Ask it as a yes/no Choice on the same ticket and &amp;#8220;yes&amp;#8221; gets 0.01. Do not assume identities between separate questions&amp;nbsp;hold.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And &amp;#8220;can&amp;#8217;t hallucinate&amp;#8221; means it cannot invent a value outside your schema. It can still pick the wrong value, confidently. Almeida agreed on &lt;span class="caps"&gt;HN&lt;/span&gt;: &amp;#8220;because these models are probabilistic, it&amp;#8217;s also possible to be confidently wrong&amp;#8221;. A commenter there summed Jev up as &amp;#8220;basically a zero-shot classifier that can accept raw text&amp;#8221;. I think that is a fair description, and it is not an insult. A zero-shot classifier with frontier-level judgment, calibrated probabilities, and a price of $42 per billion input tokens is a new building block, whatever you call&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;Where I would reach for it&amp;nbsp;first:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Guardrails in agent loops.&lt;/strong&gt; Score every tool call or agent trace before it runs. At these prices, you can check every step instead of&amp;nbsp;sampling.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Routing and triage.&lt;/strong&gt; Tickets to teams, alerts to close, queue, or act, requests to the right&amp;nbsp;model.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Classification over large datasets.&lt;/strong&gt; Map millions of records into&amp;nbsp;features.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Where I would not: anything that needs generated text, exact arithmetic, or multi-hop reasoning. Keep an &lt;span class="caps"&gt;LLM&lt;/span&gt; for&amp;nbsp;those.&lt;/p&gt;
&lt;p&gt;The chat interface made LLMs famous, and it also taught us to bolt a conversation onto places that only needed a decision. Jev&amp;#8217;s bet is that most automation is an if-statement that has to read. Whether or not TypeSafe&amp;#8217;s multipliers survive independent testing, the design move works today with any model: turn the policy into small typed questions, let code own the control flow, and gate every action on a probability you can&amp;nbsp;check.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://typesafe.ai/blog/introducing-system-one-models-and-jev"&gt;Introducing System One Models &lt;span class="amp"&gt;&amp;amp;&lt;/span&gt; Jev&lt;/a&gt;, Diogo Almeida, TypeSafe &lt;span class="caps"&gt;AI&lt;/span&gt;, 2026-09-15, Original&amp;nbsp;source&lt;/li&gt;
&lt;li&gt;&lt;a href="https://evals.typesafe.ai/"&gt;Workflow evals&lt;/a&gt;, TypeSafe &lt;span class="caps"&gt;AI&lt;/span&gt;, the four-workflow evaluation and its&amp;nbsp;data&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.typesafe.ai/"&gt;TypeSafe docs&lt;/a&gt;, primitives, confidence, pricing, and&amp;nbsp;patterns&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.typesafe.ai/model-jaggedness/jev-1.13"&gt;Jev 1.13 jaggedness&lt;/a&gt;, TypeSafe&amp;#8217;s own list of known failure&amp;nbsp;modes&lt;/li&gt;
&lt;li&gt;&lt;a href="https://typesafe.ai/blog/bitterest-lesson"&gt;The Bitterest Lesson&lt;/a&gt;, Diogo Almeida, on why the right task beats data, compute, and&amp;nbsp;algorithms&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2203.02155"&gt;Training language models to follow instructions with human feedback&lt;/a&gt;, the InstructGPT&amp;nbsp;paper&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/typesafe-ai/typesafe-sdk-python"&gt;TypeSafe Python &lt;span class="caps"&gt;SDK&lt;/span&gt;&lt;/a&gt;, source of the code&amp;nbsp;example&lt;/li&gt;
&lt;li&gt;&lt;a href="https://techcrunch.com/2026/09/18/a-new-kind-of-ai-model-from-a-chatgpt-inventor-is-thrilling-developers/"&gt;A new kind of &lt;span class="caps"&gt;AI&lt;/span&gt; model from a ChatGPT inventor is thrilling developers&lt;/a&gt;, Tim Fernholz, TechCrunch, early developer&amp;nbsp;reports&lt;/li&gt;
&lt;li&gt;&lt;a href="https://news.ycombinator.com/item?id=49717558"&gt;Introducing System One Models and Jev&lt;/a&gt;, Hacker News launch thread with replies from the &lt;span class="caps"&gt;CEO&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://archerhume.com/posts/jevs-architecture-unmasked/"&gt;Jev&amp;#8217;s Architecture Unmasked&lt;/a&gt;, Archer Hume, 2026-09-17, black-box probes of the live &lt;span class="caps"&gt;API&lt;/span&gt; and a&amp;nbsp;reconstruction&lt;/li&gt;
&lt;li&gt;&lt;a href="https://sgnt.ai/p/jev/"&gt;You could have built Jev&lt;/a&gt;, sgnt.ai, on the single-token logit trick and the open&amp;nbsp;clones&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2402.05099"&gt;Hydragen: High-Throughput &lt;span class="caps"&gt;LLM&lt;/span&gt; Inference with Shared Prefixes&lt;/a&gt;, shared-prefix&amp;nbsp;attention&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/typesafe-ai/system-one-adapter-python/blob/fb52b1030b7fc1f4f1cf39910afa5da54f9835e3/src/system_one_adapter/_utils/confidence_metrics.py"&gt;confidence_metrics.py&lt;/a&gt;, TypeSafe&amp;#8217;s confidence&amp;nbsp;formulas&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.latent.space/p/jev"&gt;Jev: System One Models for Prod, Not God&lt;/a&gt;, Latent Space podcast with Diogo&amp;nbsp;Almeida&lt;/li&gt;
&lt;li&gt;&lt;a href="https://laya.convaiinnovations.com/"&gt;Laya: 33ms Multilingual System 1 Decision Engine with Calibrated Probabilities&lt;/a&gt;, Nandakishor M, an open model with Jev&amp;#8217;s&amp;nbsp;interface&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/NandhaKishorM/laya"&gt;Laya source code&lt;/a&gt;, Apache 2.0, including the decision head&amp;nbsp;in &lt;code&gt;laya/common.py&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2503.23303"&gt;SalesRLAgent: A Reinforcement Learning Approach for Real-Time Sales Conversion Prediction and Optimization&lt;/a&gt;, Nandakishor M, 2025-03-30, an earlier probability-not-text model for one fixed&amp;nbsp;question&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2510.01237"&gt;Confidence-Aware Routing for Large Language Model Reliability Enhancement&lt;/a&gt;, Nandakishor M,&amp;nbsp;2025-09-23&lt;/li&gt;
&lt;li&gt;&lt;a href="https://news.ycombinator.com/item?id=49765348"&gt;I built non-autoregressive decision models with &lt;span class="caps"&gt;RL&lt;/span&gt; a year ago&lt;/a&gt;, Hacker News thread on Laya and prior&amp;nbsp;work&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-llm-agents"&gt;First Principles: &lt;span class="caps"&gt;LLM&lt;/span&gt; Agents&lt;/a&gt;, Related post on why probabilistic output must be&amp;nbsp;verified&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/so-you-want-to-build-an-llm-agent"&gt;So You Want To Build An &lt;span class="caps"&gt;LLM&lt;/span&gt; Agent&lt;/a&gt;, Related post on why verification, not generation, is the hard&amp;nbsp;part&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-software-observability"&gt;First Principles: Software Observability&lt;/a&gt;, Related post on inferring internal state from external&amp;nbsp;outputs&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-data-engineering"&gt;First Principles: Data Engineering and ETLs&lt;/a&gt;, Related post on explicit contracts between producers and&amp;nbsp;consumers&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-software-design"&gt;First Principles: Software Design&lt;/a&gt;, Related post on design as&amp;nbsp;decomposition&lt;/li&gt;
&lt;/ol&gt;</content><category term="Engineering"/><category term="ai"/><category term="llm"/><category term="agents"/><category term="evaluation"/><category term="architecture"/><category term="structured-output"/></entry><entry><title>Torvalds on AI: It Is a Tool, and 100% of Your Code Was Always Written by Compilers</title><link href="https://alexsavio.github.io/torvalds-ai-is-a-tool-not-a-replacement.html" rel="alternate"/><published>2026-06-09T00:00:00+02:00</published><updated>2026-06-09T00:00:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2026-06-09:/torvalds-ai-is-a-tool-not-a-replacement.html</id><summary type="html">&lt;p&gt;Linus Torvalds says he gets angry hearing &amp;#8220;99% of our code is &lt;span class="caps"&gt;AI&lt;/span&gt;&amp;#8221;, because 100% of it was already written by compilers and nobody brags about that. &lt;span class="caps"&gt;AI&lt;/span&gt; is a productivity tool in the compiler lineage, and its real cost in open source is maintainer burnout from drive-by bug&amp;nbsp;reports.&lt;/p&gt;</summary><content type="html">&lt;h2 id="tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;At the Open Source Summit North America in late May 2026, Linus Torvalds spent part of his keynote pushing back on a now-familiar claim: that &lt;span class="caps"&gt;AI&lt;/span&gt; is about to make programmers redundant. His sharpest line was aimed at the boast you hear everywhere lately, &amp;#8220;99% of our code is written by &lt;span class="caps"&gt;AI&lt;/span&gt;.&amp;#8221; It makes him angry, he said, because 100% of those same people&amp;#8217;s code was already written by &lt;strong&gt;compilers&lt;/strong&gt;, and nobody ever brags about that. His point is not that &lt;span class="caps"&gt;AI&lt;/span&gt; is useless. It is that &lt;span class="caps"&gt;AI&lt;/span&gt; is a tool in a long line of tools, the same lineage as assemblers and compilers, and it does not remove the need to understand the system underneath. He even put rough numbers on it: compilers made programming maybe &lt;strong&gt;1,000 times&lt;/strong&gt; more productive, and &lt;span class="caps"&gt;AI&lt;/span&gt; adds something like &lt;strong&gt;10x&lt;/strong&gt; on&amp;nbsp;top.&lt;/p&gt;
&lt;p&gt;The part most hot takes skip is what comes next. The immediate cost of &lt;span class="caps"&gt;AI&lt;/span&gt; in open source is not bad code. It is &lt;strong&gt;burnout&lt;/strong&gt;, the slow grind of maintainers drowning in &lt;span class="caps"&gt;AI&lt;/span&gt;-generated bug reports that show up without a fix&amp;nbsp;attached.&lt;/p&gt;
&lt;p&gt;A quick boundary before we go further: this post is not about whether LLMs can write code. They obviously can, and they are good at it. It is about the framing Torvalds is attacking, the idea that a percentage of &amp;#8220;&lt;span class="caps"&gt;AI&lt;/span&gt;-written code&amp;#8221; tells you anything useful, and about what the current &lt;span class="caps"&gt;AI&lt;/span&gt; surge is quietly doing to the people who maintain the software you depend&amp;nbsp;on.&lt;/p&gt;
&lt;h2 id="the-compiler-argument"&gt;The compiler&amp;nbsp;argument&lt;/h2&gt;
&lt;p&gt;Torvalds&amp;#8217; best move here is rhetorical, and it works because it is true. Every developer who says &amp;#8220;&lt;span class="caps"&gt;AI&lt;/span&gt; wrote 99% of this&amp;#8221; is already standing on a mountain of code generation they never think to&amp;nbsp;mention.&lt;/p&gt;
&lt;p&gt;Here is the thing. You write source code, and a &lt;strong&gt;compiler&lt;/strong&gt; turns it into machine code. You did not place the registers, pick the instructions, or lay out the stack frames yourself. A tool did all of that, and it has for decades. So by the same logic the &lt;span class="caps"&gt;AI&lt;/span&gt; crowd is using, 100% of your output has been machine-written since long before anyone had heard of an &lt;span class="caps"&gt;LLM&lt;/span&gt;. The percentage was never the interesting&amp;nbsp;number.&lt;/p&gt;
&lt;pre class="mermaid"&gt;
flowchart LR
    classDef big fill:#1e66f5,color:#ffffff,stroke:#1e4ed8,stroke-width:2px;
    classDef small fill:#40a02b,color:#ffffff,stroke:#2f7a20,stroke-width:2px;
    A[Machine code&lt;br/&gt;by hand] --&gt; B[Assembler]
    B --&gt; C[Compiler&lt;br/&gt;~1,000x]:::big
    C --&gt; D[AI assist&lt;br/&gt;~10x]:::small
&lt;/pre&gt;

&lt;p&gt;What this framing does is put &lt;span class="caps"&gt;AI&lt;/span&gt; on a continuum instead of a cliff edge. Every step up the abstraction ladder, machine code to assembly, assembly to Fortran, raised productivity and pushed the human a little further from the metal. And honestly, the jump from hand-written assembly to a compiler was a far bigger deal than the one from a modern &lt;span class="caps"&gt;IDE&lt;/span&gt; to an &lt;span class="caps"&gt;AI&lt;/span&gt; assistant. Put Torvalds&amp;#8217; rough figures next to each other, around 1,000x for compilers against 10x for &lt;span class="caps"&gt;AI&lt;/span&gt;, and the proportion speaks for itself. None of that means &lt;span class="caps"&gt;AI&lt;/span&gt; does not matter. It means we have lost the sense of&amp;nbsp;scale.&lt;/p&gt;
&lt;p&gt;The line worth keeping is this one: &lt;strong&gt;&amp;#8220;&lt;span class="caps"&gt;AI&lt;/span&gt; is changing programming, but it&amp;#8217;s not changing the fun.&amp;#8221;&lt;/strong&gt; The thing that makes programming engaging, getting to know a system well enough to bend it to your will, is exactly the part that does not get automated&amp;nbsp;away.&lt;/p&gt;
&lt;h2 id="the-skill-gap-does-not-close-it-moves"&gt;The skill gap does not close, it&amp;nbsp;moves&lt;/h2&gt;
&lt;p&gt;The tempting story about &lt;span class="caps"&gt;AI&lt;/span&gt; coding tools is that they flatten expertise. Anyone can write a prompt, so everyone is a senior engineer now. Torvalds says the opposite, and I think he is&amp;nbsp;right.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;People who know what they&amp;#8217;re doing to understand systems will be able to prompt tools to write good code. People who don&amp;#8217;t understand the complexity of systems will also prompt systems and write processes that will&amp;nbsp;fail.&amp;#8221;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The prompt is not the skill. The skill is the judgment: knowing whether the code that comes back is correct, safe, and something you will still want to maintain in five years. If you already have that judgment, &lt;span class="caps"&gt;AI&lt;/span&gt; raises your ceiling. If you do not, it mostly raises your confidence, and the output looks just as polished either way. That is the&amp;nbsp;trap.&lt;/p&gt;
&lt;p&gt;This is the same place I landed writing about &lt;a href="https://alexsavio.github.io/first-principles-llm-agents"&gt;&lt;span class="caps"&gt;LLM&lt;/span&gt; agents from first principles&lt;/a&gt;. The model is a stochastic text generator, and everything that actually carries weight (verification, state, control flow) lives in the system you build around it. Strip away the hype and the human&amp;#8217;s job has not really changed: understand the system, check the output, own the&amp;nbsp;result.&lt;/p&gt;
&lt;h2 id="the-part-nobody-tweets-maintainer-burnout"&gt;The part nobody tweets: maintainer&amp;nbsp;burnout&lt;/h2&gt;
&lt;p&gt;This is where Torvalds shifts from a fun rhetorical jab to something genuinely important and weirdly&amp;nbsp;underdiscussed.&lt;/p&gt;
&lt;p&gt;&lt;span class="caps"&gt;AI&lt;/span&gt; turns out to be good at finding bugs in old code. The Linux kernel has more than &lt;strong&gt;35 years&lt;/strong&gt; of history behind it, and &lt;span class="caps"&gt;AI&lt;/span&gt; tools are surfacing real, hidden issues. Sounds like a clean win, until you ask the obvious follow-up: who fixes&amp;nbsp;them?&lt;/p&gt;
&lt;p&gt;The kernel can cope, because it has people. The thousands of one-to-three-person projects sitting underneath your stack cannot. They are now getting a steady trickle of &lt;strong&gt;&lt;span class="caps"&gt;AI&lt;/span&gt;-generated bug reports and pull requests&lt;/strong&gt; with no patch attached, and often no human on the other end who will answer when you ask a follow-up&amp;nbsp;question.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Sometimes &lt;span class="caps"&gt;AI&lt;/span&gt; reports a bug, and when you ask for more information, the person has done that drive-by and doesn&amp;#8217;t even answer your question. So, that&amp;#8217;s the real burnout&amp;nbsp;issue.&amp;#8221;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class="mermaid"&gt;
flowchart TD
    classDef bad fill:#d20f39,color:#ffffff,stroke:#a30826,stroke-width:2px;
    A[AI scans open-source code] --&gt; B[Finds real bug]
    B --&gt; C{Patch included?}
    C --&gt;|No, drive-by| D[Maintainer must triage,&lt;br/&gt;reproduce, fix, answer]
    C --&gt;|No follow-up| E[Maintainer asks for info]
    E --&gt; F[Silence]
    D --&gt; G[Burnout]:::bad
    F --&gt; G
&lt;/pre&gt;

&lt;p&gt;Torvalds is blunt about the incentive driving some of this. Companies spend &amp;#8220;a lot of money and a lot of tokens&amp;#8221; finding bugs in open source so they can put out a press release, and, as he points out, &lt;strong&gt;none of them ship a patch&lt;/strong&gt;. Finding a vulnerability and dumping it on an unpaid maintainer is not a contribution. It is handing your work to someone who did not ask for it and calling it security&amp;nbsp;research.&lt;/p&gt;
&lt;p&gt;And this is not hypothetical. The kernel is actually the resilient case here. In early 2026, &lt;strong&gt;Daniel Stenberg ended curl&amp;#8217;s HackerOne bug bounty&lt;/strong&gt; because his security team was drowning in what he called &amp;#8220;&lt;span class="caps"&gt;AI&lt;/span&gt; slop&amp;#8221;, confident, fabricated vulnerability reports where the hit rate had fallen to something like one in twenty. A seven-person team, offering up to $10,000 for a critical bug, decided it was better to shut the program down than keep triaging machine-generated noise. There is a darker version of this too. The &lt;strong&gt;xz-utils backdoor&lt;/strong&gt; (&lt;span class="caps"&gt;CVE&lt;/span&gt;-2024-3094) was planted by an attacker who spent more than two years quietly befriending a single, overworked maintainer, with sock-puppet accounts piling on exactly the &amp;#8220;why are you so slow&amp;#8221; pressure that wears an exhausted volunteer down. Drive-by &lt;span class="caps"&gt;AI&lt;/span&gt; reports do not just waste time. They burn the attention that is supposed to catch the real&amp;nbsp;attack.&lt;/p&gt;
&lt;p&gt;The kernel&amp;#8217;s own numbers show the strain. In the run-up to the &lt;strong&gt;7.1&lt;/strong&gt; release, maintainers saw more commits during prep than in any release before it, roughly &lt;strong&gt;20%&lt;/strong&gt; more submissions, and it turned out the bump came from &lt;span class="caps"&gt;AI&lt;/span&gt; use rather than a sudden surge of human interest. More throughput sounds great right up until you remember every one of those still needs a human to read&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;When someone asked which &lt;span class="caps"&gt;AI&lt;/span&gt; tools the kernel uses to review incoming patches, Torvalds named one and moved on. The specific tool barely matters. Even with it, humans still have to maintain, review, and vouch for every fix that lands. The bottleneck just moved, from writing the patch to standing behind it, and that part is still stubbornly&amp;nbsp;human.&lt;/p&gt;
&lt;h2 id="where-the-boosters-have-a-point"&gt;Where the boosters have a&amp;nbsp;point&lt;/h2&gt;
&lt;p&gt;In fairness to the other side, and it is worth being fair, &lt;span class="caps"&gt;AI&lt;/span&gt; genuinely does collapse a lot of work. Boilerplate, test scaffolding, glue code, translating between languages, poking around an unfamiliar &lt;span class="caps"&gt;API&lt;/span&gt;: all of it goes faster with a decent model in the loop. Torvalds is not denying any of that. He is the one who put the number at roughly 10x. The argument is not whether &lt;span class="caps"&gt;AI&lt;/span&gt; helps. It is about what the help actually&amp;nbsp;means.&lt;/p&gt;
&lt;p&gt;Where the boosters go wrong is the leap from &amp;#8220;&lt;span class="caps"&gt;AI&lt;/span&gt; writes the easy 80% fast&amp;#8221; to &amp;#8220;&lt;span class="caps"&gt;AI&lt;/span&gt; writes 99% of what matters.&amp;#8221; That last 20%, the part where you need to understand why the system is shaped the way it is, is where the real engineering lives, and it is exactly the part that does not compress. Making the easy work instant does not make the hard work easy. It just leaves you with nothing but the hard&amp;nbsp;work.&lt;/p&gt;
&lt;h2 id="what-this-means-if-you-ship-software"&gt;What this means if you ship&amp;nbsp;software&lt;/h2&gt;
&lt;p&gt;So what does all of this add up to if you actually ship software for a&amp;nbsp;living?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Stop quoting &amp;#8220;% &lt;span class="caps"&gt;AI&lt;/span&gt;-written.&amp;#8221;&lt;/strong&gt; It measures nothing. It never did for compilers and it does not now. The questions that matter are whether the code is understood, tested, and&amp;nbsp;owned.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The bottleneck is review, not generation.&lt;/strong&gt; &lt;span class="caps"&gt;AI&lt;/span&gt; made writing cheap and turned review into the scarce resource, so budget for it. It is the same lesson from &lt;a href="https://alexsavio.github.io/so-you-want-to-build-an-llm-agent"&gt;building real agents&lt;/a&gt;: generation is the easy 80%, and verification is the 20% that breaks in&amp;nbsp;production.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;If you point &lt;span class="caps"&gt;AI&lt;/span&gt; at open source, bring a patch.&lt;/strong&gt; A bug report with no fix and no human to follow up is a tax on a volunteer. If your company harvests vulnerabilities for marketing, you are the burnout Torvalds is&amp;nbsp;describing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Expertise compounds, it does not evaporate.&lt;/strong&gt; &lt;span class="caps"&gt;AI&lt;/span&gt; rewards the people who understand systems and quietly punishes the ones who do not. Invest in the understanding, not the prompt&amp;nbsp;library.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Strip it all back and the &amp;#8220;99% of our code is &lt;span class="caps"&gt;AI&lt;/span&gt;&amp;#8221; boast is really a status claim wearing the costume of a metric. Torvalds&amp;#8217; reply cuts through it cleanly: you have been generating code with tools your whole career, so the only questions worth asking are whether you understand what comes out the other end, and who pays when it breaks. &lt;span class="caps"&gt;AI&lt;/span&gt; changed the tooling. It did not change the job, and it did not change the&amp;nbsp;fun.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://thenewstack.io/torvalds-ai-programming-productivity/"&gt;Why Linux creator Linus Torvalds gets angry hearing &amp;#8220;99% of code is &lt;span class="caps"&gt;AI&lt;/span&gt;&amp;#8221;&lt;/a&gt;, B. Cameron Gain, The New Stack, 2026-05-29, Original&amp;nbsp;source&lt;/li&gt;
&lt;li&gt;&lt;a href="https://events.linuxfoundation.org/open-source-summit-north-america/"&gt;Open Source Summit North America&lt;/a&gt;, where the keynote was&amp;nbsp;delivered&lt;/li&gt;
&lt;li&gt;&lt;a href="https://daniel.haxx.se/blog/2026/01/26/the-end-of-the-curl-bug-bounty/"&gt;The end of the curl bug-bounty&lt;/a&gt;, Daniel Stenberg, on ending curl&amp;#8217;s bounty over &lt;span class="caps"&gt;AI&lt;/span&gt;&amp;nbsp;slop&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/XZ_Utils_backdoor"&gt;&lt;span class="caps"&gt;XZ&lt;/span&gt; Utils backdoor (&lt;span class="caps"&gt;CVE&lt;/span&gt;-2024-3094)&lt;/a&gt;, the single-maintainer social-engineering supply-chain&amp;nbsp;attack&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-llm-agents"&gt;First Principles: &lt;span class="caps"&gt;LLM&lt;/span&gt; Agents&lt;/a&gt;, Related post on what survives when you strip the agent&amp;nbsp;hype&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/so-you-want-to-build-an-llm-agent"&gt;So You Want To Build An &lt;span class="caps"&gt;LLM&lt;/span&gt; Agent&lt;/a&gt;, Related post on why verification, not generation, is the hard&amp;nbsp;part&lt;/li&gt;
&lt;/ol&gt;</content><category term="Engineering"/><category term="ai"/><category term="code-generation"/><category term="open-source"/><category term="llm"/><category term="agents"/><category term="maintainers"/></entry><entry><title>First Principles: LLM Agents (Most of Yours Are Chatbots Wearing a Hat)</title><link href="https://alexsavio.github.io/first-principles-llm-agents.html" rel="alternate"/><published>2026-05-08T12:00:00+02:00</published><updated>2026-05-08T12:00:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2026-05-08:/first-principles-llm-agents.html</id><summary type="html">&lt;p&gt;&lt;span class="caps"&gt;LLM&lt;/span&gt; agent design is buried under framework worship, multi-agent fantasies, and vector-&lt;span class="caps"&gt;DB&lt;/span&gt; orthodoxy. Strip it back to what is provably true and only six things survive. Most of the architecture teams reach for is a chatbot wearing a&amp;nbsp;hat.&lt;/p&gt;</summary><content type="html">&lt;h2 id="tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span class="caps"&gt;LLM&lt;/span&gt; agents are drowning in inherited wisdom: pick a framework, spin up a crew of specialists, plug a vector database in for &amp;#8220;memory&amp;#8221;, watch the demo work, and ship. Strip the topic down to what is actually true about a language model in a loop, and only six irreducible facts survive. Most of the multi-agent, framework-first, &lt;span class="caps"&gt;RAG&lt;/span&gt;-by-default architecture that engineers reach for is overhead, not substance. The uncomfortable conclusion: the first agent worth building is a 30-line ReAct loop with a step budget, not a &amp;#8220;crew&amp;#8221; of personas powered by a graph &lt;span class="caps"&gt;DSL&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;This is the sixth post in my First Principles series, where I take a concept the industry treats as settled and strip it back to what is actually provable. Previous entries: &lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;Software Observability&lt;/a&gt;, &lt;a href="https://alexsavio.github.io/first-principles-software-design.html"&gt;Software Design&lt;/a&gt;, &lt;a href="https://alexsavio.github.io/first-principles-devops.html"&gt;DevOps&lt;/a&gt;, &lt;a href="https://alexsavio.github.io/first-principles-data-engineering.html"&gt;Data Engineering&lt;/a&gt;, and &lt;a href="https://alexsavio.github.io/first-principles-distributed-systems.html"&gt;Distributed Systems&lt;/a&gt;. &lt;span class="caps"&gt;LLM&lt;/span&gt; agents felt like the right next target because few topics have calcified around tooling as fast, with as little benchmark evidence to back it&amp;nbsp;up.&lt;/em&gt;&lt;/p&gt;
&lt;div class="toc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-conventional-view"&gt;The Conventional&amp;nbsp;View&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-people-just-assume"&gt;What People Just&amp;nbsp;Assume&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-actually-survives-scrutiny"&gt;What Actually Survives&amp;nbsp;Scrutiny&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-falls-away"&gt;What Falls&amp;nbsp;Away&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#rebuilt-from-scratch"&gt;Rebuilt From&amp;nbsp;Scratch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-changes-when-you-think-this-way"&gt;What Changes When You Think This&amp;nbsp;Way&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#when-you-actually-need-an-agent"&gt;When You Actually Need an&amp;nbsp;Agent&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-honest-test"&gt;The Honest&amp;nbsp;Test&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#references"&gt;References&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id="the-conventional-view"&gt;The Conventional&amp;nbsp;View&lt;/h2&gt;
&lt;p&gt;Ask a builder how to ship an &lt;span class="caps"&gt;LLM&lt;/span&gt; agent in 2026 and the answer comes out like a Lego instruction sheet. Pick a framework (LangGraph, CrewAI, AutoGen, &lt;span class="caps"&gt;ADK&lt;/span&gt;). Wire a &amp;#8220;crew&amp;#8221; of specialist agents (Researcher, Writer, Critic, Manager). Plug a vector database in for &amp;#8220;long-term memory&amp;#8221;. Wrap it all in an orchestrator. Add &lt;span class="caps"&gt;MCP&lt;/span&gt; servers for the tools you do not want to write yourself. Watch the demo loop produce a paragraph that sounds plausible.&amp;nbsp;Ship.&lt;/p&gt;
&lt;p&gt;The discipline is defined by its frameworks, its acronyms (&lt;span class="caps"&gt;RAG&lt;/span&gt;, &lt;span class="caps"&gt;MCP&lt;/span&gt;, &lt;span class="caps"&gt;A2A&lt;/span&gt;, ReAct, ToT, GoT), and its conference-talk reference architectures. &lt;em&gt;Multi-agent&lt;/em&gt; is &amp;#8220;modern&amp;#8221;. A single ReAct loop is &amp;#8220;naive&amp;#8221;. Without a vector &lt;span class="caps"&gt;DB&lt;/span&gt; you do not have &amp;#8220;memory&amp;#8221;. Without a framework you are &amp;#8220;reinventing the&amp;nbsp;wheel&amp;#8221;.&lt;/p&gt;
&lt;p&gt;This post is not about which framework to pick. It is about whether most of that machinery is doing any work at all, and what an &lt;span class="caps"&gt;LLM&lt;/span&gt; agent looks like when you stop copying the architecture of an investor deck and reason forward from the things that are actually true about a language&amp;nbsp;model.&lt;/p&gt;
&lt;h2 id="what-people-just-assume"&gt;What People Just&amp;nbsp;Assume&lt;/h2&gt;
&lt;p&gt;Before you can tear something down, you have to name the inherited thinking. Here are the beliefs most engineers carry into agent building without ever having checked&amp;nbsp;them.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Assumption&lt;/th&gt;
&lt;th&gt;Where it came from&lt;/th&gt;
&lt;th&gt;Verdict&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;More agents = better outcomes&lt;/td&gt;
&lt;td&gt;AutoGen / Swarm / CrewAI demos&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;RAG&lt;/span&gt; is required for any non-trivial agent&lt;/td&gt;
&lt;td&gt;LangChain tutorials, vector-&lt;span class="caps"&gt;DB&lt;/span&gt; marketing&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;A framework ships you faster&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;YC&lt;/span&gt; pitch decks, conference talks&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Long context windows solve &amp;#8220;memory&amp;#8221;&lt;/td&gt;
&lt;td&gt;Gemini 1M / Claude 200K announcements&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Vector &lt;span class="caps"&gt;DB&lt;/span&gt; = &amp;#8220;memory&amp;#8221;&lt;/td&gt;
&lt;td&gt;Pinecone / Weaviate launch posts&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Reflection and self-critique are optional polish&lt;/td&gt;
&lt;td&gt;&amp;#8220;Agents just work&amp;#8221; hype&lt;/td&gt;
&lt;td&gt;Heuristic (often inverted)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;A frontier model is enough; eval can wait&lt;/td&gt;
&lt;td&gt;Vibes-based shipping&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;Tool calls are reliable&lt;/td&gt;
&lt;td&gt;OpenAI / Anthropic docs read optimistically&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;An autonomous agent should run unattended in production&lt;/td&gt;
&lt;td&gt;Gen-&lt;span class="caps"&gt;AI&lt;/span&gt; investor narratives&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;&amp;#8220;Agentic&amp;#8221; is a meaningful spec&lt;/td&gt;
&lt;td&gt;Twitter / LinkedIn&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The point of that table is not contrarianism. It is compression. Most of what gets repeated as &amp;#8220;agent engineering knowledge&amp;#8221; is a mix of vendor marketing, framework documentation taken as physics, and pattern names imported from research papers without the experimental conditions that made them&amp;nbsp;work.&lt;/p&gt;
&lt;h2 id="what-actually-survives-scrutiny"&gt;What Actually Survives&amp;nbsp;Scrutiny&lt;/h2&gt;
&lt;p&gt;Six things remain once you strip the heuristics and the baggage. These are properties of the underlying technology, not of any specific framework or&amp;nbsp;model.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. A language model produces text from context. That is the entire mechanism.&lt;/strong&gt; Every call is stateless. There is no &amp;#8220;goal&amp;#8221;, no &amp;#8220;memory&amp;#8221;, no &amp;#8220;self&amp;#8221;. The model receives a context window and emits tokens that are likely given that context. Anything that looks like persistent state is plumbing built around that one call. Forget this and you start arguing with the wrong layer of the&amp;nbsp;stack.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Probabilistic output cannot be trusted. It must be verified.&lt;/strong&gt; There is no truth signal inside the distribution. Plausible-looking is the only thing the model optimises for, and &amp;#8220;plausible&amp;#8221; is not the same as &amp;#8220;correct&amp;#8221;. Hallucinated APIs compile cleanly in your head and break on import. If you do not have a verification step, you do not have an agent, you have a confident&amp;nbsp;speaker.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Tokens are the only currency the runtime recognises.&lt;/strong&gt; Context window, latency, and cost are all measured in tokens. Out-of-window content does not exist for the model regardless of how cleverly you stored it. Long prompts are slow, expensive, and degrade quality through &amp;#8220;lost in the middle&amp;#8221; effects. Token budget discipline is not optimisation, it is&amp;nbsp;correctness.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. Tools are the only way to act on the world.&lt;/strong&gt; Without tools, the model can describe an action but cannot perform one. Tools are the boundary between language model and reality. The schema is the contract; the executor is the mechanism. Everything else (planning, reflection, critique) is text shuffled inside the same context&amp;nbsp;window.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5. Loops compose multiplicatively, not additively.&lt;/strong&gt; A loop&amp;nbsp;of &lt;code&gt;n&lt;/code&gt; steps with per-step success&amp;nbsp;probability &lt;code&gt;p&lt;/code&gt; succeeds end-to-end with&amp;nbsp;probability &lt;code&gt;p^n&lt;/code&gt;. Five steps at 90% individual success give you 59% overall. Ten give you 35%. Without verification at each step and a hard step budget, longer chains do not get smarter, they get exponentially less&amp;nbsp;reliable.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6. Untrusted content in the context is an instruction injection vector.&lt;/strong&gt; The model cannot distinguish &amp;#8220;user instructions&amp;#8221; from &amp;#8220;data the user pasted in&amp;#8221; from &amp;#8220;documents the agent retrieved&amp;#8221;. Anything in the prompt is an instruction candidate. Prompt injection is structural, not a bug to patch. This is &lt;span class="caps"&gt;OWASP&lt;/span&gt; &lt;span class="caps"&gt;LLM01&lt;/span&gt; and it is not going away with a smarter&amp;nbsp;model.&lt;/p&gt;
&lt;p&gt;That is the whole bedrock. Six statements. Notice what is &lt;em&gt;not&lt;/em&gt; on the list: multi-agent crews, vector databases, frameworks, &lt;span class="caps"&gt;RAG&lt;/span&gt;, &lt;span class="caps"&gt;MCP&lt;/span&gt;, &amp;#8220;agent memory&amp;#8221;, planning patterns, reflection, ReAct, ToT. None of those are fundamental. They are tools, patterns, or&amp;nbsp;rebrandings.&lt;/p&gt;
&lt;h2 id="what-falls-away"&gt;What Falls&amp;nbsp;Away&lt;/h2&gt;
&lt;p&gt;Once you stop at &amp;#8220;only what is provably true&amp;#8221;, the conventional architecture advice starts looking&amp;nbsp;suspicious.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;More agents = better outcomes.&amp;#8221;&lt;/strong&gt; Multi-agent systems multiply the failure modes from truth #5. A &amp;#8220;Researcher → Writer → Critic&amp;#8221; chain is three loops, not three minds. If a single well-prompted call cannot do the job, three of them dressed in role names usually cannot either; they just cost three times as much and fail in three places. The real reason multi-agent persists is that &lt;em&gt;role personas&lt;/em&gt; read better in demos than &lt;em&gt;steps in a function&lt;/em&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;&lt;span class="caps"&gt;RAG&lt;/span&gt; is required for any non-trivial agent.&amp;#8221;&lt;/strong&gt; &lt;span class="caps"&gt;RAG&lt;/span&gt; is a workaround for the fact that you cannot fit your corpus in the context window and cannot fine-tune cheaply. It is a useful workaround in those cases. It is not a fundamental property of agents. If your knowledge fits in the context window, &lt;span class="caps"&gt;RAG&lt;/span&gt; is overhead. If your problem does not need external knowledge at all, &lt;span class="caps"&gt;RAG&lt;/span&gt; is&amp;nbsp;theatre.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;A framework ships you faster.&amp;#8221;&lt;/strong&gt; A framework hides the mechanism. The mechanism (tool schema, stop reasons, tool-use blocks, tool-result feedback, message accumulation) is exactly what you have to debug when the agent misbehaves. You debug what you do not understand. Frameworks are accelerators &lt;em&gt;after&lt;/em&gt; you know the underlying loop, not&amp;nbsp;before.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Long context windows solve memory.&amp;#8221;&lt;/strong&gt; Throwing 200K tokens at the model on every turn pays token cost as &lt;span class="caps"&gt;RAM&lt;/span&gt; cost, with worse retrieval characteristics than an actual database, plus a &amp;#8220;lost in the middle&amp;#8221; recall curve on top. Context length and memory are different problems. The same context length that &amp;#8220;solves memory&amp;#8221; also burns latency and money on every&amp;nbsp;call.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Vector &lt;span class="caps"&gt;DB&lt;/span&gt; = memory.&amp;#8221;&lt;/strong&gt; A vector database is approximate similarity search over embeddings. That is a useful retrieval primitive. It is not memory in any cognitive sense. Calling it memory is marketing, and treating it as memory leads to architectures where the agent forgets what it just did because the embedding for &amp;#8220;what just happened&amp;#8221; was not similar enough to whatever the next query searched&amp;nbsp;for.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Reflection is optional polish.&amp;#8221;&lt;/strong&gt; Reflection (&amp;#8220;draft, critique, revise&amp;#8221;) routinely buys 20 to 40 percent quality on hard tasks for the price of one extra &lt;span class="caps"&gt;LLM&lt;/span&gt; call. Treating it as a nice-to-have means you are leaving the cheapest, best-evidenced reliability gain on the table. By contrast, multi-agent setups often add no measurable lift over a single agent with&amp;nbsp;reflection.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Eval can wait.&amp;#8221;&lt;/strong&gt; &amp;#8220;Feels good&amp;#8221; is not a contract. Without a golden set and a regression run, every prompt change and every model upgrade is a coin flip. Teams discover this the first time a model provider silently rolls a point release and their agent quietly drops 15 points on the metric nobody was&amp;nbsp;watching.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Autonomous unattended agents.&amp;#8221;&lt;/strong&gt; Truth #5 plus truth #6 makes unattended autonomy in any consequential domain a liability story waiting to happen. Today&amp;#8217;s agents are best modeled as power tools with a kill switch, not&amp;nbsp;employees.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="rebuilt-from-scratch"&gt;Rebuilt From&amp;nbsp;Scratch&lt;/h2&gt;
&lt;p&gt;If you only started from the six truths and never heard of LangGraph, this is what you would&amp;nbsp;build.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default to the smallest possible loop.&lt;/strong&gt; A working ReAct agent is 30 lines: send a message, parse the response, if there is a tool call execute it, append the result, send again, stop on a final answer or a step-budget breach. That is the entire substrate. Build it once by hand before you ever import a&amp;nbsp;framework.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;litellm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;completion&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;json&lt;/span&gt;

&lt;span class="n"&gt;TOOLS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
    &lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"function"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"function"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"calculator"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Evaluate math expression"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"parameters"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"expr"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;}},&lt;/span&gt;
            &lt;span class="s2"&gt;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"expr"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}]&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"__builtins__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{}},&lt;/span&gt; &lt;span class="p"&gt;{}))&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"claude-sonnet-4-6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_steps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;msgs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_steps&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;completion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;msgs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;TOOLS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2048&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;
        &lt;span class="n"&gt;msgs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model_dump&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tool_calls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tool_calls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;function&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;msgs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"tool"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s2"&gt;"tool_call_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="ne"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"step budget exhausted"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;LiteLLM is a thin &lt;span class="caps"&gt;SDK&lt;/span&gt; wrapper, not a framework. It buys vendor neutrality (one &lt;span class="caps"&gt;API&lt;/span&gt;, 100+ providers, automatic fallback chains) without hiding the mechanism. Swap models with a string. Fall back to a local model on outage with one extra argument. Same code, different&amp;nbsp;backends.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Make verification explicit at every step.&lt;/strong&gt; Truth #2 says probabilistic output cannot be trusted; truth #5 says unverified intermediate steps compound multiplicatively. Validate every model output against a schema before acting on it. Pydantic at every boundary. Parse, do not&amp;nbsp;believe.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;pydantic&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ValidationError&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;confidence&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ge&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;le&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model_validate_json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;ValidationError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="ne"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"LLM output invalid: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Hard-cap the loop.&lt;/strong&gt; Step budget is a numerical safety bound that follows directly from truth #5. Without it the agent burns money or runs forever. There is no scenario where unbounded iteration is&amp;nbsp;correct.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Trace every call.&lt;/strong&gt; Input tokens, output tokens, latency, stop reason, tool calls, tool results. Without traces you have a black box. With traces you have a debugger. This is the same observability rule from &lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;First Principles: Software Observability&lt;/a&gt;, specialised for non-deterministic&amp;nbsp;outputs.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Reflection beats fancier patterns.&lt;/strong&gt; &amp;#8220;Generate, critique, revise&amp;#8221; inside a single agent gives you most of the quality lift that multi-agent setups claim, at one or two extra calls instead of N. Add reflection before you add&amp;nbsp;personas.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Treat retrieved content as data, never as instructions.&lt;/strong&gt; Truth #6. Wrap it in delimiters. Verify intent against the original user request, not against the retrieved text. This is &lt;span class="caps"&gt;OWASP&lt;/span&gt; &lt;span class="caps"&gt;LLM01&lt;/span&gt; in plain&amp;nbsp;code.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Pin the model&amp;nbsp;version.&lt;/strong&gt; &lt;code&gt;claude-sonnet-4-6&lt;/code&gt;,&amp;nbsp;not &lt;code&gt;claude-sonnet-latest&lt;/code&gt;. Pin the prompts as files in&amp;nbsp;a &lt;code&gt;prompts/&lt;/code&gt; directory and treat them as code: review, version, diff. A &amp;#8220;latest&amp;#8221; tag in production is a silent regression&amp;nbsp;vector.&lt;/p&gt;
&lt;p&gt;Here is what the loop actually looks like when you draw it. Note where verification has to live, and where untrusted content enters the trust&amp;nbsp;boundary.&lt;/p&gt;
&lt;pre class="mermaid"&gt;
flowchart LR
    classDef trust fill:#1e66f5,color:#ffffff,stroke:#1e4ed8,stroke-width:2px;
    classDef untrust fill:#d20f39,color:#ffffff,stroke:#a30826,stroke-width:2px;
    U[User prompt]:::trust --&gt; C[Context]
    C --&gt; M[LLM call]
    M --&gt; P[Parse + validate]
    P --&gt;|tool call| T[Tool executor]
    P --&gt;|final answer| O[Result]
    T --&gt; R[Tool result]:::untrust
    R --&gt; C
    O --&gt; V[Verification]
    V --&gt;|pass| D[Deliver]
    V --&gt;|fail| C
&lt;/pre&gt;

&lt;p&gt;Five boxes do real work. Two boundaries (untrusted content entering context, output before delivery) are where the entire safety story lives. Most of what frameworks add is decoration around this&amp;nbsp;picture.&lt;/p&gt;
&lt;h2 id="what-changes-when-you-think-this-way"&gt;What Changes When You Think This&amp;nbsp;Way&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The 30-line ReAct loop stops being &amp;#8220;naive&amp;#8221;. It is the &lt;em&gt;correct&lt;/em&gt; substrate.&lt;/strong&gt; Frameworks are evaluated against actual needs, not adopted before the loop&amp;nbsp;exists.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multi-agent becomes a last resort, not a first instinct.&lt;/strong&gt; You reach for it when a single prompt truly exceeds 1000 tokens of conflicting instructions, and only after reflection has been&amp;nbsp;tried.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class="caps"&gt;RAG&lt;/span&gt; becomes a tool, not a default.&lt;/strong&gt; First question: does the knowledge fit in the context window? Second: does the task even need external knowledge? Skip &lt;span class="caps"&gt;RAG&lt;/span&gt; when both answers say&amp;nbsp;so.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Vector DBs stop being called &amp;#8220;memory&amp;#8221;.&lt;/strong&gt; They are similarity search, used where similarity search is the right primitive. State and history live in plain databases, where they&amp;nbsp;belong.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Eventually consistent agent reasoning&amp;#8221; becomes suspect.&lt;/strong&gt; If you cannot say what success looks like, you do not have a goal, you have a wish. Add explicit success criteria and verify against them per&amp;nbsp;iteration.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Eval becomes table stakes.&lt;/strong&gt; Every prompt change ships with a golden-set run. Every model upgrade is gated by an&amp;nbsp;eval.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Single-agent + tools + reflection + traces becomes the boring default.&lt;/strong&gt; That stack outperforms most multi-agent crews in production, at a fraction of the&amp;nbsp;cost.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="when-you-actually-need-an-agent"&gt;When You Actually Need an&amp;nbsp;Agent&lt;/h2&gt;
&lt;p&gt;To be fair to the other side: agentic loops are sometimes the right answer. Here are the only honest&amp;nbsp;triggers.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;The task genuinely needs multi-step decomposition.&lt;/strong&gt; A single prompt cannot do it because intermediate observations change the next step. Code-fix loops, search-and-summarise loops, browser-driven loops&amp;nbsp;qualify.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;You need to call tools at all.&lt;/strong&gt; If the work is pure text-in / text-out, you have a structured prompt, not an agent. Stop adding agentic complexity to a function&amp;nbsp;call.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Side effects are gated by a human or by transactional rollback.&lt;/strong&gt; Either a human approves consequential actions, or every action is idempotent and revertible. If neither holds, you are accumulating&amp;nbsp;risk.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Notice what is &lt;em&gt;not&lt;/em&gt; on the list: &amp;#8220;we want to use AutoGen&amp;#8221;, &amp;#8220;the architecture diagram needs more boxes&amp;#8221;, &amp;#8220;the demo will look more impressive with three personas&amp;#8221;. Those are social reasons in engineering clothes. They produce the same kind of résumé-driven architecture the &lt;a href="https://alexsavio.github.io/first-principles-distributed-systems.html"&gt;Distributed Systems&lt;/a&gt; post took apart, just dressed in a different&amp;nbsp;jacket.&lt;/p&gt;
&lt;h2 id="the-honest-test"&gt;The Honest&amp;nbsp;Test&lt;/h2&gt;
&lt;p&gt;Before your next agent design review, try this exercise. Take your architecture diagram. Cross out every component that is not the &lt;span class="caps"&gt;LLM&lt;/span&gt; call, the tool executor, or the message log. What is left should still answer the question &amp;#8220;how does work get done?&amp;#8221;. If most of the diagram disappeared and the answer is still yes, the rest was decoration. If the answer is no, you have a dependency tree to question, not&amp;nbsp;validate.&lt;/p&gt;
&lt;p&gt;Then run the second test. Implement the same task as a 30-line ReAct loop with one tool, one reflection pass, and a step budget of 8. Compare the output against the multi-agent crew. In most cases the simple version is within 5 percent of the complex one, runs in a third of the time, and costs a fifth as&amp;nbsp;much.&lt;/p&gt;
&lt;p&gt;&lt;span class="caps"&gt;LLM&lt;/span&gt; agents are not a badge of sophistication. They are a stateless function in a loop with verification, a step budget, and a kill switch. The engineers who ship boring single-agent systems with traces, eval suites, and pinned model versions are not behind the curve. They are the ones who read the curve carefully and refused to pay for complexity they could not&amp;nbsp;justify.&lt;/p&gt;
&lt;p&gt;First principles thinking is not about rejecting frameworks. It is about refusing to import a framework before you can write the loop without one. Next time someone says &amp;#8220;we need a multi-agent system&amp;#8221;, ask which of the six truths forces that decision. If they cannot answer, you just found a box to&amp;nbsp;delete.&lt;/p&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2210.03629"&gt;ReAct: Synergizing Reasoning and Acting in Language Models&lt;/a&gt;. Yao et al., 2022. Original ReAct&amp;nbsp;paper.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.anthropic.com/research/building-effective-agents"&gt;Building Effective Agents&lt;/a&gt;. Anthropic, 2024. The single best argument for &amp;#8220;start simple, add complexity only when proven&amp;nbsp;necessary&amp;#8221;.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://owasp.org/www-project-top-10-for-large-language-model-applications/"&gt;&lt;span class="caps"&gt;OWASP&lt;/span&gt; Top 10 for Large Language Model Applications&lt;/a&gt;. &lt;span class="caps"&gt;OWASP&lt;/span&gt;, 2025. &lt;span class="caps"&gt;LLM01&lt;/span&gt; (prompt injection) and &lt;span class="caps"&gt;LLM06&lt;/span&gt; (excessive agency) are the two that bite agent designs&amp;nbsp;hardest.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2307.03172"&gt;Lost in the Middle: How Language Models Use Long Contexts&lt;/a&gt;. Liu et al., 2023. Empirical evidence that long-context retrieval degrades sharply outside the start and end of the&amp;nbsp;window.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2303.11366"&gt;Reflexion: Language Agents with Verbal Reinforcement Learning&lt;/a&gt;. Shinn et al., 2023. Quantifies the lift from&amp;nbsp;self-reflection.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Agentic-Design-Patterns-Hands-Intelligent/dp/3032014018"&gt;Agentic Design Patterns&lt;/a&gt;. Antonio Gulli, 2025. Catalogues the 21 patterns the conventional view treats as&amp;nbsp;orthodoxy.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.litellm.ai/"&gt;LiteLLM Documentation&lt;/a&gt;. The vendor-neutral &lt;span class="caps"&gt;SDK&lt;/span&gt; referenced in the example&amp;nbsp;loop.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://modelcontextprotocol.io/"&gt;Model Context Protocol Specification&lt;/a&gt;. The wire protocol for tool servers when tool count grows past&amp;nbsp;trivial.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;First Principles: Software Observability&lt;/a&gt;. Part 1 of this&amp;nbsp;series.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-software-design.html"&gt;First Principles: Software Design&lt;/a&gt;. Part 2 of this&amp;nbsp;series.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-devops.html"&gt;First Principles: DevOps&lt;/a&gt;. Part 3 of this&amp;nbsp;series.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-data-engineering.html"&gt;First Principles: Data Engineering and ETLs&lt;/a&gt;. Part 4 of this&amp;nbsp;series.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-distributed-systems.html"&gt;First Principles: Distributed Systems (Most of Yours Should Not Exist)&lt;/a&gt;. Part 5 of this&amp;nbsp;series.&lt;/li&gt;
&lt;/ol&gt;</content><category term="Engineering"/><category term="first-principles"/><category term="llm"/><category term="agents"/><category term="ai"/><category term="architecture"/><category term="prompt-engineering"/></entry><entry><title>So You Want To Build An LLM Agent</title><link href="https://alexsavio.github.io/so-you-want-to-build-an-llm-agent.html" rel="alternate"/><published>2026-05-08T00:00:00+02:00</published><updated>2026-05-08T00:00:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2026-05-08:/so-you-want-to-build-an-llm-agent.html</id><summary type="html">&lt;p&gt;Most agent demos are toys: the tweet-thread prototype works, production breaks in week one. A vendor-neutral 30-line ReAct loop, the six failure modes that kill prototypes, and the patterns that actually save you in&amp;nbsp;production.&lt;/p&gt;</summary><content type="html">&lt;h2 id="tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;Most agent demos are toys. The tweet-thread prototype works, production breaks in week one. An &lt;span class="caps"&gt;LLM&lt;/span&gt; agent is a loop: model call, parse, tool, observe, repeat. The hard part is not the loop, it is the six failure modes that kill prototypes (no step budget, no output validation, no retry, no traces, no eval, hallucinated APIs) and the patterns that prevent them. Build the 30-line vendor-neutral version with LiteLLM first, add patterns when production proves the&amp;nbsp;need.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Companion piece, written the same day: &lt;a href="https://alexsavio.github.io/first-principles-llm-agents.html"&gt;First Principles: &lt;span class="caps"&gt;LLM&lt;/span&gt; Agents (Most of Yours Are Chatbots Wearing a Hat)&lt;/a&gt;. That one strips the topic to its irreducible truths. This one is the practical build&amp;nbsp;guide.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="what-an-agent-actually-is"&gt;What An Agent Actually&amp;nbsp;Is&lt;/h2&gt;
&lt;p&gt;Strip the mystique. Agent =&amp;nbsp;loop:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nx"&gt;perceive&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;→&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;reason&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;→&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;act&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;→&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;observe&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;→&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;repeat&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;until&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;goal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;span class="caps"&gt;LLM&lt;/span&gt; call, parse output, run tool, feed result back, &lt;span class="caps"&gt;LLM&lt;/span&gt; call again. That&amp;#8217;s&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;Five things separate an agent from a&amp;nbsp;chatbot:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Tools&lt;/strong&gt;: act on the world, not just&amp;nbsp;talk.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Loop&lt;/strong&gt;: multi-step, not&amp;nbsp;single-shot.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory&lt;/strong&gt;: state across&amp;nbsp;turns.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Goal&lt;/strong&gt;: explicit terminate&amp;nbsp;condition.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Self-correction&lt;/strong&gt;: critique plus&amp;nbsp;retry.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If your &amp;#8220;agent&amp;#8221; lacks any of these, you have a chatbot wearing a&amp;nbsp;hat.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="the-5-minute-version-vendor-neutral"&gt;The 5-Minute Version&amp;nbsp;(Vendor-Neutral)&lt;/h2&gt;
&lt;p&gt;Working ReAct loop using &lt;strong&gt;LiteLLM&lt;/strong&gt;: one &lt;span class="caps"&gt;API&lt;/span&gt;, 100+ providers. Swap models with one&amp;nbsp;string.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;litellm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;litellm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;completion&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;os&lt;/span&gt;

&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"ANTHROPIC_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;span class="c1"&gt;# or OPENAI_API_KEY, GEMINI_API_KEY, MISTRAL_API_KEY, etc.&lt;/span&gt;

&lt;span class="n"&gt;TOOLS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
    &lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"function"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"function"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"calculator"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Evaluate math expression"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"parameters"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"expr"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;}},&lt;/span&gt;
            &lt;span class="s2"&gt;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"expr"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}]&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"__builtins__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{}},&lt;/span&gt; &lt;span class="p"&gt;{}))&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"claude-sonnet-4-6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_steps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;msgs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_steps&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;completion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;msgs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;TOOLS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2048&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;
        &lt;span class="n"&gt;msgs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model_dump&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tool_calls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tool_calls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;function&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;msgs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"tool"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s2"&gt;"tool_call_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="ne"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"step budget exhausted"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Same code, different backends:&lt;/span&gt;
&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"17*23+41"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"claude-sonnet-4-6"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"17*23+41"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gpt-5"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"17*23+41"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gemini-2.5-pro"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"17*23+41"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ollama/llama3.3"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;                     &lt;span class="c1"&gt;# local&lt;/span&gt;
&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"17*23+41"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"together_ai/meta-llama/Llama-3.3-70B-Instruct"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning.&lt;/strong&gt;&amp;nbsp;The &lt;code&gt;eval&lt;/code&gt; in &lt;code&gt;calculator&lt;/code&gt; is a teaching shortcut, not a&amp;nbsp;sandbox. &lt;code&gt;().__class__.__mro__[1].__subclasses__()&lt;/code&gt; escapes it in two lines. For real math tools use &lt;a href="https://pypi.org/project/simpleeval/"&gt;&lt;code&gt;simpleeval&lt;/code&gt;&lt;/a&gt;; for general user code, run it in a separate process or container. Never expose&amp;nbsp;raw &lt;code&gt;eval&lt;/code&gt; to model output in&amp;nbsp;production.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The loop,&amp;nbsp;drawn:&lt;/p&gt;
&lt;pre class="mermaid"&gt;
flowchart LR
    classDef trust fill:#1e66f5,color:#ffffff,stroke:#1e4ed8,stroke-width:2px;
    classDef untrust fill:#d20f39,color:#ffffff,stroke:#a30826,stroke-width:2px;
    U[User prompt]:::trust --&gt; C[Context]
    C --&gt; M[LLM call]
    M --&gt; P[Parse + validate]
    P --&gt;|tool call| T[Tool executor]
    P --&gt;|final answer| O[Result]
    T --&gt; R[Tool result]:::untrust
    R --&gt; C
    O --&gt; V[Verification]
    V --&gt;|pass| D[Deliver]
    V --&gt;|fail| C
&lt;/pre&gt;

&lt;p&gt;Five working boxes. Two trust boundaries: untrusted content entering context (red), output before delivery (verification gate). Everything else is&amp;nbsp;decoration.&lt;/p&gt;
&lt;p&gt;Run it. Works. Looks like&amp;nbsp;magic.&lt;/p&gt;
&lt;p&gt;Now ship&amp;nbsp;it.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="picking-the-llm-backend"&gt;Picking The &lt;span class="caps"&gt;LLM&lt;/span&gt;&amp;nbsp;Backend&lt;/h2&gt;
&lt;p&gt;Three valid approaches. Pick by&amp;nbsp;need.&lt;/p&gt;
&lt;h3 id="litellm-universal-wrapper-default"&gt;LiteLLM, Universal Wrapper&amp;nbsp;(default)&lt;/h3&gt;
&lt;p&gt;100+ providers behind one &lt;span class="caps"&gt;API&lt;/span&gt;. Format conversion automatic. Fallback chains&amp;nbsp;built-in.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;litellm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;completion&lt;/span&gt;

&lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;completion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"claude-sonnet-4-6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"hi"&lt;/span&gt;&lt;span class="p"&gt;}],&lt;/span&gt;
    &lt;span class="n"&gt;fallbacks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"gpt-5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"gemini-2.5-pro"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;  &lt;span class="c1"&gt;# auto-fallback on rate-limit / outage&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Best for: multi-provider hedging, production with outage resilience, A/B testing across models, vendor&amp;nbsp;neutrality.&lt;/p&gt;
&lt;p&gt;Cost: extra dep. Occasional lag on bleeding-edge&amp;nbsp;features.&lt;/p&gt;
&lt;h3 id="openai-sdk-base_url-de-facto-standard"&gt;OpenAI &lt;span class="caps"&gt;SDK&lt;/span&gt;&amp;nbsp;+ &lt;code&gt;base_url&lt;/code&gt;, De-Facto&amp;nbsp;Standard&lt;/h3&gt;
&lt;p&gt;Many providers serve OpenAI-compatible endpoints. Same &lt;span class="caps"&gt;SDK&lt;/span&gt;, swap base &lt;span class="caps"&gt;URL&lt;/span&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;openai&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;

&lt;span class="c1"&gt;# OpenAI native&lt;/span&gt;
&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Groq (fast inference)&lt;/span&gt;
&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.groq.com/openai/v1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Together AI&lt;/span&gt;
&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.together.xyz/v1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# OpenRouter (access ~300 models with one key)&lt;/span&gt;
&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://openrouter.ai/api/v1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Local: Ollama / vLLM / LM Studio&lt;/span&gt;
&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ollama"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"http://localhost:11434/v1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Best for: single-provider deployments, when you want one well-known &lt;span class="caps"&gt;SDK&lt;/span&gt;&amp;nbsp;shape.&lt;/p&gt;
&lt;p&gt;Cost: tool-call format quirks vary by backend; not all providers fully&amp;nbsp;OpenAI-compatible.&lt;/p&gt;
&lt;h3 id="provider-native-sdks-best-fidelity"&gt;Provider-Native SDKs, Best&amp;nbsp;Fidelity&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# OpenAI&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;openai&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;

&lt;span class="c1"&gt;# Google Gemini&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;google&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;genai&lt;/span&gt;

&lt;span class="c1"&gt;# Anthropic&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;anthropic&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Anthropic&lt;/span&gt;

&lt;span class="c1"&gt;# Mistral&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;mistralai&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Mistral&lt;/span&gt;

&lt;span class="c1"&gt;# Local Ollama&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;ollama&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Best for: cutting-edge features (Anthropic prompt caching, OpenAI structured-output strict mode, Gemini 1M context). Features land in native &lt;span class="caps"&gt;SDK&lt;/span&gt;&amp;nbsp;first.&lt;/p&gt;
&lt;p&gt;Cost: N SDKs = N code paths. Vendor lock. Rewriting code on provider&amp;nbsp;switch.&lt;/p&gt;
&lt;h3 id="trade-off-table"&gt;Trade-Off&amp;nbsp;Table&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;LiteLLM&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;One &lt;span class="caps"&gt;API&lt;/span&gt;, 100+ providers, format conversion, fallback chains, cost tracking&lt;/td&gt;
&lt;td&gt;Extra dep, occasional version lag&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;OpenAI &lt;span class="caps"&gt;SDK&lt;/span&gt; + base_url&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;One &lt;span class="caps"&gt;SDK&lt;/span&gt;, native to many providers, well-known shape&lt;/td&gt;
&lt;td&gt;Format quirks per backend; partial &lt;span class="caps"&gt;OAI&lt;/span&gt; compatibility&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Provider-native&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Latest features first, best per-vendor docs&lt;/td&gt;
&lt;td&gt;N SDKs, vendor lock&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;For most production agents: &lt;strong&gt;LiteLLM is the right default&lt;/strong&gt;. Code stays vendor-neutral. Switch winner-of-the-month with a string change. Local fallback to Ollama costs&amp;nbsp;nothing.&lt;/p&gt;
&lt;p&gt;The rest of this post uses LiteLLM. Same patterns work with any&amp;nbsp;backend.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="what-this-costs"&gt;What This&amp;nbsp;Costs&lt;/h2&gt;
&lt;p&gt;Numbers move every quarter; orders of magnitude do not. May 2026 list prices, single-turn ≈ 500 input + 100 output&amp;nbsp;tokens:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Input ($/1M tok)&lt;/th&gt;
&lt;th&gt;Output ($/1M tok)&lt;/th&gt;
&lt;th&gt;Single-turn ≈&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Claude Haiku 4.5&lt;/td&gt;
&lt;td&gt;$1&lt;/td&gt;
&lt;td&gt;$5&lt;/td&gt;
&lt;td&gt;$0.001&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude Sonnet 4.6&lt;/td&gt;
&lt;td&gt;$3&lt;/td&gt;
&lt;td&gt;$15&lt;/td&gt;
&lt;td&gt;$0.003&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude Opus 4.7&lt;/td&gt;
&lt;td&gt;$15&lt;/td&gt;
&lt;td&gt;$75&lt;/td&gt;
&lt;td&gt;$0.015&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span class="caps"&gt;GPT&lt;/span&gt;-5&lt;/td&gt;
&lt;td&gt;$5&lt;/td&gt;
&lt;td&gt;$15&lt;/td&gt;
&lt;td&gt;$0.004&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 2.5 Pro&lt;/td&gt;
&lt;td&gt;$2.50&lt;/td&gt;
&lt;td&gt;$10&lt;/td&gt;
&lt;td&gt;$0.002&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Real agents look different from the single-turn number in two ways that&amp;nbsp;matter.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Context grows step by step; total cost grows quadratically.&lt;/strong&gt; Every iteration appends the prior tool call plus its result, so per-call input&amp;nbsp;grows &lt;code&gt;O(n)&lt;/code&gt;. The agent re-pays for the full prefix on each step, summed&amp;nbsp;across &lt;code&gt;n&lt;/code&gt; steps that&amp;nbsp;is &lt;code&gt;O(n²)&lt;/code&gt; total. Step 10 of a 10-step loop sees the entire history on every&amp;nbsp;call.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Frontier models cost 5x to 50x more than cheap ones.&lt;/strong&gt; A 1k-task batch on Sonnet runs&amp;nbsp;~&lt;span class="math"&gt;\(20; on Haiku ~\)&lt;/span&gt;4; on Opus ~$100. Pick by which step needs which tier, not by which name impressed the&amp;nbsp;team.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Worked example: a 10-step Sonnet 4.6 loop with growing context (avg 2k input by step 10, 200 output) runs roughly $0.10 per task. Run it 10k times a day and that is $1k/day, $30k/month. The math kills products that did not budget for&amp;nbsp;it.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="cut-cost-with-prompt-caching"&gt;Cut Cost With Prompt&amp;nbsp;Caching&lt;/h2&gt;
&lt;p&gt;Most production agents send the same prefix on every call (system prompt + tool definitions + few-shot examples), then a small variable suffix (the user&amp;#8217;s question). Anthropic, OpenAI, and Gemini all support caching that prefix. Cache hits cost roughly 10% of normal input. For a 5k-token prefix at 100 calls per day, that is 90% of input cost&amp;nbsp;gone.&lt;/p&gt;
&lt;p&gt;Anthropic explicit&amp;nbsp;cache:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;anthropic&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Anthropic&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Anthropic&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"claude-sonnet-4-6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;max_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;
        &lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;LONG_SYSTEM_PROMPT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"cache_control"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ephemeral"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;  &lt;span class="c1"&gt;# ~5 min TTL&lt;/span&gt;
    &lt;span class="p"&gt;}],&lt;/span&gt;
    &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;TOOLS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;}],&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;OpenAI auto-caches prefixes ≥ 1024 tokens automatically. LiteLLM passes&amp;nbsp;Anthropic &lt;code&gt;cache_control&lt;/code&gt; through unchanged. Order matters: cache prefix first, variable content last. Putting the question above the system prompt invalidates the cache on every&amp;nbsp;call.&lt;/p&gt;
&lt;p&gt;Single biggest cost lever in production. Currently underused because the docs hide&amp;nbsp;it.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="where-prototypes-die"&gt;Where Prototypes&amp;nbsp;Die&lt;/h2&gt;
&lt;p&gt;Same six failures, every&amp;nbsp;time.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. No step budget.&lt;/strong&gt; Loop runs forever. Burns &lt;span class="caps"&gt;API&lt;/span&gt; budget at 3am. The math nails&amp;nbsp;it: &lt;code&gt;p(success)^n&lt;/code&gt; collapses. Five 90% steps = 59% overall. Cap iterations. Fail&amp;nbsp;fast.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. No output validation.&lt;/strong&gt; &lt;span class="caps"&gt;LLM&lt;/span&gt; returns &amp;#8220;the answer is approximately 391&amp;#8221;. Your code&amp;nbsp;does &lt;code&gt;int(response)&lt;/code&gt;. Crash. Use Pydantic at every boundary. Parse, don&amp;#8217;t validate. Schema as&amp;nbsp;guardrail.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;pydantic&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ValidationError&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;confidence&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ge&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;le&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;completion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model_validate_json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;ValidationError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="ne"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"LLM output invalid: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3. No retry, no rollback.&lt;/strong&gt; Tool times out. Whole run aborts. Partial side effects leak (email half-sent, &lt;span class="caps"&gt;DB&lt;/span&gt; row half-written). Production&amp;nbsp;needs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Classify failures: transient (retry with backoff) vs permanent (escalate) vs catastrophic (rollback plus&amp;nbsp;alert).&lt;/li&gt;
&lt;li&gt;Checkpoint state before risky&amp;nbsp;ops.&lt;/li&gt;
&lt;li&gt;Idempotent tool&amp;nbsp;calls.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;4. No traces.&lt;/strong&gt; Agent fails. You stare at the final error. Useless. Log every &lt;span class="caps"&gt;LLM&lt;/span&gt; call: input tokens, output tokens, latency, stop reason, tool calls. Without traces you are blind. Trajectory log is the&amp;nbsp;debugger.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5. No eval.&lt;/strong&gt; Ship &amp;#8220;feels good&amp;#8221; code. Regress silently next sprint. Build a golden test set. Three eval&amp;nbsp;modes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Outcome-based&lt;/strong&gt;: did the agent achieve the goal? Pass /&amp;nbsp;fail.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Process-based&lt;/strong&gt;: efficient, logical path? Right&amp;nbsp;tools?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class="caps"&gt;LLM&lt;/span&gt;-as-Judge&lt;/strong&gt;: separate model scores 1 to&amp;nbsp;5.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;6. Hallucinated APIs.&lt;/strong&gt; Model confidently&amp;nbsp;imports &lt;code&gt;langchain.agents.create_react_agent_v3&lt;/code&gt;. Doesn&amp;#8217;t exist. Always verify against current docs before depending on a non-trivial &lt;span class="caps"&gt;API&lt;/span&gt;. Pin versions.&amp;nbsp;Never &lt;code&gt;latest&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="pick-a-trace-backend-before-day-two"&gt;Pick A Trace Backend Before Day&amp;nbsp;Two&lt;/h2&gt;
&lt;p&gt;Failure mode #4 (no traces) is the one that compounds fastest. Every &lt;span class="caps"&gt;LLM&lt;/span&gt; call is non-deterministic; without a trace &lt;span class="caps"&gt;UI&lt;/span&gt; you read &lt;span class="caps"&gt;JSONL&lt;/span&gt; by hand at 3am. Pick a backend on day two, not after the first&amp;nbsp;incident.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Stance&lt;/th&gt;
&lt;th&gt;Setup&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Arize Phoenix&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Open-source, OTel-native, runs locally or self-hosted&lt;/td&gt;
&lt;td&gt;&lt;code&gt;pip install arize-phoenix&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Langfuse&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Open-source self-host plus hosted SaaS, prompt management built in&lt;/td&gt;
&lt;td&gt;&lt;code&gt;docker compose up&lt;/code&gt;, then &lt;span class="caps"&gt;SDK&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Helicone&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Hosted proxy, transparent:&amp;nbsp;change &lt;code&gt;base_url&lt;/code&gt; and you have traces&lt;/td&gt;
&lt;td&gt;One env var&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;OpenTelemetry direct&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Vendor-neutral, ship to Jaeger, Tempo, Datadog&lt;/td&gt;
&lt;td&gt;More wiring, no &lt;span class="caps"&gt;LLM&lt;/span&gt;-specific &lt;span class="caps"&gt;UI&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Phoenix is the cheapest start: zero infra, runs in a notebook, OTel under the hood, integrates with LiteLLM out of the&amp;nbsp;box.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;phoenix&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;px&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;phoenix.otel&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;register&lt;/span&gt;

&lt;span class="n"&gt;px&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;launch_app&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;project_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"my-agent"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;auto_instrument&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# Every LiteLLM call now appears at http://localhost:6006&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;For the deeper grounding on what to trace and why (logs, metrics, traces as three pillars; trace IDs in every log line; SLOs over raw error counts), see &lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;First Principles: Software Observability&lt;/a&gt;. &lt;span class="caps"&gt;LLM&lt;/span&gt; agents are not a special observability domain; they just have more state per span and more probabilistic failure modes per request. Same discipline, applied&amp;nbsp;harder.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="the-patterns-that-actually-save-you"&gt;The Patterns That Actually Save&amp;nbsp;You&lt;/h2&gt;
&lt;p&gt;21 patterns in Gulli&amp;#8217;s &lt;em&gt;Agentic Design Patterns&lt;/em&gt;. Group into 4 buckets matching what an agent actually&amp;nbsp;does.&lt;/p&gt;
&lt;h3 id="bucket-1-core-execution-decompose-run"&gt;Bucket 1: Core Execution (decompose +&amp;nbsp;run)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Prompt Chaining&lt;/strong&gt;: output of one step = input of next. Linear &lt;span class="caps"&gt;DAG&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Routing&lt;/strong&gt;: conditional path. &lt;span class="caps"&gt;LLM&lt;/span&gt;-as-router or rule&amp;nbsp;classifier.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parallelization&lt;/strong&gt;: independent sub-tasks concurrent. ThreadPool&amp;nbsp;or &lt;code&gt;asyncio.gather&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Planning&lt;/strong&gt;: high-level goal, numbered sub-tasks. Re-plan on&amp;nbsp;failure.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When task = &amp;#8220;single &lt;span class="caps"&gt;LLM&lt;/span&gt; call too small, full &lt;span class="caps"&gt;DAG&lt;/span&gt; too big&amp;#8221;, these&amp;nbsp;compose.&lt;/p&gt;
&lt;h3 id="bucket-2-external-world-act-retrieve"&gt;Bucket 2: External World (act +&amp;nbsp;retrieve)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Tool Use / Function Calling&lt;/strong&gt;: &lt;span class="caps"&gt;JSON&lt;/span&gt; schema, model emits structured call, you&amp;nbsp;execute.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class="caps"&gt;MCP&lt;/span&gt;&lt;/strong&gt; (Model Context Protocol): wire protocol for tool servers. &lt;span class="caps"&gt;JSON&lt;/span&gt;-&lt;span class="caps"&gt;RPC&lt;/span&gt; over &lt;span class="caps"&gt;STDIO&lt;/span&gt;/&lt;span class="caps"&gt;SSE&lt;/span&gt;. Decouples tool dev from agent dev. When tool count grows past 5, you want&amp;nbsp;this.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class="caps"&gt;RAG&lt;/span&gt;&lt;/strong&gt;: retrieve relevant docs, inject as context, generate. Chunk 200 to 500 tokens, hybrid &lt;span class="caps"&gt;BM25&lt;/span&gt; + vector for production. Mitigates hallucination, extends knowledge past&amp;nbsp;cutoff.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Tools are hands. &lt;span class="caps"&gt;RAG&lt;/span&gt; is senses. Both required for grounded&amp;nbsp;operation.&lt;/p&gt;
&lt;h3 id="bucket-3-state-self-improvement"&gt;Bucket 3: State +&amp;nbsp;Self-Improvement&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Memory Management&lt;/strong&gt;: short-term (conversation buffer) plus long-term (persisted facts). Three sub-types: episodic (past interactions), semantic (facts), procedural&amp;nbsp;(skills).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reflection / Self-Correction&lt;/strong&gt;: generator plus critic. Two flavors: &amp;#8220;check your work&amp;#8221; (same agent reviews self) vs &amp;#8220;internal critic&amp;#8221; (separate critic agent, more&amp;nbsp;rigorous).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Learning / Adaptation&lt;/strong&gt;: agent updates behaviour from feedback. Online learning. Rare in practice; usually fine-tune offline&amp;nbsp;instead.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Goal Setting + Monitoring&lt;/strong&gt;: &lt;span class="caps"&gt;SMART&lt;/span&gt; criteria. Without an explicit done-condition, the agent&amp;nbsp;drifts.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exception Handling + State Rollback&lt;/strong&gt;: transactional state. Checkpoint, try, rollback on&amp;nbsp;error.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Reflection alone often beats fancier patterns. &amp;#8220;Draft, critique, revise&amp;#8221; gives 20 to 40 percent quality lift on hard tasks. Cheap.&amp;nbsp;Proven.&lt;/p&gt;
&lt;h3 id="bucket-4-collaboration"&gt;Bucket 4:&amp;nbsp;Collaboration&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Multi-Agent&lt;/strong&gt;: specialist team (Researcher + Writer + Critic). Modularity, reduced complexity, simulated&amp;nbsp;brainstorming.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class="caps"&gt;A2A&lt;/span&gt;&lt;/strong&gt;&amp;nbsp;(Agent-to-Agent): &lt;code&gt;/.well-known/agent.json&lt;/code&gt; discovery, &lt;span class="caps"&gt;JSON&lt;/span&gt;-&lt;span class="caps"&gt;RPC&lt;/span&gt; &lt;code&gt;sendTask&lt;/code&gt; / &lt;code&gt;sendTaskSubscribe&lt;/code&gt; (streaming). Cross-org&amp;nbsp;standard.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class="caps"&gt;HITL&lt;/span&gt;&lt;/strong&gt; (Human-in-the-Loop): pause for approval at critical junctures. Plan approval, destructive tool confirmation, ambiguity resolution, final output&amp;nbsp;review.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Resource-Aware Optimisation&lt;/strong&gt;: route by complexity. Cheap models for classify, mid-tier for standard agent, frontier for hard reasoning. Pair with budget cap per&amp;nbsp;request.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Guardrails&lt;/strong&gt;: 5 layers, input validation plus output filtering plus tool restrictions plus behavioural constraints plus&amp;nbsp;checkpoint/rollback.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Multi-agent feels powerful. Often overkill. Default = single agent + tools. Split into specialists only when a single prompt exceeds 1000 tokens or contains conflicting&amp;nbsp;instructions.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="composition-single-pattern-mastery"&gt;Composition &amp;gt; Single-Pattern&amp;nbsp;Mastery&lt;/h2&gt;
&lt;p&gt;True power = composing patterns. Research-assistant example from the&amp;nbsp;book.&lt;/p&gt;
&lt;p&gt;User asks: &lt;em&gt;&amp;#8220;Analyze quantum computing impact on&amp;nbsp;cybersecurity.&amp;#8221;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Composition:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Planning&lt;/strong&gt; decomposes into 4 research&amp;nbsp;steps.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tool Use&lt;/strong&gt; drives each step (search, ArXiv &lt;span class="caps"&gt;API&lt;/span&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multi-Agent&lt;/strong&gt;: Researcher gathers, Writer synthesises, Critic&amp;nbsp;reviews.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reflection&lt;/strong&gt;: Critic catches logic errors, fact errors, Writer&amp;nbsp;revises.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory&lt;/strong&gt;: persist plan, info, drafts, feedback across the multi-step&amp;nbsp;run.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Five patterns woven together. None individually impressive. Together: an autonomous research&amp;nbsp;system.&lt;/p&gt;
&lt;p&gt;That&amp;#8217;s the craft. Not &amp;#8220;I know ReAct.&amp;#8221; It&amp;#8217;s &amp;#8220;I see the canvas as a&amp;nbsp;whole.&amp;#8221;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="hard-won-lessons"&gt;Hard-Won&amp;nbsp;Lessons&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Frontier models for quality-critical paths.&lt;/strong&gt; Cheap models truncate context, lose subtle reasoning. Use cheap tier for classify / extract / route only. Cost saved &amp;lt; quality lost on the actual reasoning&amp;nbsp;step.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Untrusted content is data, never instructions.&lt;/strong&gt; Tool output, retrieved docs, user files all enter the prompt. Prompt injection is structural, not a bug. Wrap retrieved content in delimiters. Verify intent against the original user request, not against the retrieved&amp;nbsp;text.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Pin everything in version control.&lt;/strong&gt; Model version&amp;nbsp;(&lt;code&gt;claude-sonnet-4-6&lt;/code&gt;, not &amp;#8220;latest&amp;#8221;). Prompts&amp;nbsp;as &lt;code&gt;.md&lt;/code&gt; files&amp;nbsp;in &lt;code&gt;/prompts/&lt;/code&gt;. Treat prompts as code: review, version,&amp;nbsp;diff.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Goals before loops.&lt;/strong&gt; Without an explicit done-condition, the agent burns budget on infinite &amp;#8220;let me also check&amp;#8230;&amp;#8221;&amp;nbsp;Add &lt;code&gt;success_criteria: list[str]&lt;/code&gt;. Verify before each&amp;nbsp;iteration.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Rollback before retry.&lt;/strong&gt; Partial state from a failed op corrupts the next&amp;nbsp;attempt. &lt;code&gt;with transactional(state):&lt;/code&gt; pattern. Checkpoint, try, rollback on&amp;nbsp;exception.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Run before claim.&lt;/strong&gt; Generated code &amp;#8220;looks right&amp;#8221;, plausible syntax, plausible imports, may not execute. There is no truth signal in the distribution. Run tests, build, lint, type-check, the actual&amp;nbsp;feature.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;LiteLLM fallbacks save 3am pages.&lt;/strong&gt; Provider has an outage, traffic shifts to a fallback model automatically. Cost: one extra arg per&amp;nbsp;call.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;completion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"claude-sonnet-4-6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;fallbacks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"gpt-5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"gemini-2.5-pro"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"ollama/llama3.3"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;hr&gt;
&lt;h2 id="the-shift-coming"&gt;The Shift&amp;nbsp;Coming&lt;/h2&gt;
&lt;p&gt;Three trends from the book worth&amp;nbsp;tracking.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Human-in-the-loop becomes human-on-the-loop.&lt;/strong&gt; Today: agent pauses, asks human at every fork. Tomorrow: agent runs autonomously, reports only on completion or critical exception. Scope of trust expands as eval and guardrails&amp;nbsp;mature.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Standardisation via &lt;span class="caps"&gt;MCP&lt;/span&gt; plus &lt;span class="caps"&gt;A2A&lt;/span&gt;.&lt;/strong&gt; Today: tool integration is per-framework, glue code everywhere. Tomorrow: &lt;span class="caps"&gt;MCP&lt;/span&gt; for tools, &lt;span class="caps"&gt;A2A&lt;/span&gt; for agents. Agent marketplaces. Hire-able specialist agents (research agent, travel agent). The &amp;#8220;Awesome Agents&amp;#8221; repo on GitHub is already curating&amp;nbsp;this.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Neuro-symbolic blend.&lt;/strong&gt; Pure &lt;span class="caps"&gt;LLM&lt;/span&gt; = pattern match plus probabilistic. Add classical &lt;span class="caps"&gt;AI&lt;/span&gt; (logic, planning, constraint solving) for rigor. Best of both. Watch for &lt;span class="caps"&gt;SR&lt;/span&gt; 11-7-grade model governance demands as agents enter regulated&amp;nbsp;domains.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="practical-path"&gt;Practical&amp;nbsp;Path&lt;/h2&gt;
&lt;p&gt;Build in this order. Stop when the problem is&amp;nbsp;solved.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Stage&lt;/th&gt;
&lt;th&gt;Add&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hello world&lt;/td&gt;
&lt;td&gt;LiteLLM + tools + ReAct loop (30 lines)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Useful demo&lt;/td&gt;
&lt;td&gt;+ Pydantic structured output + memory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Beta&lt;/td&gt;
&lt;td&gt;+ Planning + Reflection + traces&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Production&lt;/td&gt;
&lt;td&gt;+ Guardrails + Exception handling + Eval suite&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scale&lt;/td&gt;
&lt;td&gt;+ Resource-aware routing + Multi-agent (when needed)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cross-org&lt;/td&gt;
&lt;td&gt;+ &lt;span class="caps"&gt;MCP&lt;/span&gt; + &lt;span class="caps"&gt;A2A&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Most projects stop at &amp;#8220;Production&amp;#8221;. That&amp;#8217;s fine. Resist the urge to add multi-agent before a single-agent prompt exceeds 1000 tokens. Three similar lines beats premature&amp;nbsp;abstraction.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="dont-use-a-framework-until-youve-built-without-one"&gt;Don&amp;#8217;t Use A Framework Until You&amp;#8217;ve Built Without&amp;nbsp;One&lt;/h2&gt;
&lt;p&gt;Build the 30-line ReAct loop first. Understand the mechanism: tools as &lt;span class="caps"&gt;JSON&lt;/span&gt; schema, stop reasons, tool_use blocks, tool_result feedback, message&amp;nbsp;accumulation.&lt;/p&gt;
&lt;p&gt;Then evaluate frameworks (LangGraph, CrewAI, &lt;span class="caps"&gt;ADK&lt;/span&gt;, Strands) against actual needs. They hide the mechanism, ship faster, but you debug what you don&amp;#8217;t&amp;nbsp;understand.&lt;/p&gt;
&lt;p&gt;LiteLLM ≠ framework. It&amp;#8217;s a thin &lt;span class="caps"&gt;SDK&lt;/span&gt; wrapper. Keep it under your code, not over it. The patterns above are yours to&amp;nbsp;compose.&lt;/p&gt;
&lt;p&gt;From-scratch teaches mechanism. Framework hides mechanism. Both valid. Order&amp;nbsp;matters.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="bottom-line"&gt;Bottom&amp;nbsp;Line&lt;/h2&gt;
&lt;p&gt;Agents are not magic. Loop, tools, memory, goal, self-correction. Composition of well-known patterns. The hard part isn&amp;#8217;t any single pattern, it&amp;#8217;s running the resulting system reliably in&amp;nbsp;production.&lt;/p&gt;
&lt;p&gt;Six failure modes kill prototypes. Five buckets of patterns prevent them. Build the 30-line version today. Add patterns when production need is proven, not&amp;nbsp;anticipated.&lt;/p&gt;
&lt;p&gt;Pick LiteLLM by default. Vendor-neutral code outlives the&amp;nbsp;model-of-the-month.&lt;/p&gt;
&lt;p&gt;The canvas is in front of you. Patterns are in your hands. Now go&amp;nbsp;build.&lt;/p&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.anthropic.com/research/building-effective-agents"&gt;Building Effective Agents&lt;/a&gt;. Anthropic, 2024. The single best argument for &amp;#8220;start simple, add complexity only when proven&amp;nbsp;necessary&amp;#8221;.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2210.03629"&gt;ReAct: Synergizing Reasoning and Acting in Language Models&lt;/a&gt;. Yao et al., 2022. Original ReAct&amp;nbsp;paper.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2303.11366"&gt;Reflexion: Language Agents with Verbal Reinforcement Learning&lt;/a&gt;. Shinn et al., 2023. Quantifies the lift from&amp;nbsp;self-reflection.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Agentic-Design-Patterns-Hands-Intelligent/dp/3032014018"&gt;Agentic Design Patterns&lt;/a&gt;. Antonio Gulli, 2025. The 21 patterns referenced throughout this&amp;nbsp;post.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.litellm.ai/"&gt;LiteLLM Documentation&lt;/a&gt;. Vendor-neutral &lt;span class="caps"&gt;SDK&lt;/span&gt; used in the example&amp;nbsp;loop.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://modelcontextprotocol.io/"&gt;Model Context Protocol Specification&lt;/a&gt;. Wire protocol for tool&amp;nbsp;servers.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://a2aproject.github.io/A2A/"&gt;&lt;span class="caps"&gt;A2A&lt;/span&gt; Protocol&lt;/a&gt;. Cross-org agent-to-agent discovery and task&amp;nbsp;standard.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://owasp.org/www-project-top-10-for-large-language-model-applications/"&gt;&lt;span class="caps"&gt;OWASP&lt;/span&gt; Top 10 for Large Language Model Applications&lt;/a&gt;. Prompt injection (&lt;span class="caps"&gt;LLM01&lt;/span&gt;) and excessive agency (&lt;span class="caps"&gt;LLM06&lt;/span&gt;) bite agent designs&amp;nbsp;hardest.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/"&gt;Parse, don&amp;#8217;t validate&lt;/a&gt;. Alexis King, 2019. The original phrase, applied to schema validation at&amp;nbsp;boundaries.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://web.archive.org/web/2026/https://www.federalreserve.gov/supervisionreg/srletters/sr1107.htm"&gt;&lt;span class="caps"&gt;SR&lt;/span&gt; 11-7, Model Risk Management&lt;/a&gt;. &lt;span class="caps"&gt;US&lt;/span&gt; Federal Reserve, 2011 (Wayback mirror, federalreserve.gov returning 404 as of 2026-05-08). Governance regime for any model used in regulated&amp;nbsp;decisions.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.arize.com/phoenix"&gt;Arize Phoenix&lt;/a&gt;. Open-source &lt;span class="caps"&gt;LLM&lt;/span&gt; observability, OTel-native, runs&amp;nbsp;locally.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://langfuse.com/docs"&gt;Langfuse&lt;/a&gt;. Open-source self-hostable &lt;span class="caps"&gt;LLM&lt;/span&gt; observability with prompt&amp;nbsp;management.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.helicone.ai/"&gt;Helicone&lt;/a&gt;. Proxy-based &lt;span class="caps"&gt;LLM&lt;/span&gt; observability, single env-var&amp;nbsp;integration.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching"&gt;Anthropic Prompt Caching&lt;/a&gt;. Cache reuse up to 90% input cost&amp;nbsp;savings.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/simpleeval/"&gt;simpleeval&lt;/a&gt;. Sandboxed expression evaluator for the calculator-tool&amp;nbsp;case.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;First Principles: Software Observability&lt;/a&gt;. The three-pillar discipline that grounds the trace-backend&amp;nbsp;section.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-llm-agents.html"&gt;First Principles: &lt;span class="caps"&gt;LLM&lt;/span&gt; Agents (Most of Yours Are Chatbots Wearing a Hat)&lt;/a&gt;. Companion piece, same day, conceptual&amp;nbsp;frame.&lt;/li&gt;
&lt;/ol&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Engineering"/><category term="ai"/><category term="agents"/><category term="llm"/><category term="prompt-engineering"/><category term="litellm"/><category term="python"/></entry><entry><title>Dependency cooldowns considered harmful: a first-principles analysis</title><link href="https://alexsavio.github.io/dependency-cooldown-considered-harmful.html" rel="alternate"/><published>2026-04-13T20:30:00+02:00</published><updated>2026-04-13T20:30:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2026-04-13:/dependency-cooldown-considered-harmful.html</id><summary type="html">&lt;p&gt;Dependency cooldowns promise supply-chain safety by hiding releases for N days, but the math shows they guarantee extended &lt;span class="caps"&gt;CVE&lt;/span&gt; exposure while catching only a narrow band of attacks that lockfiles and staging already cover. The time buffer belongs in staging, not the&amp;nbsp;resolver.&lt;/p&gt;</summary><content type="html">&lt;h2 id="tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Intro.&lt;/strong&gt; A &amp;#8220;dependency cooldown&amp;#8221; tells your resolver to ignore releases newer&amp;nbsp;than &lt;span class="math"&gt;\(N\)&lt;/span&gt; days, on the theory that the community will catch bad releases before you adopt them. In an April 2026 post, Astral laid out their internal security posture and listed cooldowns as one of the layers they lean on. It sounds cautious. It is in fact an unusually expensive hedge that optimizes for the wrong failure mode, deadlocks with the tools that protect you from the &lt;em&gt;actual&lt;/em&gt; high-frequency failure mode (CVEs), and cannot be rescued with a user-level&amp;nbsp;override.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Argument.&lt;/strong&gt; Reason from first principles about what can actually happen to a dependency, and a flat pre-resolver cooldown is dominated by buffering &lt;em&gt;later&lt;/em&gt; in the pipeline (at audit time, at merge time, at staging). Cooldowns trade a certain cost, extended &lt;span class="caps"&gt;CVE&lt;/span&gt; exposure every time a fix lands, for a speculative benefit, dodging fast-yanked malicious releases, that lockfiles, hashes, and staging already cover. A Monte Carlo simulation of the cost model (backed by a closed-form analytical check to machine precision) puts the break-even risk&amp;nbsp;ratio &lt;span class="math"&gt;\(I_{\text{attack}} / I_{\text{cve}}\)&lt;/span&gt; at roughly &lt;strong&gt;12,000&lt;/strong&gt; for an 8-day cooldown. For a typical non-financial-critical service, that is nowhere close, and the policy&amp;nbsp;loses.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Caveat.&lt;/strong&gt; The math flips at high enough stakes.&amp;nbsp;At &lt;span class="math"&gt;\(I_{\text{attack}} / I_{\text{cve}} \geq 10^5\)&lt;/span&gt; (think: payments, custodial crypto, identity), a real cooldown does pay. The right answer for those teams is not &amp;#8220;no cooldown&amp;#8221; but &amp;#8220;the least bad &lt;em&gt;variant&lt;/em&gt; of one&amp;#8221;, because the word &amp;#8220;cooldown&amp;#8221; today flattens eight different policies into a single switch and the default switch is the one that loses. Sections 8 and 9 name the&amp;nbsp;alternatives.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Conclusion.&lt;/strong&gt; Adopt fast. Verify hard. Buffer late. If you truly need a window in the resolver, do not reach for the flat&amp;nbsp;one.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;🧮 &lt;strong&gt;Reproduce the numbers.&lt;/strong&gt; Every number in this post (break-even ratio, compromise probabilities, the cooldown sweep, the &amp;#8220;one compromise every 69 years&amp;#8221;) comes from a self-contained Python script. It runs in ~3 seconds&amp;nbsp;via &lt;code&gt;uv run&lt;/code&gt; (&lt;span class="caps"&gt;PEP&lt;/span&gt; 723 inline metadata, numpy-only), asserts the Monte Carlo matches the analytical closed form to within 0.002, and prints a full cost-model&amp;nbsp;report.&lt;/p&gt;
&lt;p&gt;👉 &lt;strong&gt;&lt;a href="https://gist.github.com/alexsavio/3cdf6f284614fd4ea4d7a2b865ec5249"&gt;Gist: &lt;code&gt;simulate_dependency_cooldown.py&lt;/code&gt; + captured&amp;nbsp;output&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Change any parameter&amp;nbsp;(&lt;span class="math"&gt;\(\lambda_{\text{cve}}\)&lt;/span&gt;, &lt;span class="math"&gt;\(r_{\text{attack}}\)&lt;/span&gt;, the detection-delay mixture, your audit latency) and re-run. If you disagree with the conclusion, disagree with the parameters, not the&amp;nbsp;math.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="0-what-this-is-not"&gt;0. What this is&amp;nbsp;not&lt;/h2&gt;
&lt;p&gt;This is not an argument against Astral&amp;#8217;s broader security posture, most of which is excellent: trusted publishing, sigstore attestations, immutable releases, pinned actions, no caching during releases. Those layers genuinely move the needle. It is also not an argument against putting latency between a release and your production code. There should be latency. The question is &lt;em&gt;where in the pipeline&lt;/em&gt; that latency earns its keep. A cooldown places it before the resolver, which turns out to be the worst possible spot: it blinds the resolver to &lt;span class="caps"&gt;CVE&lt;/span&gt; fixes, deadlocks with live-&lt;span class="caps"&gt;DB&lt;/span&gt; auditors, and duplicates protections that lockfiles and staging already provide. Every other layer is strictly better at the&amp;nbsp;job.&lt;/p&gt;
&lt;h2 id="1-the-scenario-ci-goes-red-on-a-security-fix"&gt;1. The scenario: &lt;span class="caps"&gt;CI&lt;/span&gt; goes red on a security&amp;nbsp;fix&lt;/h2&gt;
&lt;p&gt;Start with the concrete situation that prompted this post. A typical modern Python upgrade pipeline looks like&amp;nbsp;this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;uv lock --upgrade&lt;/code&gt; (respects&amp;nbsp;cooldown)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pip-audit&lt;/code&gt; (does not respect cooldown; queries live advisory &lt;span class="caps"&gt;DB&lt;/span&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A &lt;span class="caps"&gt;CVE&lt;/span&gt; lands on package X. The maintainers cut a patch release X+1 the same day. Your scheduled Dependabot run fires. Here is what happens&amp;nbsp;next:&lt;/p&gt;
&lt;pre class="mermaid"&gt;
flowchart TD
    A[uv lock --upgrade&lt;br/&gt;exclude-newer respects cooldown] --&gt; B[Resolver refuses&lt;br/&gt;to see X+1]
    B --&gt; C[Lockfile pins X&lt;br/&gt;vulnerable version]
    C --&gt; D[pip-audit queries&lt;br/&gt;live advisory DB]
    D --&gt; E[Audit flags X&lt;br/&gt;CI fails RED]
    E --&gt; F{Fix X+1?}
    F --&gt;|blocked by cooldown| B
    F --&gt;|wait C days| G[Window expires]
    G --&gt; A
&lt;/pre&gt;

&lt;p&gt;There is no version constraint you can write to escape this.&amp;nbsp;Pinning &lt;code&gt;cryptography&amp;gt;=46.0.7&lt;/code&gt; directly&amp;nbsp;produces:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;× No solution found when resolving dependencies:
╰─▶ Because only cryptography&amp;lt;=46.0.6 is available and your
    project depends on cryptography&amp;gt;=46.0.7, we can conclude
    that your project's requirements are unsatisfiable.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;exclude-newer&lt;/code&gt; is a &lt;strong&gt;hard pre-filter on the catalog&lt;/strong&gt;, not a preference. The solver never sees filtered versions, so user constraints cannot recover them. The cooldown and the auditor deadlock, and the only way to break the deadlock is to wait for the window to expire. During those days, &lt;span class="caps"&gt;CI&lt;/span&gt; is red and the scheduled &lt;span class="caps"&gt;PR&lt;/span&gt; cannot&amp;nbsp;open.&lt;/p&gt;
&lt;p&gt;This is not a tooling bug. It is the direct consequence of layering a &amp;#8220;hide new versions&amp;#8221; filter under a &amp;#8220;check against live &lt;span class="caps"&gt;CVE&lt;/span&gt; data&amp;#8221; auditor. The two policies are logically incompatible for the entire duration of every cooldown window in which a &lt;span class="caps"&gt;CVE&lt;/span&gt; lands. &lt;strong&gt;It will recur on every future &lt;span class="caps"&gt;CVE&lt;/span&gt; that ships inside the window.&lt;/strong&gt; That&amp;#8217;s the scenario. The rest of this post explains why it is structural, not fixable by clever configuration, and what to do&amp;nbsp;instead.&lt;/p&gt;
&lt;h2 id="2-what-events-can-actually-happen-to-a-dependency"&gt;2. What events can actually happen to a&amp;nbsp;dependency&lt;/h2&gt;
&lt;p&gt;To reason about the scenario from first principles, start by enumerating the things a package version can actually experience. At any&amp;nbsp;time &lt;span class="math"&gt;\(t\)&lt;/span&gt;, a released version is in exactly one of these&amp;nbsp;states:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Fine forever.&lt;/strong&gt; The vast&amp;nbsp;majority.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Latent bug&lt;/strong&gt;, discovered&amp;nbsp;at &lt;span class="math"&gt;\(t = D_{\text{bug}}\)&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Latent &lt;span class="caps"&gt;CVE&lt;/span&gt;&lt;/strong&gt;, present all along, disclosed&amp;nbsp;at &lt;span class="math"&gt;\(t = D_{\text{cve}}\)&lt;/span&gt;, fix released&amp;nbsp;at &lt;span class="math"&gt;\(t = D_{\text{cve}} + \varepsilon\)&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Malicious&lt;/strong&gt;: supply-chain attack, discovered and yanked&amp;nbsp;at &lt;span class="math"&gt;\(t = D_{\text{mal}}\)&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Intentional breaking change&lt;/strong&gt;, discovered via your own traffic&amp;nbsp;at &lt;span class="math"&gt;\(t = D_{\text{reg}}\)&lt;/span&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Each class has its own &lt;strong&gt;detection-delay distribution&lt;/strong&gt;, and they are wildly&amp;nbsp;different.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Class&lt;/th&gt;
&lt;th&gt;Typical detection delay&lt;/th&gt;
&lt;th&gt;Who notices&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🕷️ Supply-chain attack (typosquat, account compromise)&lt;/td&gt;
&lt;td&gt;⚡ hours to days&lt;/td&gt;
&lt;td&gt;🤖 scanners, community&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🐛 Bug / regression&lt;/td&gt;
&lt;td&gt;📅 days to weeks&lt;/td&gt;
&lt;td&gt;👥 early adopters + your traffic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🔓 &lt;span class="caps"&gt;CVE&lt;/span&gt; disclosed against existing version&lt;/td&gt;
&lt;td&gt;⏳ already there; disclosure starts the clock&lt;/td&gt;
&lt;td&gt;🔬 researchers, vendors&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;💥 Breaking change&lt;/td&gt;
&lt;td&gt;📅 days to weeks&lt;/td&gt;
&lt;td&gt;👤 users&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Same content, different lens. Plot each class on&amp;nbsp;a &lt;code&gt;(detection speed, blast radius)&lt;/code&gt; plane and a visual story emerges about where a cooldown can actually&amp;nbsp;help:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Dependency events: detection speed vs blast radius" src="https://alexsavio.github.io/imgs/dependency_events_quadrant.png"&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Chart generated by &lt;a href="https://github.com/alexsavio/alexsavio.github.io/blob/master/scripts/plot_dependency_events_quadrant.py"&gt;&lt;code&gt;scripts/plot_dependency_events_quadrant.py&lt;/code&gt;&lt;/a&gt; (matplotlib, &lt;span class="caps"&gt;PEP&lt;/span&gt; 723 inline script, runs&amp;nbsp;via &lt;code&gt;uv run&lt;/code&gt;).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A cooldown lives entirely in the left half of the plane: it only bites events it can &lt;em&gt;see&lt;/em&gt;, meaning ones with fast detection. Of the two left-half points worth catching, typosquats are already handled by new-dep review, and the post-disclosure &lt;span class="caps"&gt;CVE&lt;/span&gt; fix is exactly the event a cooldown &lt;strong&gt;delays&lt;/strong&gt;, not protects against. Everything in the right half (long-dwell, pre-disclosure &lt;span class="caps"&gt;CVE&lt;/span&gt; latency) is invisible to any cooldown window you could reasonably set. The quadrant that a cooldown is &lt;em&gt;supposed&lt;/em&gt; to own, top-left, is in practice almost empty once you subtract the events lockfiles and new-dep review already&amp;nbsp;cover.&lt;/p&gt;
&lt;p&gt;These distributions are the entire game. A cooldown is a bet on one of them: specifically,&amp;nbsp;that &lt;span class="math"&gt;\(D_{\text{mal}} &amp;lt; C\)&lt;/span&gt; often enough to justify the cost. Everything else is&amp;nbsp;arithmetic.&lt;/p&gt;
&lt;h2 id="3-the-critical-asymmetry-cves-run-the-clock-backwards"&gt;3. The critical asymmetry: CVEs run the clock&amp;nbsp;backwards&lt;/h2&gt;
&lt;p&gt;The naive cooldown argument treats &amp;#8220;new version&amp;#8221; as the risky event. For CVEs this is backwards, and this single asymmetry is the whole reason the scenario in section 1 exists. The real time sequence for a &lt;span class="caps"&gt;CVE&lt;/span&gt;&amp;nbsp;is:&lt;/p&gt;
&lt;div class="math"&gt;$$
\begin{aligned}
t = -\infty &amp;amp;\quad\text{you adopted vulnerable version } v_{\text{old}} \text{ (no warning)} \\
t = 0       &amp;amp;\quad\text{CVE disclosed; fix } v_{\text{new}} \text{ released the same day} \\
t = 0^{+}   &amp;amp;\quad\text{attackers start scanning the internet} \\
t = N       &amp;amp;\quad\text{you upgrade to } v_{\text{new}}
\end{aligned}
$$&lt;/div&gt;
&lt;p&gt;Your exposure window&amp;nbsp;is &lt;span class="math"&gt;\([0, N]\)&lt;/span&gt;. It does not start&amp;nbsp;when &lt;span class="math"&gt;\(v_{\text{new}}\)&lt;/span&gt; ships; it started whenever you&amp;nbsp;adopted &lt;span class="math"&gt;\(v_{\text{old}}\)&lt;/span&gt;, which was weeks or months&amp;nbsp;ago. &lt;span class="math"&gt;\(v_{\text{new}}\)&lt;/span&gt; is the &lt;em&gt;end&lt;/em&gt; of your exposure, not the&amp;nbsp;beginning.&lt;/p&gt;
&lt;p&gt;A cooldown&amp;nbsp;forces &lt;span class="math"&gt;\(N \geq C\)&lt;/span&gt;. That does not &amp;#8220;delay risk.&amp;#8221; It &lt;strong&gt;guarantees the extension of an exposure window you were already in&lt;/strong&gt;. The cooldown is not caution; it is a commitment to stay vulnerable, paid up front, for every future &lt;span class="caps"&gt;CVE&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;This is the core confusion cooldowns bake in: they conflate &lt;strong&gt;novelty&lt;/strong&gt; with &lt;strong&gt;risk&lt;/strong&gt;. A new version is novel; it is not (usually) risky. A not-yet-patched old version is not novel; it is (definitely) risky. The policy taxes the wrong&amp;nbsp;axis.&lt;/p&gt;
&lt;h2 id="4-the-time-sequence-for-a-supply-chain-attack"&gt;4. The time sequence for a supply-chain&amp;nbsp;attack&lt;/h2&gt;
&lt;p&gt;Now the event the cooldown is actually trying to protect&amp;nbsp;against:&lt;/p&gt;
&lt;div class="math"&gt;$$
\begin{aligned}
t = 0 &amp;amp;\quad\text{malicious } v_{\text{new}} \text{ published} \\
t = D &amp;amp;\quad\text{community detects, yanks, rotates credentials} \\
t = N &amp;amp;\quad\text{you adopt}
\end{aligned}
$$&lt;/div&gt;
&lt;p&gt;You are compromised&amp;nbsp;iff &lt;span class="math"&gt;\(N &amp;lt; D\)&lt;/span&gt;. A cooldown with&amp;nbsp;window &lt;span class="math"&gt;\(C\)&lt;/span&gt; guarantees &lt;span class="math"&gt;\(N \geq C\)&lt;/span&gt;, so you are protected&amp;nbsp;iff &lt;span class="math"&gt;\(C &amp;gt; D\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;This is genuinely useful, but narrower than it&amp;nbsp;sounds:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Typosquats&lt;/strong&gt; are detected in hours. Any cooldown catches them. But you weren&amp;#8217;t going to&amp;nbsp;install &lt;code&gt;requessts&lt;/code&gt; anyway; this class is caught by new-dep review and pip&amp;#8217;s&amp;nbsp;warnings.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compromised maintainer accounts&lt;/strong&gt; (event-stream, ua-parser-js) get detected in 1–5 days typically. An 8-day cooldown catches them &lt;em&gt;if&lt;/em&gt; you would have adopted the compromised version in those 1–5&amp;nbsp;days.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Long-dwell attacks&lt;/strong&gt; (xz-utils, the SolarWinds family) sit undetected for weeks to months. No reasonable cooldown catches&amp;nbsp;these.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transitive compromises&lt;/strong&gt; don&amp;#8217;t care about your cooldown at all. The transitive is pinned in someone else&amp;#8217;s lockfile and updates on someone else&amp;#8217;s&amp;nbsp;schedule.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So the cooldown defends against the middle band: medium-dwell compromises of packages you were about to adopt in the danger window. A real class, but not &amp;#8220;supply chain attacks in&amp;nbsp;general.&amp;#8221;&lt;/p&gt;
&lt;h2 id="5-expected-cost-math"&gt;5. Expected-cost&amp;nbsp;math&lt;/h2&gt;
&lt;p&gt;Put numbers on it. Let me define the model cleanly before plugging in, because the sloppy version (where &amp;#8220;rate&amp;#8221; secretly contains a probability) leads to double&amp;nbsp;counting.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Parameters.&lt;/strong&gt; Over one year, for a typical non-trivial&amp;nbsp;service:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class="math"&gt;\(\lambda_{\text{cve}}\)&lt;/span&gt; = rate of &lt;span class="caps"&gt;CVE&lt;/span&gt; disclosures affecting packages in your dep tree. &lt;strong&gt;~25/year&lt;/strong&gt; for a non-trivial Python&amp;nbsp;service.&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(r_{\text{attack}}\)&lt;/span&gt; = rate of malicious releases published in packages you could plausibly adopt (before any mitigation). &lt;strong&gt;~0.1/year&lt;/strong&gt; is a reasonable guess for a team with lockfiles and new-dep review already in&amp;nbsp;place.&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(L\)&lt;/span&gt; = audit latency in days. One cycle (&lt;strong&gt;1 day&lt;/strong&gt;) if you audit on every&amp;nbsp;resolve.&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(C\)&lt;/span&gt; = cooldown window in days&amp;nbsp;(e.g., &lt;span class="math"&gt;\(C = 8\)&lt;/span&gt;).&lt;/li&gt;
&lt;li&gt;&lt;span class="math"&gt;\(N_0\)&lt;/span&gt; = your natural adoption delay. Weekly upgrade cadence&amp;nbsp;means &lt;span class="math"&gt;\(N_0 \sim \mathrm{Uniform}(0, 7)\)&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;span class="math"&gt;\(D\)&lt;/span&gt; = detection delay for a malicious release, drawn from a mixture of exponentials reflecting the classes in section&amp;nbsp;4:&lt;/p&gt;
&lt;p&gt;
&lt;div class="math"&gt;$$
D \sim 0.5 \cdot \mathrm{Exp}(1/0.5) \;+\; 0.3 \cdot \mathrm{Exp}(1/3) \;+\; 0.2 \cdot \mathrm{Exp}(1/60)
$$&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;(typosquats in hours, account compromises in days, long-dwell in months).&amp;nbsp;- &lt;span class="math"&gt;\(I_{\text{cve}}\)&lt;/span&gt; = cost of one vuln-day of known-vulnerable exposure.&amp;nbsp;- &lt;span class="math"&gt;\(I_{\text{attack}}\)&lt;/span&gt; = cost of one successful compromise. Both costs are in the same unit, so the quantity we really care about is the&amp;nbsp;ratio &lt;span class="math"&gt;\(I_{\text{attack}} / I_{\text{cve}}\)&lt;/span&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Term (1): guaranteed &lt;span class="caps"&gt;CVE&lt;/span&gt; exposure.&lt;/strong&gt; Each disclosed &lt;span class="caps"&gt;CVE&lt;/span&gt; costs you the time between disclosure and upgrade. A cooldown forces that time to be at&amp;nbsp;least &lt;span class="math"&gt;\(C\)&lt;/span&gt;; auditing forces it to be at&amp;nbsp;least &lt;span class="math"&gt;\(L\)&lt;/span&gt;. So exposure-per-&lt;span class="caps"&gt;CVE&lt;/span&gt;&amp;nbsp;is &lt;span class="math"&gt;\(\max(C, L)\)&lt;/span&gt;. Annual&amp;nbsp;cost:&lt;/p&gt;
&lt;div class="math"&gt;$$
\text{CVE}(C) \;=\; \lambda_{\text{cve}} \cdot \max(C, L) \cdot I_{\text{cve}}
$$&lt;/div&gt;
&lt;p&gt;Plugging&amp;nbsp;in: &lt;span class="math"&gt;\(\text{CVE}(0) = 25 \cdot 1 = 25\)&lt;/span&gt; vuln-days/year. &lt;span class="math"&gt;\(\text{CVE}(8) = 25 \cdot 8 = 200\)&lt;/span&gt;. The cooldown&amp;#8217;s &lt;em&gt;guaranteed&lt;/em&gt; &lt;span class="caps"&gt;CVE&lt;/span&gt; tax is the &lt;strong&gt;difference&lt;/strong&gt;, &lt;span class="math"&gt;\(\lambda_{\text{cve}} \cdot (\max(C, L) - L) \cdot I_{\text{cve}} = 175 \cdot I_{\text{cve}}\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Term (2): residual attack cost.&lt;/strong&gt; This is where the naive model went wrong. The clean decomposition is: a compromise happens iff you adopt before detection,&amp;nbsp;i.e., &lt;span class="math"&gt;\(N &amp;lt; D\)&lt;/span&gt;,&amp;nbsp;where &lt;span class="math"&gt;\(N\)&lt;/span&gt; is your effective adoption delay. Without a&amp;nbsp;cooldown, &lt;span class="math"&gt;\(N = N_0\)&lt;/span&gt;. With&amp;nbsp;cooldown &lt;span class="math"&gt;\(C\)&lt;/span&gt;, the resolver refuses versions newer&amp;nbsp;than &lt;span class="math"&gt;\(C\)&lt;/span&gt; days,&amp;nbsp;so &lt;span class="math"&gt;\(N = \max(C, N_0)\)&lt;/span&gt;. Annual attack&amp;nbsp;cost:&lt;/p&gt;
&lt;div class="math"&gt;$$
\text{Attack}(C) \;=\; r_{\text{attack}} \cdot \Pr\bigl(\max(C, N_0) &amp;lt; D\bigr) \cdot I_{\text{attack}}
$$&lt;/div&gt;
&lt;p&gt;No hidden probability&amp;nbsp;inside &lt;span class="math"&gt;\(r_{\text{attack}}\)&lt;/span&gt;. The probability of compromise is computed from the model, not&amp;nbsp;assumed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Plugging in.&lt;/strong&gt;&amp;nbsp;For &lt;span class="math"&gt;\(N_0 \sim \mathrm{Uniform}(0, 7)\)&lt;/span&gt; and the detection-delay mixture above, a direct &lt;a href="https://gist.github.com/alexsavio/3cdf6f284614fd4ea4d7a2b865ec5249"&gt;Monte Carlo simulation&lt;/a&gt; (2 million samples, seed 42, results match analytical closed forms to four decimal places)&amp;nbsp;gives:&lt;/p&gt;
&lt;div class="math"&gt;$$
\Pr(N_0 &amp;lt; D) \approx 0.341 \qquad \Pr\bigl(\max(8, N_0) &amp;lt; D\bigr) \approx 0.196
$$&lt;/div&gt;
&lt;p&gt;So an 8-day cooldown&amp;nbsp;prevents &lt;span class="math"&gt;\(\Delta P \approx 0.145\)&lt;/span&gt; of attacks in absolute terms. Expected compromises per&amp;nbsp;year:&lt;/p&gt;
&lt;div class="math"&gt;$$
\text{compromises/year:} \quad r_{\text{attack}} \cdot \Pr(N &amp;lt; D) \;=\; 0.1 \cdot 0.341 \approx 0.034 \;\text{(no cooldown)}
$$&lt;/div&gt;
&lt;div class="math"&gt;$$
\qquad\qquad\qquad 0.1 \cdot 0.196 \approx 0.020 \;\text{(8-day cooldown)}
$$&lt;/div&gt;
&lt;p&gt;The cooldown prevents about &lt;strong&gt;one compromise every 69 years&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Total cost.&lt;/strong&gt; Combining both&amp;nbsp;terms:&lt;/p&gt;
&lt;div class="math"&gt;$$
\text{cost}(C) \;=\; \lambda_{\text{cve}} \cdot \max(C, L) \cdot I_{\text{cve}} \;+\; r_{\text{attack}} \cdot \Pr\bigl(\max(C, N_0) &amp;lt; D\bigr) \cdot I_{\text{attack}}
$$&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Break-even.&lt;/strong&gt;&amp;nbsp;Setting &lt;span class="math"&gt;\(\text{cost}(8) = \text{cost}(0)\)&lt;/span&gt; and solving for the risk&amp;nbsp;ratio:&lt;/p&gt;
&lt;div class="math"&gt;$$
\frac{I_{\text{attack}}}{I_{\text{cve}}} \;=\; \frac{\lambda_{\text{cve}} \cdot (C - L)}{r_{\text{attack}} \cdot \bigl[\Pr(N_0 &amp;lt; D) - \Pr(\max(C, N_0) &amp;lt; D)\bigr]} \;=\; \frac{175}{0.0145} \approx 12{,}073
$$&lt;/div&gt;
&lt;p&gt;In plain language: one compromise would have to be as damaging as &lt;strong&gt;12,000 &lt;span class="caps"&gt;CVE&lt;/span&gt;-days of exposure&lt;/strong&gt; for an 8-day cooldown to pay off at these parameters. For most teams, nowhere close. The math gets worse when you notice that term (2) is &lt;strong&gt;already mostly mitigated&lt;/strong&gt; by lockfile hashes and new-dep review, which the cooldown does not&amp;nbsp;improve.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The shape of the tradeoff.&lt;/strong&gt;&amp;nbsp;Sweeping &lt;span class="math"&gt;\(C\)&lt;/span&gt; through common values (numbers taken directly from the &lt;a href="https://gist.github.com/alexsavio/3cdf6f284614fd4ea4d7a2b865ec5249"&gt;simulation gist&lt;/a&gt; output, section &amp;#8220;Shape of the&amp;nbsp;tradeoff&amp;#8221;):&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Cooldown &lt;span class="math"&gt;\(C\)&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;&lt;span class="caps"&gt;CVE&lt;/span&gt; exposure&lt;/th&gt;
&lt;th&gt;&lt;span class="math"&gt;\(\Pr(\text{compromise})\)&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;Compromises prevented&amp;nbsp;vs &lt;span class="math"&gt;\(C=0\)&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;Break-even &lt;span class="math"&gt;\(I_{\text{attack}} / I_{\text{cve}}\)&lt;/span&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;0 days&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;25 vuln-days/yr&lt;/td&gt;
&lt;td&gt;0.3406&lt;/td&gt;
&lt;td&gt;baseline&lt;/td&gt;
&lt;td&gt;n/a&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🟢 &lt;strong&gt;1 day&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;25 vuln-days/yr&lt;/td&gt;
&lt;td&gt;0.3134&lt;/td&gt;
&lt;td&gt;1 per 368 yrs&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt; (free&amp;nbsp;lunch: &lt;span class="math"&gt;\(C = L\)&lt;/span&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🟢 &lt;strong&gt;2 days&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;50 vuln-days/yr&lt;/td&gt;
&lt;td&gt;0.2887&lt;/td&gt;
&lt;td&gt;1 per 193 yrs&lt;/td&gt;
&lt;td&gt;4,814&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🟡 &lt;strong&gt;5 days&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;125 vuln-days/yr&lt;/td&gt;
&lt;td&gt;0.2354&lt;/td&gt;
&lt;td&gt;1 per 95 yrs&lt;/td&gt;
&lt;td&gt;9,511&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🟡 &lt;strong&gt;7 days&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;175 vuln-days/yr&lt;/td&gt;
&lt;td&gt;0.2071&lt;/td&gt;
&lt;td&gt;1 per 75 yrs&lt;/td&gt;
&lt;td&gt;11,234&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🔴 &lt;strong&gt;14 days&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;350 vuln-days/yr&lt;/td&gt;
&lt;td&gt;0.1612&lt;/td&gt;
&lt;td&gt;1 per 56 yrs&lt;/td&gt;
&lt;td&gt;18,117&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🔴 &lt;strong&gt;30 days&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;750 vuln-days/yr&lt;/td&gt;
&lt;td&gt;0.1213&lt;/td&gt;
&lt;td&gt;1 per 46 yrs&lt;/td&gt;
&lt;td&gt;33,064&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Two things jump out. First, &lt;strong&gt;&lt;span class="math"&gt;\(C = 1\)&lt;/span&gt; is genuinely free&lt;/strong&gt;: it matches your audit latency, so &lt;span class="caps"&gt;CVE&lt;/span&gt; exposure does not move at all, yet it still catches an extra ~3% of compromises. If you &lt;em&gt;must&lt;/em&gt; have a cooldown, that is the one that does not cost you anything. Second, &lt;strong&gt;break-even grows faster than linearly&amp;nbsp;in &lt;span class="math"&gt;\(C\)&lt;/span&gt;&lt;/strong&gt;: doubling the window more than doubles the risk ratio at which the cooldown pays off, because the &lt;span class="caps"&gt;CVE&lt;/span&gt; tax grows linearly while the remaining attack surface shrinks sub-linearly. Long windows get punished&amp;nbsp;hard.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;⚠️ &lt;strong&gt;Limits of this model.&lt;/strong&gt; The detection-delay&amp;nbsp;mixture, &lt;span class="math"&gt;\(r_{\text{attack}}\)&lt;/span&gt;, and the linearity&amp;nbsp;of &lt;span class="math"&gt;\(I_{\text{cve}}\)&lt;/span&gt; are priors, not measurements. Treat the break-even ratio as accurate to roughly &lt;strong&gt;one significant figure&lt;/strong&gt;: &amp;#8220;~12,000&amp;#8221; could plausibly be 6,000 or 30,000 depending on what you believe about long-dwell tail shape, how bursty fast-yank detection really is, and whether &lt;span class="caps"&gt;CVE&lt;/span&gt; cost escalates non-linearly with exposure time. The model is also blind to transitive deps, fleet multipliers, operational toil, attacker adaptation, and catastrophic tail events that expected-value math systematically undersizes. These biases point in both directions and mostly cancel; the best place to push back on this post is to &lt;strong&gt;challenge the parameters, not the structure&lt;/strong&gt;. What the model does &lt;em&gt;not&lt;/em&gt; depend on: the &lt;span class="caps"&gt;CVE&lt;/span&gt; clock-asymmetry argument (section 3), the auditor/resolver deadlock (section 1), or the operational-debt modes (section 7). Those are qualitative, distribution-free, and&amp;nbsp;robust.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="6-where-to-put-the-time-buffer"&gt;6. Where to put the time&amp;nbsp;buffer&lt;/h2&gt;
&lt;p&gt;The real question is not &amp;#8220;should there be latency between a version shipping and prod running it.&amp;#8221; There should. The question is &lt;strong&gt;where in the pipeline to put that latency.&lt;/strong&gt; You have three&amp;nbsp;choices:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Buffer location&lt;/th&gt;
&lt;th&gt;Fast &lt;span class="caps"&gt;CVE&lt;/span&gt; adoption?&lt;/th&gt;
&lt;th&gt;Catches regressions?&lt;/th&gt;
&lt;th&gt;Defends fast-yank attacks?&lt;/th&gt;
&lt;th&gt;Deadlocks with audit tooling?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🚫 &lt;strong&gt;Pre-resolver&lt;/strong&gt; (cooldown)&lt;/td&gt;
&lt;td&gt;❌ no&lt;/td&gt;
&lt;td&gt;⚠️ weak, you hope the community flags it&lt;/td&gt;
&lt;td&gt;⚠️ narrow band&lt;/td&gt;
&lt;td&gt;❌ yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;⚙️ &lt;strong&gt;Post-resolver, pre-merge&lt;/strong&gt; (&lt;span class="caps"&gt;CI&lt;/span&gt; + audit + review)&lt;/td&gt;
&lt;td&gt;✅ yes&lt;/td&gt;
&lt;td&gt;❌ no&lt;/td&gt;
&lt;td&gt;✅ yes, via hashes&lt;/td&gt;
&lt;td&gt;✅ no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🧪 &lt;strong&gt;Post-merge, pre-prod&lt;/strong&gt; (staging bake)&lt;/td&gt;
&lt;td&gt;✅ yes&lt;/td&gt;
&lt;td&gt;✅ yes, real traffic&lt;/td&gt;
&lt;td&gt;✅ yes&lt;/td&gt;
&lt;td&gt;✅ no&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Pre-resolver buffering is &lt;strong&gt;dominated&lt;/strong&gt; on every axis that matters for a typical service. There is one degenerate&amp;nbsp;exception: &lt;span class="math"&gt;\(C \approx L\)&lt;/span&gt;, a cooldown matched to your audit latency. That setting costs nothing extra in &lt;span class="caps"&gt;CVE&lt;/span&gt; exposure&amp;nbsp;(since &lt;span class="math"&gt;\(\max(C, L) = L\)&lt;/span&gt;) and still catches a few fast-yank attacks. It is the only version of a cooldown that is strictly non-harmful, and it is &lt;em&gt;not&lt;/em&gt; what anyone means when they enable one. Everything larger starts paying the &lt;span class="caps"&gt;CVE&lt;/span&gt; tax described in section&amp;nbsp;5.&lt;/p&gt;
&lt;p&gt;If you have a weak argument for buffering &lt;em&gt;earlier&lt;/em&gt;, you have a strictly stronger argument for buffering &lt;em&gt;later&lt;/em&gt;. Staging bake is the killer comparison. It uses your own traffic to detect regressions. That is a &lt;strong&gt;higher-fidelity signal&lt;/strong&gt; than &amp;#8220;the community didn&amp;#8217;t yank it yet&amp;#8221;: you know whether &lt;em&gt;your&lt;/em&gt; code, &lt;em&gt;your&lt;/em&gt; workload, &lt;em&gt;your&lt;/em&gt; configuration breaks. The community cannot tell you that. A cooldown pretends community vigilance is a substitute. It&amp;nbsp;isn&amp;#8217;t.&lt;/p&gt;
&lt;h2 id="7-additional-failure-modes"&gt;7. Additional failure&amp;nbsp;modes&lt;/h2&gt;
&lt;p&gt;Beyond the deadlock, cooldowns accumulate operational&amp;nbsp;debt:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Per-package allow-lists&amp;nbsp;rot.&lt;/strong&gt; &lt;code&gt;uv&lt;/code&gt; offers &lt;code&gt;exclude-newer-package&lt;/code&gt; to exempt a package from the cooldown. Every &lt;span class="caps"&gt;CVE&lt;/span&gt; that lands in the window requires someone to add a line. Nobody removes the lines later. Within a year the allow-list covers every security-critical package you have (i.e., exactly the ones the cooldown was supposed to protect), and the cooldown applies only to packages where it has no&amp;nbsp;upside.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Silence is not safety.&lt;/strong&gt; When a release is yanked, you want to know &lt;em&gt;now&lt;/em&gt;, because you probably already adopted it in prior weeks. A cooldown-based policy hides yanks until the window expires. You get neither warning nor&amp;nbsp;action.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;False security against the wrong threat model.&lt;/strong&gt; Cooldowns optimize for malicious-release attacks you probably mitigate via lockfile hashes, while ignoring account compromise, dependency confusion, transitive bad actors, and long-dwell attacks. The marketing matches the real threat landscape&amp;nbsp;poorly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Staleness tax compounds.&lt;/strong&gt; Over a year, an 8-day cooldown means every production service you ship is, on average, 4 days behind the ecosystem. Every bug fix, every performance improvement, every compatibility patch arrives late. None of that delay makes you safer; it just means you run older code continuously, forever, by&amp;nbsp;construction.&lt;/p&gt;
&lt;h2 id="8-when-cooldowns-actually-win"&gt;8. When cooldowns actually&amp;nbsp;win&lt;/h2&gt;
&lt;p&gt;Every model has a regime where its conclusion flips. Sweeping the total cost function from section 5 across cooldown windows at different risk&amp;nbsp;ratios &lt;span class="math"&gt;\(I_{\text{attack}} / I_{\text{cve}}\)&lt;/span&gt; reproduces the &lt;a href="https://gist.github.com/alexsavio/3cdf6f284614fd4ea4d7a2b865ec5249"&gt;simulation output&lt;/a&gt;:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;span class="math"&gt;\(I_{\text{attack}} / I_{\text{cve}}\)&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;Optimal &lt;span class="math"&gt;\(C\)&lt;/span&gt;&lt;/th&gt;
&lt;th&gt;What kind of service&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🟢 &lt;span class="math"&gt;\(10^2 - 10^4\)&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1 day&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;typical web service, internal tools, SaaS backend&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🟡 &lt;span class="math"&gt;\(10^5\)&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;14 days&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;high-value platform: fintech, identity, custodian&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🔴 &lt;span class="math"&gt;\(10^6\)&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;90 days&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;catastrophic-breach-class: payments, custodial crypto, critical infrastructure&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Read this as: a team that genuinely models one compromise as equivalent to &lt;strong&gt;100,000 &lt;span class="caps"&gt;CVE&lt;/span&gt;-days&lt;/strong&gt; of exposure should run a real cooldown. At that risk ratio, the 175-vuln-day tax is cheap insurance. For everyone else, it is&amp;nbsp;not.&lt;/p&gt;
&lt;p&gt;The&amp;nbsp;break-even &lt;span class="math"&gt;\(I_{\text{attack}} / I_{\text{cve}}\)&lt;/span&gt; for an 8-day cooldown under the default detection-delay mixture is approximately &lt;strong&gt;12,000&lt;/strong&gt;. Below that, no cooldown&amp;nbsp;(or &lt;span class="math"&gt;\(C \approx L\)&lt;/span&gt;) wins. Above it, cooldowns start to pay and should grow with the&amp;nbsp;stakes.&lt;/p&gt;
&lt;p&gt;Most teams are nowhere near 12,000. Estimate yours honestly before you&amp;nbsp;adopt.&lt;/p&gt;
&lt;h2 id="9-the-word-cooldown-needs-better-semantics"&gt;9. The word &amp;#8220;cooldown&amp;#8221; needs better&amp;nbsp;semantics&lt;/h2&gt;
&lt;p&gt;Part of the problem is that the term &amp;#8220;cooldown&amp;#8221; flattens at least eight distinct policies into one switch. Each has a different cost profile and a different threat model. Naming them separately turns a sterile debate about &amp;#8220;cooldowns yes/no&amp;#8221; into a design question about which filter you actually&amp;nbsp;want.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Flat pre-resolver cooldown.&lt;/strong&gt; The thing&amp;nbsp;uv&amp;#8217;s &lt;code&gt;exclude-newer&lt;/code&gt; ships today. Hides every release younger&amp;nbsp;than &lt;span class="math"&gt;\(C\)&lt;/span&gt; days from the resolver. Uniform window, uniform package set. This is what the rest of the post argues&amp;nbsp;against.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Audit-matched cooldown&lt;/strong&gt;&amp;nbsp;(&lt;span class="math"&gt;\(C = L\)&lt;/span&gt;). Set the cooldown equal to your audit latency. Zero &lt;span class="caps"&gt;CVE&lt;/span&gt; tax, catches the hours-class fast-yank attacks for free. The only version that is strictly non-harmful. Almost nobody configures this because it feels uselessly small. It&amp;nbsp;isn&amp;#8217;t.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Additions-only cooldown.&lt;/strong&gt; Apply the cooldown only to packages not already in your lockfile. The threat model the cooldown actually addresses is malicious &lt;em&gt;new&lt;/em&gt; adoption; upgrades of already-vetted packages are a different attack surface. This isolates the benefit without the &lt;span class="caps"&gt;CVE&lt;/span&gt; tax on upgrades. Needs tooling&amp;nbsp;support; &lt;code&gt;exclude-newer-package&lt;/code&gt; can fake it via inverted&amp;nbsp;allow-lists.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. Release-cadence-adaptive cooldown.&lt;/strong&gt; Window inversely proportional to recent release frequency. Packages that publish weekly have dense community traffic and short effective detection delays, so the cooldown contributes nothing and should be near zero. Packages that publish yearly have almost no community scrutiny, so the long-tail regime from section 4 applies and a longer window can matter. Addresses the long-dwell failure directly instead of picking one number for the whole dep&amp;nbsp;tree.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5. Canary cooldown&lt;/strong&gt; (fleet-staged adoption). Upgrade 10% of your fleet on day 1, the rest on&amp;nbsp;day &lt;span class="math"&gt;\(C\)&lt;/span&gt;. Compromises are detected by &lt;em&gt;your&lt;/em&gt; telemetry on the canary before the full rollout. This is just canary deployment applied to dependencies and it subsumes what a cooldown pretends to buy, because the detection signal is your actual traffic rather than community vigilance. Section 6 already argues this is a higher-fidelity&amp;nbsp;signal.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6. Advisory-aware cooldown&lt;/strong&gt; (the resolver fix). The deadlock in section 1 exists because the resolver and the auditor do not talk. An advisory-aware resolver polls the &lt;span class="caps"&gt;CVE&lt;/span&gt; database at resolve time and exempts any version that &lt;em&gt;fixes&lt;/em&gt; a listed vulnerability from the cooldown. The policy would read: &amp;#8220;hide fresh releases &lt;em&gt;unless&lt;/em&gt; the fresh release is a security patch.&amp;#8221; That is the only form of cooldown whose failure mode is not a guaranteed &lt;span class="caps"&gt;CVE&lt;/span&gt;-exposure extension. It does not exist in any mainstream Python resolver today. It should. If I had one practical ask of the uv team, it would be&amp;nbsp;this.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;7. Information-theoretic cooldown.&lt;/strong&gt; A cooldown is a bet that community inaction provides meaningful signal about package safety. Ask the prior question: &lt;em&gt;how many of the packages in your dep tree actually have a community watching?&lt;/em&gt; The top ~1,000 PyPI packages have eyes on them. The long tail does not. For a package with no community watchers, a cooldown provides exactly &lt;strong&gt;zero bits of information&lt;/strong&gt;, because the absence of a yank means nothing, since nobody would have yanked it anyway. An honest cooldown implementation would apply only to packages with a measurable watcher population (GitHub stars above a threshold, weekly downloads above a threshold, recent security-advisory activity) and skip the rest. Most dep trees would end up with a cooldown on maybe 50 packages, not&amp;nbsp;500.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A variant I originally listed and then cut&lt;/strong&gt;: &amp;#8220;differential cooldown by blast radius&amp;#8221;, where security-sensitive packages&amp;nbsp;get &lt;span class="math"&gt;\(C = 0\)&lt;/span&gt; and utility packages get a longer window. It sounds principled, but the end state is identical to the allow-list rot failure mode from section 7: the cooldown applies exactly where it has no upside and skips exactly where it would matter. Steelmanning it with &amp;#8220;utility packages have higher typosquat rates&amp;#8221; doesn&amp;#8217;t rescue it, because variant 2&amp;nbsp;(&lt;span class="math"&gt;\(C = L\)&lt;/span&gt;) already catches typosquats for free and your new-dep review (section 10) catches typosquat &lt;em&gt;additions&lt;/em&gt;. Freezing the rot pattern in configuration is still the rot&amp;nbsp;pattern.&lt;/p&gt;
&lt;p&gt;Options 2 through 7 are all strictly better than option 1 in at least one dimension, and some of them strictly dominate it. If your package manager shipped any of them instead of option 1, the argument in this post would be much narrower and the Astral practice much more defensible. The problem is that when a blog post, a config flag, or a pipeline template says &amp;#8220;cooldown&amp;#8221;, everyone reads option 1, and option 1 is the one that&amp;nbsp;loses.&lt;/p&gt;
&lt;h2 id="10-what-first-principles-actually-say"&gt;10. What first principles actually&amp;nbsp;say&lt;/h2&gt;
&lt;p&gt;Work the sequence of events again, but from the defender&amp;#8217;s perspective. You want each class of risk handled at the point in the pipeline where detection is cheapest and most&amp;nbsp;accurate.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Threat&lt;/th&gt;
&lt;th&gt;Best detection point&lt;/th&gt;
&lt;th&gt;Cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🔓 &lt;span class="caps"&gt;CVE&lt;/span&gt; fix needed&lt;/td&gt;
&lt;td&gt;as soon as disclosed&lt;/td&gt;
&lt;td&gt;🔍 audit on every resolve&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🐛 Latent bug / regression&lt;/td&gt;
&lt;td&gt;under your own traffic&lt;/td&gt;
&lt;td&gt;🧪 staging environment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🕷️ Fast-yank supply-chain attack&lt;/td&gt;
&lt;td&gt;at lock time, on new additions&lt;/td&gt;
&lt;td&gt;🔐 lockfile hashes + new-dep review&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🐚 Long-dwell supply-chain attack&lt;/td&gt;
&lt;td&gt;via advisory subscription and &lt;span class="caps"&gt;SBOM&lt;/span&gt; monitoring&lt;/td&gt;
&lt;td&gt;📡 targeted vigilance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;💥 Breaking change&lt;/td&gt;
&lt;td&gt;in &lt;span class="caps"&gt;CI&lt;/span&gt; against your integration tests&lt;/td&gt;
&lt;td&gt;✔️ tests&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Notice what&amp;#8217;s missing from this table: &lt;strong&gt;a time window during which the resolver pretends new versions do not exist.&lt;/strong&gt; That policy does not appear in any row because no row benefits from it. Every legitimate concern has a better&amp;nbsp;home.&lt;/p&gt;
&lt;p&gt;The operational rules that fall&amp;nbsp;out:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Lockfiles with hashes, always.&lt;/strong&gt; This is the supply-chain defense that actually works.&amp;nbsp;Use &lt;code&gt;uv sync --locked&lt;/code&gt; or &lt;code&gt;--frozen&lt;/code&gt; in &lt;span class="caps"&gt;CI&lt;/span&gt; and deploy paths&lt;sup id="fnref:uv-sync-flags"&gt;&lt;a class="footnote-ref" href="#fn:uv-sync-flags"&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Audit on every resolve, block on &lt;span class="caps"&gt;HIGH&lt;/span&gt;/&lt;span class="caps"&gt;CRITICAL&lt;/span&gt;.&lt;/strong&gt;&amp;nbsp;Drives &lt;code&gt;audit_latency&lt;/code&gt; to one&amp;nbsp;cycle.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Upgrade frequently.&lt;/strong&gt;&amp;nbsp;Short &lt;code&gt;N&lt;/code&gt; between &lt;span class="caps"&gt;CVE&lt;/span&gt; disclosure and your patch. Frequency is safety, not&amp;nbsp;risk.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Staging bake for regression detection.&lt;/strong&gt; Your traffic beats community traffic for your workload. This is the same &amp;#8220;recovery beats prevention&amp;#8221; logic that falls out of &lt;a href="https://alexsavio.github.io/first-principles-devops.html"&gt;first principles in devops&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Manual review on new dependencies only.&lt;/strong&gt; Upgrades of existing deps are a small attack surface. Additions are the hot&amp;nbsp;spot.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Subscribe to advisories for critical-path packages.&lt;/strong&gt; Ten packages, maybe. Targeted vigilance is cheap and has no deadlock&amp;nbsp;cost.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pin manually when you truly need to be paranoid about one package.&lt;/strong&gt; Surgical. No collateral damage. No allow-list&amp;nbsp;rot.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A team I work with recently ripped out an 8-day flat cooldown from a Python monorepo and replaced it&amp;nbsp;with &lt;code&gt;pip-audit&lt;/code&gt; on every &lt;span class="caps"&gt;PR&lt;/span&gt; plus &lt;span class="caps"&gt;CODEOWNERS&lt;/span&gt; review on&amp;nbsp;any &lt;code&gt;pyproject.toml&lt;/code&gt; edit. The deadlock stopped recurring, &lt;span class="caps"&gt;CVE&lt;/span&gt; fixes now ship same-day, and the human-review budget landed on the one surface that actually matters: new&amp;nbsp;dependencies.&lt;/p&gt;
&lt;p&gt;These rules are scoped by the caveat in section 8. At high enough stakes, you should layer one of the smarter variants from section 9 on top; at typical stakes, the rules above are the whole&amp;nbsp;answer.&lt;/p&gt;
&lt;h2 id="11-summary"&gt;11.&amp;nbsp;Summary&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;✅ Pros of cooldowns&lt;/th&gt;
&lt;th&gt;❌ Cons of cooldowns&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;✅ Catches fast-yank supply-chain attacks in a narrow window&lt;/td&gt;
&lt;td&gt;❌ Guarantees extended &lt;span class="caps"&gt;CVE&lt;/span&gt; exposure every time a fix lands&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;✅ Trivial to enable&lt;/td&gt;
&lt;td&gt;❌ Deadlocks with every live-&lt;span class="caps"&gt;DB&lt;/span&gt; vulnerability scanner&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;✅ Supported in most package managers&lt;/td&gt;
&lt;td&gt;❌ Cannot be overridden by user version constraints&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;✅ Feels cautious&lt;/td&gt;
&lt;td&gt;❌ Per-package allow-lists accumulate permanently&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;❌ Hides yank signals during the window&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;❌ Wrong threat model: protects against a narrow band that lockfiles + review already cover&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;❌ Silently delays every improvement, 100% of the time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;❌ Confuses novelty with risk&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The flat pre-resolver cooldown that today&amp;#8217;s package managers ship optimizes for the wrong point in the pipeline, against the wrong threat model, at the cost of a certain and recurring operational debt. The real defense is layered: fast audits in &lt;span class="caps"&gt;CI&lt;/span&gt;, tight lockfiles with hashes, a staging bake against your own traffic, and manual review on the narrow surface where it pays, new dependencies. Once those layers exist, flat cooldowns add nothing but delay at typical risk ratios. If you need more than that, reach for one of the smarter variants in section 9, canary rollouts or advisory-aware resolvers before flat windows. Caution should be cheap when the thing you are cautious about is bad, and free when it is good. Flat cooldowns are instead expensive every day, in exchange for a contingent payoff that, for most services, the math cannot justify. If a policy makes you feel safer every day while making you measurably less safe every week, retire it and replace it with one that actually&amp;nbsp;pays.&lt;/p&gt;
&lt;p&gt;Adopt fast. Verify hard. Buffer&amp;nbsp;late.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/alexsavio/3cdf6f284614fd4ea4d7a2b865ec5249"&gt;Simulation&amp;nbsp;gist: &lt;code&gt;simulate_dependency_cooldown.py&lt;/code&gt; + output&lt;/a&gt;. Companion Python script backing every number in this post, plus the captured run output. Reproduce or challenge the results&amp;nbsp;end-to-end.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://astral.sh/blog/open-source-security-at-astral"&gt;Open source security at Astral&lt;/a&gt;, William Woodruff, April 2026. The original post this analysis responds&amp;nbsp;to.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.astral.sh/uv/reference/settings/#exclude-newer"&gt;uv: &lt;code&gt;exclude-newer&lt;/code&gt; documentation&lt;/a&gt;. The cooldown mechanism analyzed in this&amp;nbsp;post.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/pypa/pip-audit"&gt;pip-audit&lt;/a&gt;. Live advisory &lt;span class="caps"&gt;DB&lt;/span&gt; auditor referenced in the deadlock&amp;nbsp;example.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/dominictarr/event-stream/issues/116"&gt;event-stream incident (2018)&lt;/a&gt;. Canonical medium-dwell account-compromise supply-chain&amp;nbsp;attack.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cve.org/CVERecord?id=CVE-2024-3094"&gt;xz-utils backdoor (&lt;span class="caps"&gt;CVE&lt;/span&gt;-2024-3094)&lt;/a&gt;. Long-dwell supply-chain attack no cooldown could&amp;nbsp;catch.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-devops.html"&gt;First Principles: DevOps&lt;/a&gt;. Related post on why feedback loops and recovery beat prevention in operational&amp;nbsp;systems.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="footnote"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:uv-sync-flags"&gt;
&lt;p&gt;&lt;code&gt;--locked&lt;/code&gt; errors&amp;nbsp;if &lt;code&gt;uv.lock&lt;/code&gt; is out of sync&amp;nbsp;with &lt;code&gt;pyproject.toml&lt;/code&gt;, catching the case where someone edits a dependency and forgets to&amp;nbsp;re-lock. &lt;code&gt;--frozen&lt;/code&gt; goes further: installs exactly what the lockfile says and never&amp;nbsp;reads &lt;code&gt;pyproject.toml&lt;/code&gt; at all, so the deploy path is fully deterministic. A&amp;nbsp;bare &lt;code&gt;uv sync&lt;/code&gt; is fine for local development because &lt;a href="https://docs.astral.sh/uv/concepts/projects/sync/#automatic-lock-and-sync"&gt;uv does not consider a lockfile outdated just because new versions shipped upstream&lt;/a&gt;; the lockfile stays stable until someone explicitly&amp;nbsp;runs &lt;code&gt;uv lock --upgrade&lt;/code&gt;.&amp;#160;&lt;a class="footnote-backref" href="#fnref:uv-sync-flags" title="Jump back to footnote 1 in the text"&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;script type="text/javascript"&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Engineering"/><category term="first-principles"/><category term="python"/><category term="security"/><category term="dependencies"/><category term="supply-chain"/><category term="devops"/></entry><entry><title>First Principles: Distributed Systems (Most of Yours Should Not Exist)</title><link href="https://alexsavio.github.io/first-principles-distributed-systems.html" rel="alternate"/><published>2026-04-09T18:00:00+02:00</published><updated>2026-04-09T18:00:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2026-04-09:/first-principles-distributed-systems.html</id><summary type="html">&lt;p&gt;Distributed systems thinking is drowning in inherited wisdom — microservices by default, horizontal scaling as a reflex, eventual consistency as a catchphrase. Strip it down to six irreducible truths and most of that architectural baggage falls away. The uncomfortable conclusion: the first, cheapest, most reliable distributed system is the one you did not&amp;nbsp;build.&lt;/p&gt;</summary><content type="html">&lt;h2 id="tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;Distributed systems thinking is drowning in inherited wisdom: microservices by default, horizontal scaling as a reflex, eventual consistency as a catchphrase. Strip the topic down to its irreducible truths, the six things that are actually provable, and most of that architectural baggage falls away. The uncomfortable conclusion: the first, cheapest, most reliable distributed system is the one you did not build. Everything else is a tax you should only pay when you can prove it buys you&amp;nbsp;something.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;This is the fifth post in my First Principles series, where I take a concept the industry treats as settled and strip it back to what&amp;#8217;s actually provable. Previous entries: &lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;Software Observability&lt;/a&gt;, &lt;a href="https://alexsavio.github.io/first-principles-software-design.html"&gt;Software Design&lt;/a&gt;, &lt;a href="https://alexsavio.github.io/first-principles-devops.html"&gt;DevOps&lt;/a&gt;, and &lt;a href="https://alexsavio.github.io/first-principles-data-engineering.html"&gt;Data Engineering&lt;/a&gt;. Distributed systems felt like the right next target because few topics have a wider gap between what engineers repeat and what they&amp;#8217;ve actually&amp;nbsp;measured.&lt;/em&gt;&lt;/p&gt;
&lt;div class="toc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-conventional-view"&gt;The Conventional&amp;nbsp;View&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-people-just-assume"&gt;What People Just&amp;nbsp;Assume&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-actually-survives-scrutiny"&gt;What Actually Survives&amp;nbsp;Scrutiny&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-falls-away"&gt;What Falls&amp;nbsp;Away&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#rebuilt-from-scratch"&gt;Rebuilt From&amp;nbsp;Scratch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-changes-when-you-think-this-way"&gt;What Changes When You Think This&amp;nbsp;Way&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#when-you-actually-need-distribution"&gt;When You Actually Need&amp;nbsp;Distribution&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-honest-architectural-test"&gt;The Honest Architectural&amp;nbsp;Test&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#references"&gt;References&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id="the-conventional-view"&gt;The Conventional&amp;nbsp;View&lt;/h2&gt;
&lt;p&gt;Ask any backend engineer how to scale a system and the answer comes out reflexively: split the work across nodes, replicate for reliability, reach for consensus when you need agreement, accept that complexity is the price of scale. &lt;em&gt;&amp;#8220;You need a distributed system&amp;#8221;&lt;/em&gt; has quietly become the default answer for any non-trivial backend. Microservices are &amp;#8220;modern&amp;#8221;. A monolith is &amp;#8220;legacy&amp;#8221;. Kubernetes is table&amp;nbsp;stakes.&lt;/p&gt;
&lt;p&gt;This post is not about how to build a better service mesh. It is about whether you should be building one at all, and what distributed systems look like when you stop copying the architecture of a company 1,000× your size and reason forward from the things that are actually&amp;nbsp;true.&lt;/p&gt;
&lt;h2 id="what-people-just-assume"&gt;What People Just&amp;nbsp;Assume&lt;/h2&gt;
&lt;p&gt;Before you can tear something down, you have to name the inherited thinking. Here are the beliefs most engineers carry into distributed systems without ever having checked&amp;nbsp;them:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Assumption&lt;/th&gt;
&lt;th&gt;Where it came from&lt;/th&gt;
&lt;th&gt;Verdict&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;You need a distributed system to scale&lt;/td&gt;
&lt;td&gt;SaaS-era orthodoxy, &lt;span class="caps"&gt;FAANG&lt;/span&gt; blog posts&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Microservices are the modern way&lt;/td&gt;
&lt;td&gt;Netflix and Uber conference talks&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;The network is reliable most of the time&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;LAN&lt;/span&gt; intuition, local dev&lt;/td&gt;
&lt;td&gt;Baggage (Fallacy #1)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Latency between services is negligible&lt;/td&gt;
&lt;td&gt;Same-datacenter hand-waving&lt;/td&gt;
&lt;td&gt;Baggage (Fallacy #2)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Consensus protocols are required for correctness&lt;/td&gt;
&lt;td&gt;Coursework memory&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;CAP&lt;/span&gt; forces a binary &lt;span class="caps"&gt;CP&lt;/span&gt; vs &lt;span class="caps"&gt;AP&lt;/span&gt; choice&lt;/td&gt;
&lt;td&gt;Pop-sci reading of Brewer&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;Eventually consistent is good enough&lt;/td&gt;
&lt;td&gt;DynamoDB and Cassandra marketing&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;More nodes equals more reliability&lt;/td&gt;
&lt;td&gt;Replication intuition&lt;/td&gt;
&lt;td&gt;Heuristic (often inverted)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;Clocks across machines can be trusted with some slop&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;NTP&lt;/span&gt; familiarity&lt;/td&gt;
&lt;td&gt;Baggage (Fallacy #6)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;Partial failure is an edge case&lt;/td&gt;
&lt;td&gt;Single-machine mental model&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The point of that table is not contrarianism. It is compression. Most of what engineers treat as &amp;#8220;distributed systems knowledge&amp;#8221; is a mix of convention dressed up as constraint and heuristics borrowed from companies operating at a scale you do not&amp;nbsp;have.&lt;/p&gt;
&lt;h2 id="what-actually-survives-scrutiny"&gt;What Actually Survives&amp;nbsp;Scrutiny&lt;/h2&gt;
&lt;p&gt;Six things remain once you strip the heuristics and the baggage. These are irreducible, true regardless of era, stack, or cloud&amp;nbsp;provider.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. The network is not a reliable communication medium.&lt;/strong&gt; Packets are dropped, reordered, duplicated, and delayed. This is a property of shared infrastructure and the speed of light, not a bug you can engineer around. Every message you send may or may not arrive, may arrive late, and may arrive more than&amp;nbsp;once.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. You cannot distinguish a crashed node from a slow one.&lt;/strong&gt; This is the famous &lt;span class="caps"&gt;FLP&lt;/span&gt; impossibility result in plain clothes. No timeout is &amp;#8220;correct&amp;#8221;. You are always choosing between declaring live nodes dead (false positive) and waiting forever on dead ones (false&amp;nbsp;negative).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. There is no global now.&lt;/strong&gt; Independent clocks drift. &lt;span class="caps"&gt;NTP&lt;/span&gt; bounds the drift but does not eliminate it. Two events on two machines cannot be totally ordered without a protocol, and every protocol costs round&amp;nbsp;trips.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. Every coordination step costs at least one round trip.&lt;/strong&gt; Round trips do not compose. They add up linearly in your latency budget and explode non-linearly under&amp;nbsp;failure.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5. Failure modes multiply, they do not add.&lt;/strong&gt; One machine at 99.9% uptime is straightforward. &lt;em&gt;N&lt;/em&gt; machines each at 99.9% uptime gives you a failure probability that approaches certainty as &lt;em&gt;N&lt;/em&gt; grows. Redundancy only helps if the failures are genuinely independent and the coordination layer is not itself the&amp;nbsp;bottleneck.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6. State is the hard part, compute is trivial.&lt;/strong&gt; Moving code across nodes is easy: it is just bytes. Moving or sharing state is where every hard problem lives: consistency, ordering, replication,&amp;nbsp;recovery.&lt;/p&gt;
&lt;p&gt;That is the whole bedrock. Six statements. Notice what is &lt;em&gt;not&lt;/em&gt; on the list: microservices, Kubernetes, consensus, eventual consistency, horizontal scaling. None of those are fundamental. They are tools, patterns, or rebrandings of organizational&amp;nbsp;choices.&lt;/p&gt;
&lt;h2 id="what-falls-away"&gt;What Falls&amp;nbsp;Away&lt;/h2&gt;
&lt;p&gt;Once you stop at &amp;#8220;only what is provably true&amp;#8221;, the conventional architecture advice starts looking&amp;nbsp;suspicious.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;You need a distributed system to scale.&amp;#8221;&lt;/strong&gt; A modern single machine has 128+ cores, terabytes of &lt;span class="caps"&gt;RAM&lt;/span&gt;, and NVMe pushing millions of &lt;span class="caps"&gt;IOPS&lt;/span&gt;. A well-written monolith on one big box handles workloads that teams reflexively shard across Kubernetes clusters. The assumption persisted because cloud vendors sell horizontal, not vertical, and because it justified résumé-driven&amp;nbsp;architecture.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Microservices are the modern way.&amp;#8221;&lt;/strong&gt; Microservices were an &lt;em&gt;organisational&lt;/em&gt; answer to having thousands of engineers at Netflix and Amazon, and the answer got rebranded as a &lt;em&gt;technical&lt;/em&gt; pattern. For teams of 5 to 50, you trade a tractable problem (one codebase) for an intractable one (&lt;em&gt;N&lt;/em&gt; codebases communicating over an unreliable&amp;nbsp;network).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Partial failure is an edge case.&amp;#8221;&lt;/strong&gt; In a real distributed system, something is always failing. It is steady state, not exception. The assumption persists because single-machine intuition treats &amp;#8220;up&amp;#8221; and &amp;#8220;down&amp;#8221; as binary. Distributed systems do&amp;nbsp;not.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;More nodes equals more reliability.&amp;#8221;&lt;/strong&gt; Only if the nodes fail independently &lt;em&gt;and&lt;/em&gt; the coordination layer is itself more reliable than a single node. In practice, adding nodes often &lt;em&gt;decreases&lt;/em&gt; reliability because the blast radius of a bad deploy, a misconfigured network policy, or a coordination bug grows with &lt;em&gt;N&lt;/em&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;&lt;span class="caps"&gt;CAP&lt;/span&gt; forces a binary choice.&amp;#8221;&lt;/strong&gt; &lt;span class="caps"&gt;CAP&lt;/span&gt; describes what happens &lt;em&gt;during a partition&lt;/em&gt;. Most systems are not partitioned most of the time. The real tradeoff every day is latency vs. consistency (&lt;span class="caps"&gt;PACELC&lt;/span&gt;), and blast-radius vs. coordination&amp;nbsp;cost.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="rebuilt-from-scratch"&gt;Rebuilt From&amp;nbsp;Scratch&lt;/h2&gt;
&lt;p&gt;If you only started from the six truths and never heard of Kubernetes, this is what you would&amp;nbsp;design.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default to one machine.&lt;/strong&gt; The cheapest, fastest, most reliable distributed system is the one you did not build. Scale vertically until the machine itself is the bottleneck, not until your conference talk demands horizontal scaling. A single node has zero coordination cost, zero network unreliability, one clock, and trivially consistent&amp;nbsp;state.&lt;/p&gt;
&lt;p&gt;And &amp;#8220;one machine&amp;#8221; in 2026 is not what it was in 2012. An &lt;span class="caps"&gt;AWS&lt;/span&gt; &lt;code&gt;m7i.48xlarge&lt;/code&gt; gives you 192 vCPUs, 768 GiB of &lt;span class="caps"&gt;RAM&lt;/span&gt;, and 50 Gbps of network. If you need to go&amp;nbsp;further, &lt;code&gt;u7in-32tb.224xlarge&lt;/code&gt; offers 896 vCPUs and 32 TiB of &lt;span class="caps"&gt;RAM&lt;/span&gt;, enough to hold almost any &lt;span class="caps"&gt;OLTP&lt;/span&gt; working set entirely in memory. Most teams have never done the math on what actually fits on a single box because they never considered it an option. That is the assumption talking, not the&amp;nbsp;hardware.&lt;/p&gt;
&lt;p&gt;Stack Overflow is the steelman for this whole argument. For years one of the top-100 websites on the internet, hovering in the top 50 on Alexa at its peak, ran on a handful of servers. Nick Craver&amp;#8217;s 2016 architecture post is explicit: 9 active &lt;span class="caps"&gt;IIS&lt;/span&gt; web servers (11 total), a .&lt;span class="caps"&gt;NET&lt;/span&gt; monolith serving every Q&amp;amp;A site from a single application, two &lt;span class="caps"&gt;SQL&lt;/span&gt; Server clusters on Dell R720xd boxes with 384 &lt;span class="caps"&gt;GB&lt;/span&gt; of &lt;span class="caps"&gt;RAM&lt;/span&gt; and 4 &lt;span class="caps"&gt;TB&lt;/span&gt; of PCIe &lt;span class="caps"&gt;SSD&lt;/span&gt;, Dapper as the &lt;span class="caps"&gt;ORM&lt;/span&gt;, and exactly one stored procedure in the entire database. Question pages averaged 22.71 ms to render. The homepage averaged 11.80 ms. That setup handled around 209 million &lt;span class="caps"&gt;HTTP&lt;/span&gt; requests per day. No Kubernetes. No service mesh. No eventual consistency. A monolith, a big database, and people who understood both. The reason that story feels exotic is that the industry stopped treating it as the default, not that it stopped&amp;nbsp;working.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When you must distribute, distribute along natural boundaries of independence.&lt;/strong&gt; The only honest reason to cross a network boundary is that the work on the other side is &lt;em&gt;genuinely independent&lt;/em&gt;: different users, different shards, different geographies. Services that talk to each other on every request should live in the same&amp;nbsp;process.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Make coordination explicit and rare.&lt;/strong&gt; Every round trip has a cost. Design systems where the hot path is coordination-free (local reads, local writes, local compute) and coordination happens only at boundaries: checkpoints, commits, cross-shard operations. The goal is not &amp;#8220;eventually consistent&amp;#8221;. It is &amp;#8220;locally authoritative, rarely&amp;nbsp;coordinated&amp;#8221;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Treat partial failure as steady state.&lt;/strong&gt; Instead of exception handling bolted onto a success path, model the system as a state machine where every message is &amp;#8220;maybe delivered, maybe duplicated, maybe late&amp;#8221;. Idempotency and at-least-once delivery become the contract, not the&amp;nbsp;workaround.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use time as a budget, not a clock.&lt;/strong&gt; Do not ask &amp;#8220;what time is it?&amp;#8221;. Ask &amp;#8220;how long am I willing to wait before assuming failure?&amp;#8221;. Every operation has a deadline. Every deadline is a choice between false-positive and false-negative failure detection. Make that choice explicit per&amp;nbsp;call-site.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Keep state small and local. Keep compute mobile.&lt;/strong&gt; The worst architecture is one where both compute and state are distributed and both are mobile. Every operation pays the round-trip tax and the coordination tax at&amp;nbsp;once.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Measure everything in round trips, not milliseconds.&lt;/strong&gt; &amp;#8220;This request does 14 round trips&amp;#8221; tells you more than &amp;#8220;this request takes 200ms&amp;#8221;, because round trips compose under failure and milliseconds do&amp;nbsp;not.&lt;/p&gt;
&lt;p&gt;Here is what coordination cost looks like when you map it visually instead of hiding it inside a latency graph. Every arrow is one round trip&amp;nbsp;(&lt;code&gt;1 RT&lt;/code&gt;); the client that pays the latency is highlighted in blue, the single source of truth the whole chain revolves around is highlighted in&amp;nbsp;red.&lt;/p&gt;
&lt;pre class="mermaid"&gt;
flowchart LR
    classDef client fill:#1e66f5,color:#ffffff,stroke:#1e4ed8,stroke-width:2px;
    classDef db fill:#d20f39,color:#ffffff,stroke:#a30826,stroke-width:2px;
    A[Client]:::client --&gt;|1 RT| B[API Gateway]
    B --&gt;|1 RT| C[Auth Service]
    B --&gt;|1 RT| D[User Service]
    D --&gt;|1 RT| E[Profile Service]
    D --&gt;|1 RT| F[Cache]
    E --&gt;|1 RT| G[Postgres]:::db
    B --&gt;|1 RT| H[Analytics]
    H --&gt;|1 RT| I[Kafka]
    I --&gt;|1 RT| J[Warehouse]
&lt;/pre&gt;

&lt;p&gt;Nine round trips for one logical request. Half of them exist because somebody wanted a microservice on their résumé. This is the picture you should draw for every request path in your system. Most teams have never drawn&amp;nbsp;it.&lt;/p&gt;
&lt;h2 id="what-changes-when-you-think-this-way"&gt;What Changes When You Think This&amp;nbsp;Way&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Vertical scaling stops being a dirty word.&lt;/strong&gt; The first question is not &amp;#8220;how do we shard?&amp;#8221;. It is &amp;#8220;what does this look like on one very large machine with good&amp;nbsp;observability?&amp;#8221;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Microservices become a last resort, not a first instinct.&lt;/strong&gt; You adopt them when the team structure demands it (Conway&amp;#8217;s Law) or when you have genuinely independent&amp;nbsp;workloads.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Eventually consistent&amp;#8221; becomes suspect.&lt;/strong&gt; It is often a euphemism for &amp;#8220;we gave up on defining the semantics&amp;#8221;. If you cannot answer &lt;em&gt;&amp;#8220;eventually, bounded by what?&amp;#8221;&lt;/em&gt;, you do not have a consistency model. You have a&amp;nbsp;hope.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Database-as-coordinator becomes respectable again.&lt;/strong&gt; A single Postgres with boring replication is a better substrate for most systems than a mesh of microservices plus Kafka plus a service registry plus a distributed tracer to debug why any of it&amp;nbsp;works.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consensus protocols become specialised tools.&lt;/strong&gt; You use Raft when you genuinely need a linearizable log. You do not build every service on top of&amp;nbsp;one.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Eli Bendersky&amp;#8217;s &lt;a href="https://eli.thegreenplace.net/2020/implementing-raft-part-0-introduction/"&gt;Raft implementation series&lt;/a&gt; makes this point in plain language: Raft is &amp;#8220;much better suited for coarse-grained distributed primitives, like implementing a lock server, electing leaders for higher-level protocols, replicating critical configuration data&amp;#8221;. Not for user-facing transactional workloads. Not for the hot path of your &lt;span class="caps"&gt;API&lt;/span&gt;. Every Raft round trip writes to durable storage on a majority of replicas before a client hears back. That is the right price for etcd and Kubernetes coordination. It is the wrong price for&amp;nbsp;your &lt;code&gt;/users/profile&lt;/code&gt; endpoint.&lt;/p&gt;
&lt;p&gt;The complexity tax becomes visible. Most teams pay it and get nothing back because their workload never needed distribution in the first&amp;nbsp;place.&lt;/p&gt;
&lt;h2 id="when-you-actually-need-distribution"&gt;When You Actually Need&amp;nbsp;Distribution&lt;/h2&gt;
&lt;p&gt;To be fair to the other side: distribution is sometimes the right answer. Here are the only honest triggers. If none of them apply, you are paying the tax for no&amp;nbsp;reason.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Your working set does not fit on one machine.&lt;/strong&gt; Your database plus hot cache plus in-flight state cannot physically live on a single node, even a very large one. This is rarer than people think once you actually do the&amp;nbsp;arithmetic.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Your compute budget does not fit on one machine.&lt;/strong&gt; &lt;span class="caps"&gt;CPU&lt;/span&gt; or &lt;span class="caps"&gt;GPU&lt;/span&gt; demand genuinely exceeds what a single box can deliver, and the work parallelises cleanly. Training a large model is the canonical example. Serving a &lt;span class="caps"&gt;CRUD&lt;/span&gt; &lt;span class="caps"&gt;API&lt;/span&gt; is&amp;nbsp;not.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;You need geographic distribution.&lt;/strong&gt; Users in multiple regions, latency budgets that require presence near the user, or data residency laws that forbid a single location. This is the most common legitimate driver, and it is a policy or physics problem, not a scale&amp;nbsp;problem.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Your organisation genuinely requires independent deploys.&lt;/strong&gt; Conway&amp;#8217;s Law made flesh: multiple teams that must ship on independent cadences without coordinating every release. This is an organisational trigger, not a technical one, and it should be named as&amp;nbsp;such.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Notice what is &lt;em&gt;not&lt;/em&gt; on the list: &amp;#8220;we want to learn Kubernetes&amp;#8221;, &amp;#8220;everyone else is doing microservices&amp;#8221;, &amp;#8220;the architect diagram will look impressive in the design review&amp;#8221;. Those are not engineering reasons. Those are social reasons dressed up as engineering&amp;nbsp;ones.&lt;/p&gt;
&lt;h2 id="the-honest-architectural-test"&gt;The Honest Architectural&amp;nbsp;Test&lt;/h2&gt;
&lt;p&gt;Before your next design review, try one exercise. Draw your current architecture on a whiteboard. Then delete half the boxes, any half, and ask: &lt;em&gt;&amp;#8220;what survives, and was the rest worth the coordination cost?&amp;#8221;&lt;/em&gt; If the answer is &amp;#8220;most of the value survives&amp;#8221;, the boxes you just deleted were baggage, not&amp;nbsp;architecture.&lt;/p&gt;
&lt;p&gt;Distributed systems are not a badge of sophistication. They are an expensive last resort with well-understood failure modes and a coordination cost that grows faster than the benefit for most workloads. The engineers who ship boring, single-machine systems and scale them for years are not behind the curve. They are the ones who read the curve carefully and decided not to buy into somebody else&amp;#8217;s scaling&amp;nbsp;story.&lt;/p&gt;
&lt;p&gt;First principles thinking is not about rejecting everything popular. It is about refusing to pay for complexity you cannot justify. Next time someone on your team says &amp;#8220;we need to split this into services&amp;#8221;, ask them which of the six fundamentals forced that decision. If they cannot answer, you just found a box to&amp;nbsp;delete.&lt;/p&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing"&gt;Fallacies of Distributed Computing&lt;/a&gt;. Peter Deutsch&amp;#8217;s original list, still&amp;nbsp;correct.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://groups.csail.mit.edu/tds/papers/Lynch/jacm85.pdf"&gt;Impossibility of Distributed Consensus with One Faulty Process (&lt;span class="caps"&gt;FLP&lt;/span&gt;)&lt;/a&gt;. Fischer, Lynch, Paterson,&amp;nbsp;1985.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/1509.05393"&gt;A Critique of the &lt;span class="caps"&gt;CAP&lt;/span&gt; Theorem&lt;/a&gt;. Martin Kleppmann,&amp;nbsp;2015.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/PACELC_theorem"&gt;&lt;span class="caps"&gt;PACELC&lt;/span&gt;&lt;/a&gt;. Abadi&amp;#8217;s extension to &lt;span class="caps"&gt;CAP&lt;/span&gt; that captures the latency-consistency&amp;nbsp;tradeoff.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://eli.thegreenplace.net/2020/implementing-raft-part-0-introduction/"&gt;Implementing Raft: Part 0 — Introduction&lt;/a&gt;. Eli Bendersky on where Raft fits and where it does&amp;nbsp;not.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nickcraver.com/blog/2016/02/17/stack-overflow-the-architecture-2016-edition/"&gt;Stack Overflow: The Architecture — 2016 Edition&lt;/a&gt;. Nick Craver&amp;#8217;s server counts, render times, and &lt;span class="caps"&gt;SQL&lt;/span&gt; Server&amp;nbsp;setup.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;First Principles: Software Observability&lt;/a&gt;. Part 1 of this&amp;nbsp;series.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-software-design.html"&gt;First Principles: Software Design&lt;/a&gt;. Part 2 of this&amp;nbsp;series.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-devops.html"&gt;First Principles: DevOps&lt;/a&gt;. Part 3 of this&amp;nbsp;series.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-data-engineering.html"&gt;First Principles: Data Engineering and ETLs&lt;/a&gt;. Part 4 of this&amp;nbsp;series.&lt;/li&gt;
&lt;/ol&gt;</content><category term="Engineering"/><category term="first-principles"/><category term="distributed-systems"/><category term="architecture"/><category term="microservices"/><category term="scalability"/><category term="backend"/></entry><entry><title>First Principles: Data Engineering and ETLs</title><link href="https://alexsavio.github.io/first-principles-data-engineering.html" rel="alternate"/><published>2026-04-08T20:58:00+02:00</published><updated>2026-04-08T20:58:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2026-04-08:/first-principles-data-engineering.html</id><summary type="html">&lt;p&gt;&lt;span class="caps"&gt;ETL&lt;/span&gt; is not a law of nature, it is a convention born from constraints that no longer exist. Strip data engineering down to its irreducible truths and rebuild it from scratch. What emerges is a discipline centered on contracts and observability, not pipelines and&amp;nbsp;orchestrators.&lt;/p&gt;</summary><content type="html">&lt;h2 id="tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;Most of what we call &amp;#8220;data engineering&amp;#8221; is a set of conventions inherited from an era of expensive compute and scarce storage. When you strip it down to first principles, only five truths survive: producers and consumers operate in different contexts, data must cross boundaries, semantic alignment is unavoidable, computation trades off time against money against complexity, and data without provenance is unreliable. Everything else, from the sacred &lt;span class="caps"&gt;ETL&lt;/span&gt; ordering to the &amp;#8220;collect everything&amp;#8221; data lake mentality, is implementation detail that should be&amp;nbsp;questioned.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;This is the fourth post in my First Principles series, where I take a concept the industry treats as settled and strip it back to what&amp;#8217;s provably true. The first one tackled &lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;Software Observability&lt;/a&gt;, the second &lt;a href="https://alexsavio.github.io/first-principles-software-design.html"&gt;Software Design&lt;/a&gt;, and the third &lt;a href="https://alexsavio.github.io/first-principles-devops.html"&gt;DevOps&lt;/a&gt;. Data engineering is the next natural target, because few disciplines have calcified around tooling as fast as this&amp;nbsp;one.&lt;/em&gt;&lt;/p&gt;
&lt;div class="toc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-conventional-view"&gt;The Conventional&amp;nbsp;View&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-assumptions-we-carry"&gt;The Assumptions We Carry&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#when-the-heuristics-break"&gt;When the heuristics&amp;nbsp;break&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-survives-scrutiny"&gt;What Survives Scrutiny&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#1-producers-and-consumers-operate-in-different-contexts"&gt;1. Producers and consumers operate in different&amp;nbsp;contexts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#2-data-must-cross-context-boundaries"&gt;2. Data must cross context&amp;nbsp;boundaries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#3-semantic-alignment-is-unavoidable"&gt;3. Semantic alignment is&amp;nbsp;unavoidable&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#4-computation-trades-off-time-money-and-complexity"&gt;4. Computation trades off time, money, and&amp;nbsp;complexity&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#5-data-without-provenance-is-unreliable"&gt;5. Data without provenance is&amp;nbsp;unreliable&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-airflow-cargo-cult"&gt;The Airflow Cargo&amp;nbsp;Cult&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-falls-away"&gt;What Falls Away&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#etl-as-the-defining-paradigm"&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;&lt;span class="caps"&gt;ETL&lt;/span&gt;&amp;#8221; as the defining&amp;nbsp;paradigm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#more-data-is-better"&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;More data is&amp;nbsp;better&amp;#8221;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#data-engineers-build-analysts-consume"&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Data engineers build, analysts&amp;nbsp;consume&amp;#8221;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#batch-is-default-streaming-is-special"&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Batch is default, streaming is&amp;nbsp;special&amp;#8221;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#rebuilt-from-scratch"&gt;Rebuilt From Scratch&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#start-with-data-contracts-not-pipelines"&gt;Start with data contracts, not&amp;nbsp;pipelines&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-pipeline-is-a-consequence-not-the-product"&gt;The pipeline is a consequence, not the&amp;nbsp;product&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#transform-at-the-boundary-not-in-a-dedicated-layer"&gt;Transform at the boundary, not in a dedicated&amp;nbsp;layer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#observe-data-dont-just-test-it"&gt;Observe data, don&amp;#8217;t just test&amp;nbsp;it&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#collect-data-when-you-can-articulate-who-will-use-it"&gt;Collect data when you can articulate who will use&amp;nbsp;it&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#make-lineage-and-freshness-first-class"&gt;Make lineage and freshness&amp;nbsp;first-class&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-tooling-is-catching-up"&gt;The Tooling Is Catching&amp;nbsp;Up&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#smell-test-are-you-carrying-baggage"&gt;Smell Test: Are You Carrying&amp;nbsp;Baggage?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-changes"&gt;What&amp;nbsp;Changes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#implications"&gt;Implications&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#references"&gt;References&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id="the-conventional-view"&gt;The Conventional&amp;nbsp;View&lt;/h2&gt;
&lt;p&gt;Data engineering is about building &lt;strong&gt;pipelines&lt;/strong&gt; that Extract data from sources, Transform it into a usable shape, and Load it into a destination (usually a warehouse). Teams invest heavily in orchestrators like Airflow, maintain complex DAGs, enforce strict schemas, and treat the warehouse as the single source of&amp;nbsp;truth.&lt;/p&gt;
&lt;p&gt;The discipline is defined by its tooling and its three-letter&amp;nbsp;acronym.&lt;/p&gt;
&lt;p&gt;But is any of that&amp;nbsp;fundamental?&lt;/p&gt;
&lt;h2 id="the-assumptions-we-carry"&gt;The Assumptions We&amp;nbsp;Carry&lt;/h2&gt;
&lt;p&gt;I identified ten assumptions that most practitioners treat as self-evident. Here&amp;#8217;s how each one fares under&amp;nbsp;scrutiny.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Assumption&lt;/th&gt;
&lt;th&gt;Origin&lt;/th&gt;
&lt;th&gt;Verdict&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Data must be extracted, transformed, then loaded, in that order&lt;/td&gt;
&lt;td&gt;Mainframe-era batch processing constraints&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Baggage&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;You need a centralized data warehouse as the single source of truth&lt;/td&gt;
&lt;td&gt;1990s Kimball/Inmon movement&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Heuristic&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Pipelines should be orchestrated as DAGs with a scheduler&lt;/td&gt;
&lt;td&gt;Airflow&amp;#8217;s popularity + &lt;span class="caps"&gt;CI&lt;/span&gt;/&lt;span class="caps"&gt;CD&lt;/span&gt; analogy&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Heuristic&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Schema should be enforced at write time&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;RDBMS&lt;/span&gt; tradition&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Heuristic&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Data engineers build pipelines; analysts consume them&lt;/td&gt;
&lt;td&gt;Org chart convention&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Baggage&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Batch processing is the default; streaming is advanced&lt;/td&gt;
&lt;td&gt;Batch was historically cheaper&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Baggage&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;Transformations belong in a dedicated processing layer&lt;/td&gt;
&lt;td&gt;Vendor-driven categories (Spark, dbt)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Heuristic&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;Raw data should be preserved immutably (bronze/silver/gold)&lt;/td&gt;
&lt;td&gt;Lambda architecture + compliance&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Heuristic&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;More data is better, collect everything&lt;/td&gt;
&lt;td&gt;Big data hype era, cheap storage&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Baggage&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;Data quality is a pipeline problem&lt;/td&gt;
&lt;td&gt;Analogy to software testing&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Heuristic&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The&amp;nbsp;classification:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Fundamental truth&lt;/strong&gt;: survives all tests. Keep&amp;nbsp;it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Useful heuristic&lt;/strong&gt;: sometimes true, context-dependent. Worth&amp;nbsp;questioning.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inherited baggage&lt;/strong&gt;: convention masquerading as truth. Discard&amp;nbsp;it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Four of the ten are outright baggage. The rest are heuristics, useful in some contexts but dangerously treated as universal&amp;nbsp;truths.&lt;/p&gt;
&lt;h3 id="when-the-heuristics-break"&gt;When the heuristics&amp;nbsp;break&lt;/h3&gt;
&lt;p&gt;The six assumptions I classified as heuristics aren&amp;#8217;t wrong, they&amp;#8217;re just conditional. Here&amp;#8217;s when each one stops&amp;nbsp;working:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Centralized warehouse as single source of truth&lt;/strong&gt; breaks when your producers change faster than your warehouse team can review PRs. It also fails for real-time use cases where the warehouse is always stale by&amp;nbsp;definition.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class="caps"&gt;DAG&lt;/span&gt; orchestration with a scheduler&lt;/strong&gt; breaks when most of your data flows are event-driven or near-real-time. You end up polling for &amp;#8220;is the data there yet?&amp;#8221; instead of reacting to its&amp;nbsp;arrival.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Schema-on-write&lt;/strong&gt; breaks when you&amp;#8217;re exploring a new domain and the schema is genuinely unknown. It also breaks when upstream producers change schemas without coordination (which is&amp;nbsp;always).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dedicated transformation layer&lt;/strong&gt; breaks when the people writing dbt models don&amp;#8217;t understand what the source fields mean. You get syntactically correct &lt;span class="caps"&gt;SQL&lt;/span&gt; that&amp;#8217;s semantically&amp;nbsp;wrong.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Immutable raw data (bronze/silver/gold)&lt;/strong&gt; breaks when compliance requires you to &lt;em&gt;delete&lt;/em&gt; data (&lt;span class="caps"&gt;GDPR&lt;/span&gt; right to erasure), or when storage costs actually matter at scale. &amp;#8220;Keep everything forever&amp;#8221; is a luxury, not a&amp;nbsp;principle.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data quality as a pipeline problem&lt;/strong&gt; breaks because it treats quality as a gate you pass once, not a property that degrades over time. Your data can pass every pipeline test and still be wrong if the source changed its semantics without telling&amp;nbsp;you.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="what-survives-scrutiny"&gt;What Survives&amp;nbsp;Scrutiny&lt;/h2&gt;
&lt;p&gt;After stripping away heuristics and baggage, five irreducible truths&amp;nbsp;remain.&lt;/p&gt;
&lt;h3 id="1-producers-and-consumers-operate-in-different-contexts"&gt;1. Producers and consumers operate in different&amp;nbsp;contexts&lt;/h3&gt;
&lt;p&gt;The system generating data has different goals, schemas, and timelines than whoever needs to use it. This mismatch is &lt;strong&gt;the&lt;/strong&gt; fundamental problem data engineering exists to solve. Without this gap, the entire discipline is&amp;nbsp;unnecessary.&lt;/p&gt;
&lt;h3 id="2-data-must-cross-context-boundaries"&gt;2. Data must cross context&amp;nbsp;boundaries&lt;/h3&gt;
&lt;p&gt;Whether physically copied or virtually federated, the consumer needs access to data they don&amp;#8217;t own. The mechanism is negotiable. The need is&amp;nbsp;not.&lt;/p&gt;
&lt;h3 id="3-semantic-alignment-is-unavoidable"&gt;3. Semantic alignment is&amp;nbsp;unavoidable&lt;/h3&gt;
&lt;p&gt;Two systems calling&amp;nbsp;something &lt;code&gt;customer_id&lt;/code&gt; doesn&amp;#8217;t mean they refer to the same entity. Reconciliation of &lt;strong&gt;meaning&lt;/strong&gt;, not just format, is the hard part. This is why &amp;#8220;just dump it in a lake&amp;#8221; fails: you&amp;#8217;ve moved bytes across a boundary without bridging the semantic&amp;nbsp;gap.&lt;/p&gt;
&lt;h3 id="4-computation-trades-off-time-money-and-complexity"&gt;4. Computation trades off time, money, and&amp;nbsp;complexity&lt;/h3&gt;
&lt;p&gt;You can process data faster (streaming) at higher complexity, or cheaper (batch) with higher latency. This tradeoff is physics, not preference. There is no free&amp;nbsp;lunch.&lt;/p&gt;
&lt;h3 id="5-data-without-provenance-is-unreliable"&gt;5. Data without provenance is&amp;nbsp;unreliable&lt;/h3&gt;
&lt;p&gt;You must know where data came from and how recently it reflects reality. Without that, downstream conclusions are untrustworthy. This is epistemological, not&amp;nbsp;technical.&lt;/p&gt;
&lt;h2 id="the-airflow-cargo-cult"&gt;The Airflow Cargo&amp;nbsp;Cult&lt;/h2&gt;
&lt;p&gt;Before diving into what falls away, a concrete example of inherited thinking in&amp;nbsp;action.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve seen teams adopt Apache Airflow as their first infrastructure decision when starting a data project. Not because they analyzed their scheduling needs and concluded that a &lt;span class="caps"&gt;DAG&lt;/span&gt; orchestrator was the right fit, but because &amp;#8220;that&amp;#8217;s what data teams&amp;nbsp;use&amp;#8221;.&lt;/p&gt;
&lt;p&gt;The result is predictable: a handful of simple &lt;span class="caps"&gt;SQL&lt;/span&gt; queries that run once a day, wrapped in Airflow operators, deployed on a Kubernetes cluster, monitored by a dedicated instance. The entire orchestration layer exists to&amp;nbsp;run &lt;code&gt;cron&lt;/code&gt;-equivalent jobs with 100x the operational overhead. A cron job, a dbt Cloud schedule, or even a simple GitHub Actions workflow would have done the same thing with a fraction of the&amp;nbsp;complexity.&lt;/p&gt;
&lt;p&gt;This happens because teams reason from tools instead of from problems. They ask &amp;#8220;which orchestrator should we use?&amp;#8221; instead of &amp;#8220;do we have a coordination problem that requires orchestration?&amp;#8221; Often the answer is no. You don&amp;#8217;t need a &lt;span class="caps"&gt;DAG&lt;/span&gt; scheduler until you have actual dependencies between data flows that require sequencing. Running three independent queries on a timer is not orchestration, it&amp;#8217;s&amp;nbsp;scheduling.&lt;/p&gt;
&lt;p&gt;The same pattern repeats everywhere. Kafka gets adopted for event streaming when a database trigger would suffice. &lt;strong&gt;Spark&lt;/strong&gt; and &lt;strong&gt;PySpark&lt;/strong&gt; get deployed as distributed compute clusters for datasets that fit in a single PostgreSQL instance, because &amp;#8220;we&amp;#8217;re a big data team&amp;#8221;. &lt;strong&gt;dbt&lt;/strong&gt; gets adopted as &amp;#8220;the transformation layer&amp;#8221; before anyone asks whether the transformations need a dedicated tool or could just be views in the warehouse. Data lakes get stood up for flexibility when a well-modeled warehouse would have been both simpler and more&amp;nbsp;useful.&lt;/p&gt;
&lt;p&gt;The lesson: if your tool choice precedes your problem definition, you&amp;#8217;re carrying&amp;nbsp;baggage.&lt;/p&gt;
&lt;h2 id="what-falls-away"&gt;What Falls&amp;nbsp;Away&lt;/h2&gt;
&lt;h3 id="etl-as-the-defining-paradigm"&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;&lt;span class="caps"&gt;ETL&lt;/span&gt;&amp;#8221; as the defining&amp;nbsp;paradigm&lt;/h3&gt;
&lt;p&gt;The three-letter ordering (Extract, Transform, Load) was an artifact of expensive compute. When compute was scarce, you transformed data before loading because you couldn&amp;#8217;t afford to store or re-process raw data. That constraint is largely&amp;nbsp;gone.&lt;/p&gt;
&lt;p&gt;&lt;span class="caps"&gt;ELT&lt;/span&gt;, streaming, reverse &lt;span class="caps"&gt;ETL&lt;/span&gt;, materialized views: these aren&amp;#8217;t variations on &lt;span class="caps"&gt;ETL&lt;/span&gt;. They&amp;#8217;re evidence that the paradigm was never&amp;nbsp;fundamental.&lt;/p&gt;
&lt;h3 id="more-data-is-better"&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;More data is&amp;nbsp;better&amp;#8221;&lt;/h3&gt;
&lt;p&gt;Driven by the 2010s Hadoop era, when storage became nearly free and &lt;span class="caps"&gt;FOMO&lt;/span&gt; ruled. In practice, data you never use has &lt;strong&gt;negative value&lt;/strong&gt;: it costs money to store, creates security and compliance surface area, and generates&amp;nbsp;noise.&lt;/p&gt;
&lt;p&gt;The fundamental truth is that &lt;em&gt;relevant, reliable data&lt;/em&gt; is better. Collection should be driven by known or plausible use&amp;nbsp;cases.&lt;/p&gt;
&lt;h3 id="data-engineers-build-analysts-consume"&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Data engineers build, analysts&amp;nbsp;consume&amp;#8221;&lt;/h3&gt;
&lt;p&gt;This is an org chart artifact, not a truth about the work. The fundamental problem is context-crossing, getting data from producer to consumer in a usable form. Who does that work is a staffing decision. The rise of analytics engineering (dbt) already proved that the producer/consumer boundary is&amp;nbsp;arbitrary.&lt;/p&gt;
&lt;h3 id="batch-is-default-streaming-is-special"&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Batch is default, streaming is&amp;nbsp;special&amp;#8221;&lt;/h3&gt;
&lt;p&gt;This is a cost artifact, not a fundamental distinction. Batch isn&amp;#8217;t more &amp;#8220;natural&amp;#8221;. It&amp;#8217;s just historically cheaper. As streaming infrastructure has matured, the cost gap narrows, and the distinction becomes about choosing your &lt;strong&gt;latency tolerance&lt;/strong&gt;, not picking a&amp;nbsp;paradigm.&lt;/p&gt;
&lt;h2 id="rebuilt-from-scratch"&gt;Rebuilt From&amp;nbsp;Scratch&lt;/h2&gt;
&lt;p&gt;Starting from only the five irreducible truths, here&amp;#8217;s what data engineering looks like designed from&amp;nbsp;zero.&lt;/p&gt;
&lt;h3 id="start-with-data-contracts-not-pipelines"&gt;Start with data contracts, not&amp;nbsp;pipelines&lt;/h3&gt;
&lt;p&gt;Since the core problem is context mismatch between producers and consumers, the first thing you build isn&amp;#8217;t a pipeline. It&amp;#8217;s a &lt;strong&gt;contract&lt;/strong&gt;. Producers declare what they emit (schema, semantics, freshness guarantees). Consumers declare what they need. The engineering is in bridging the gap, and the contract makes the gap&amp;nbsp;explicit.&lt;/p&gt;
&lt;p&gt;If you&amp;#8217;re coming from backend engineering, the mental model is simple: &lt;strong&gt;data contracts are OpenAPI for data&lt;/strong&gt;. The same way an &lt;span class="caps"&gt;API&lt;/span&gt; contract lets frontend and backend evolve independently as long as both sides honor the spec, a data contract lets producers and consumers evolve independently as long as the agreed-upon schema, semantics, and freshness guarantees hold. Nobody would ship a public &lt;span class="caps"&gt;API&lt;/span&gt; without documenting its shape, yet data teams routinely ship tables with no documented contract at&amp;nbsp;all.&lt;/p&gt;
&lt;p&gt;This isn&amp;#8217;t theoretical. Tools like Andrew Jones&amp;#8217; &lt;a href="https://github.com/datacontract/datacontract-cli"&gt;Data Contract &lt;span class="caps"&gt;CLI&lt;/span&gt;&lt;/a&gt; let you define contracts in &lt;span class="caps"&gt;YAML&lt;/span&gt; and validate them in &lt;span class="caps"&gt;CI&lt;/span&gt;. Protobuf and &lt;span class="caps"&gt;JSON&lt;/span&gt; Schema work for schema enforcement. The format matters less than the practice of making the producer-consumer agreement explicit and&amp;nbsp;testable.&lt;/p&gt;
&lt;p&gt;A contract without a version is just a snapshot. Real contracts need semantic versioning, deprecation windows, and an answer to &amp;#8220;what happens when the producer needs to break compatibility?&amp;#8221; Skip this and you recreate the schema-on-write failure mode one layer up: every upstream change becomes a silent incident for some consumer who was pinning to yesterday&amp;#8217;s assumptions. Treat contract evolution with the same discipline you&amp;#8217;d apply to a public &lt;span class="caps"&gt;API&lt;/span&gt;: additive changes are safe, breaking changes require a new major version and a migration&amp;nbsp;path.&lt;/p&gt;
&lt;pre class="mermaid"&gt;
graph LR
    P[Producer] --&gt;|declares| C[Contract]
    C --&gt;|schema + semantics + SLA| M[Mechanism]
    M --&gt;|batch / stream / CDC / API| D[Consumer]
    D --&gt;|declares needs| C
&lt;/pre&gt;

&lt;h3 id="the-pipeline-is-a-consequence-not-the-product"&gt;The pipeline is a consequence, not the&amp;nbsp;product&lt;/h3&gt;
&lt;p&gt;Once you have contracts, the implementation follows: you need some mechanism to get data from A to B while honoring the contract. This might be a batch job, a streaming consumer, a materialized view, a &lt;span class="caps"&gt;CDC&lt;/span&gt; feed, or a simple &lt;span class="caps"&gt;API&lt;/span&gt; call. The mechanism is chosen per-contract based on the latency-cost-complexity tradeoff, not imposed by a global architecture&amp;nbsp;diagram.&lt;/p&gt;
&lt;h3 id="transform-at-the-boundary-not-in-a-dedicated-layer"&gt;Transform at the boundary, not in a dedicated&amp;nbsp;layer&lt;/h3&gt;
&lt;p&gt;Transformations exist to reconcile semantic mismatches. They should live as close to the boundary-crossing as possible: either at the producer (who understands the source context) or at the consumer (who understands the target context). A centralized &amp;#8220;transformation layer&amp;#8221; is an organizational crutch that obscures who owns the&amp;nbsp;meaning.&lt;/p&gt;
&lt;p&gt;This is the same argument Zhamak Dehghani made for &lt;strong&gt;data mesh&lt;/strong&gt;: push ownership to the domain that understands the data. The first-principles version doesn&amp;#8217;t require adopting the full data mesh organizational model. It just requires that whoever owns the meaning also owns the transformation that encodes it. The boundary is where semantics get negotiated, and the negotiation should happen between parties who actually understand both&amp;nbsp;sides.&lt;/p&gt;
&lt;h3 id="observe-data-dont-just-test-it"&gt;Observe data, don&amp;#8217;t just test&amp;nbsp;it&lt;/h3&gt;
&lt;p&gt;Data quality isn&amp;#8217;t a test suite problem. It&amp;#8217;s an &lt;strong&gt;observability&lt;/strong&gt; problem. Tests check known failure modes; observation surfaces unknown ones. You need continuous monitoring of distributions, volumes, freshness, and lineage, not&amp;nbsp;just &lt;code&gt;assert not null&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This connects directly to &lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;the observability principles&lt;/a&gt; I wrote about earlier. In that post, I argued that the &amp;#8220;three pillars&amp;#8221; (logs, metrics, traces) describe data formats, not observability itself. The same pattern appears here: &amp;#8220;&lt;span class="caps"&gt;ETL&lt;/span&gt;&amp;#8221; describes a data flow ordering, not data engineering itself. In both cases, vendor categories got mistaken for fundamentals. The fix is the same too: explore instead of monitor, alert on invariants rather than thresholds, and treat quality as a design property rather than an&amp;nbsp;afterthought.&lt;/p&gt;
&lt;p&gt;There&amp;#8217;s a deeper problem, though. Data engineering as a discipline has a &lt;strong&gt;testing gap&lt;/strong&gt; that would be unacceptable in software engineering. Most pipeline code has zero unit tests. Transformations that encode critical business logic run without integration tests against realistic data. The entire testing culture amounts to &amp;#8220;check if the &lt;span class="caps"&gt;DAG&lt;/span&gt; ran without errors,&amp;#8221; which tells you nothing about whether the &lt;em&gt;output&lt;/em&gt; is&amp;nbsp;correct.&lt;/p&gt;
&lt;p&gt;Software engineers learned decades ago that &amp;#8220;it compiled&amp;#8221; is not a quality signal. Data engineers are still treating &amp;#8220;the job succeeded&amp;#8221; the same way. A dbt model can produce syntactically valid &lt;span class="caps"&gt;SQL&lt;/span&gt;, run without errors, and silently double-count revenue because of a bad join. Without unit tests on transformation logic and integration tests against known-good datasets, you&amp;#8217;re flying blind and calling it&amp;nbsp;confidence.&lt;/p&gt;
&lt;p&gt;Tools like &lt;a href="https://greatexpectations.io/"&gt;Great Expectations&lt;/a&gt; and &lt;a href="https://www.soda.io/"&gt;Soda&lt;/a&gt; address the observability side, but they&amp;#8217;re not substitutes for actual test coverage on the transformation code. The industry needs both: tests for known invariants and observation for unknown&amp;nbsp;drift.&lt;/p&gt;
&lt;h3 id="collect-data-when-you-can-articulate-who-will-use-it"&gt;Collect data when you can articulate who will use&amp;nbsp;it&lt;/h3&gt;
&lt;p&gt;Instead of &amp;#8220;ingest everything, schema later,&amp;#8221; the rebuilt approach: every data source entering the system has a declared consumer and use case. If you can&amp;#8217;t name one, don&amp;#8217;t ingest it. You can always add it later. This inverts the &amp;#8220;data lake&amp;#8221;&amp;nbsp;mentality.&lt;/p&gt;
&lt;h3 id="make-lineage-and-freshness-first-class"&gt;Make lineage and freshness&amp;nbsp;first-class&lt;/h3&gt;
&lt;p&gt;Since data without known provenance is unreliable, lineage tracking isn&amp;#8217;t a nice-to-have dashboard. It&amp;#8217;s part of the data itself. Every record carries (or can be traced to) its origin, the transformations applied, and when it last reflected&amp;nbsp;reality.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://openlineage.io/"&gt;OpenLineage&lt;/a&gt; is the emerging standard here, and it&amp;#8217;s worth adopting for the same reason OpenTelemetry won in observability: vendor-neutral metadata that any tool can emit and any tool can consume. Lineage captured in a proprietary format is lineage you&amp;#8217;ll lose when you change vendors. Lineage captured in an open standard travels with your&amp;nbsp;data.&lt;/p&gt;
&lt;h2 id="the-tooling-is-catching-up"&gt;The Tooling Is Catching&amp;nbsp;Up&lt;/h2&gt;
&lt;p&gt;The incumbent stack tells a story about its era. &lt;strong&gt;Spark&lt;/strong&gt; was built for a world where data didn&amp;#8217;t fit on one machine, so you distributed it across a cluster. &lt;strong&gt;PySpark&lt;/strong&gt; made that accessible to Python-native data teams, but at the cost of &lt;span class="caps"&gt;JVM&lt;/span&gt; overhead, serialization penalties, and cluster management complexity that most workloads never needed. &lt;strong&gt;dbt&lt;/strong&gt; made &lt;span class="caps"&gt;SQL&lt;/span&gt; transformations testable and version-controlled, which was a genuine leap forward, but it also cemented the idea that transformations are a separate &amp;#8220;layer&amp;#8221; rather than a boundary&amp;nbsp;responsibility.&lt;/p&gt;
&lt;p&gt;All three tools solved real problems. But they solved them with the constraints and assumptions of their time: &lt;span class="caps"&gt;JVM&lt;/span&gt;-based runtimes, Python&amp;#8217;s &lt;span class="caps"&gt;GIL&lt;/span&gt;, single-threaded execution models, and the assumption that &amp;#8220;big data&amp;#8221; meant &amp;#8220;distributed&amp;nbsp;data&amp;#8221;.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Rust data ecosystem&lt;/strong&gt; is quietly rewriting those&amp;nbsp;assumptions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Polars&lt;/strong&gt; is the most visible example. It processes DataFrames with the same &lt;span class="caps"&gt;API&lt;/span&gt; ergonomics as pandas but runs on a multithreaded Rust engine with zero-copy memory, lazy evaluation, and query optimization. Workloads that required a PySpark cluster can often run faster on a single machine with Polars, because the bottleneck was never data volume: it was runtime&amp;nbsp;inefficiency.&lt;/p&gt;
&lt;p&gt;But Polars is just one piece. &lt;strong&gt;DataFusion&lt;/strong&gt; provides a query engine that can be embedded in any application, not locked behind a cluster manager. &lt;strong&gt;Arrow&lt;/strong&gt; gives a common in-memory columnar format that eliminates serialization overhead between tools. &lt;strong&gt;Delta-rs&lt;/strong&gt; brings Delta Lake table management without the &lt;span class="caps"&gt;JVM&lt;/span&gt; dependency. Together, they form a stack where contract validation, schema enforcement, and transformation can happen at native speed, in the same process, with type safety the &lt;span class="caps"&gt;JVM&lt;/span&gt; never&amp;nbsp;offered.&lt;/p&gt;
&lt;p&gt;What this means for the first-principles&amp;nbsp;approach:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Data contracts become cheaper to enforce.&lt;/strong&gt; When schema validation runs at Rust speed instead of PySpark speed, you can validate at every boundary without worrying about performance overhead. Contracts stop being &amp;#8220;nice but expensive&amp;#8221; and become&amp;nbsp;default.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The &amp;#8220;you need a cluster&amp;#8221; assumption dies faster.&lt;/strong&gt; If Polars on a single node outperforms a 10-node Spark cluster for your workload, the entire distributed compute layer was inherited baggage. Vertical scaling wins until it actually&amp;nbsp;doesn&amp;#8217;t.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transformation and validation merge.&lt;/strong&gt; In a Rust-native pipeline, the transformation step and the contract validation step can be the same compiled binary. No orchestrator shuffling data between &amp;#8220;validate&amp;#8221; and &amp;#8220;transform&amp;#8221; stages. No serialization penalty between Python and &lt;span class="caps"&gt;JVM&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Testing becomes tractable.&lt;/strong&gt; Rust&amp;#8217;s type system catches entire categories of errors at compile time that PySpark surfaces at runtime (or never). Combined with fast execution, you can run unit and integration tests against your transformation logic in seconds, not minutes. The testing gap in data engineering gets smaller when the tooling makes testing&amp;nbsp;cheap.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This isn&amp;#8217;t about Rust zealotry. It&amp;#8217;s about recognizing that the performance characteristics of your tools shape which architectural patterns are practical. When validation is expensive, you do it rarely. When it&amp;#8217;s cheap, you do it everywhere. The Rust data ecosystem makes the first-principles approach (contracts at every boundary, test everything, observe continuously) not just theoretically correct but practically&amp;nbsp;feasible.&lt;/p&gt;
&lt;h2 id="smell-test-are-you-carrying-baggage"&gt;Smell Test: Are You Carrying&amp;nbsp;Baggage?&lt;/h2&gt;
&lt;p&gt;Quick diagnostic. If any of these sound familiar, you&amp;#8217;re optimizing conventions instead of solving&amp;nbsp;problems:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Your pipeline has no known consumer.&lt;/strong&gt; Someone requested it two years ago, they left the company, and it still runs every&amp;nbsp;night.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;You chose your orchestrator before defining your data flows.&lt;/strong&gt; &amp;#8220;We&amp;#8217;re an Airflow shop&amp;#8221; is a statement about identity, not&amp;nbsp;architecture.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;You chose Kafka before asking about latency needs.&lt;/strong&gt; If your consumers check a dashboard once a day, you don&amp;#8217;t need sub-second event&amp;nbsp;delivery.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Your transformation logic has zero unit tests.&lt;/strong&gt; You test that the job ran, not that the output is correct. A passing &lt;span class="caps"&gt;DAG&lt;/span&gt; is not a passing&amp;nbsp;test.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Your data lake has no access logs.&lt;/strong&gt; You&amp;#8217;re storing &amp;#8220;everything&amp;#8221; but can&amp;#8217;t name who queried what in the last 90&amp;nbsp;days.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Your schema changes break consumers without warning.&lt;/strong&gt; No contract means every upstream change is a&amp;nbsp;surprise.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;You have a &amp;#8220;data quality&amp;#8221; team instead of quality built into every step.&lt;/strong&gt; Separating quality from production is like separating &amp;#8220;driving safely&amp;#8221; from&amp;nbsp;&amp;#8220;driving&amp;#8221;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Your Spark cluster processes datasets that fit in a laptop&amp;#8217;s &lt;span class="caps"&gt;RAM&lt;/span&gt;.&lt;/strong&gt; The tool should match the problem, not the&amp;nbsp;resume.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;You measure data team success by pipeline count, not consumer outcomes.&lt;/strong&gt; &amp;#8220;We shipped 40 pipelines this quarter&amp;#8221; tells you nothing about whether anyone made a better decision because of them. The output metric is tables; the outcome metric is decisions. Confuse the two and you&amp;#8217;ll optimize for the wrong thing&amp;nbsp;forever.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="what-changes"&gt;What&amp;nbsp;Changes&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Conventional Thinking&lt;/th&gt;
&lt;th&gt;First-Principles Thinking&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Build pipelines, then document them&lt;/td&gt;
&lt;td&gt;Define contracts first, derive pipelines from them&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Choose batch or streaming as an architecture&lt;/td&gt;
&lt;td&gt;Choose latency per data flow based on consumer needs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Centralized transformation layer (dbt/Spark)&lt;/td&gt;
&lt;td&gt;Transform at the producer-consumer boundary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data lake: store everything, figure it out later&lt;/td&gt;
&lt;td&gt;Collect only what has a declared consumer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data quality = pipeline tests&lt;/td&gt;
&lt;td&gt;Data quality = continuous observability&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data engineer builds, analyst consumes&lt;/td&gt;
&lt;td&gt;Anyone who bridges the context gap is doing data engineering&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Orchestrator (Airflow) is the center of gravity&lt;/td&gt;
&lt;td&gt;Contract registry is the center of gravity&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="implications"&gt;Implications&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Start your next data project by writing contracts, not DAGs.&lt;/strong&gt; Define what producers emit and what consumers need before writing a single line of pipeline code. Tools like Protobuf, &lt;span class="caps"&gt;JSON&lt;/span&gt; Schema, or even a shared spreadsheet work. The format matters less than the&amp;nbsp;practice.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Audit your existing pipelines.&lt;/strong&gt; Ask: &amp;#8220;who consumes this and when do they need it?&amp;#8221; Any pipeline without a clear answer is a candidate for decommissioning. You&amp;#8217;ll likely find 20-40% of pipelines serve no active&amp;nbsp;consumer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Stop treating streaming as advanced.&lt;/strong&gt; For new data flows, evaluate latency needs first. Sometimes batch is the right call, but it should be a conscious decision, not a&amp;nbsp;default.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Push transformation ownership to semantic owners.&lt;/strong&gt; If the marketing team defines what &amp;#8220;qualified lead&amp;#8221; means, they should own (or at minimum co-own) the transformation that computes it, not a data engineer guessing from a Jira&amp;nbsp;ticket.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Invest in lineage and freshness metadata as infrastructure.&lt;/strong&gt; If you can&amp;#8217;t programmatically answer &amp;#8220;where did this number come from and how old is it?&amp;#8221; for any metric in your warehouse, that&amp;#8217;s a higher priority than building new&amp;nbsp;pipelines.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;First-principles analysis by the author, based on industry experience and reasoning from&amp;nbsp;fundamentals&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;First Principles: Software Observability&lt;/a&gt; - First post in this series, applying the same method to&amp;nbsp;observability&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-software-design.html"&gt;First Principles: Software Design&lt;/a&gt; - Second post in this series, stripping software design to its irreducible&amp;nbsp;core&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-devops.html"&gt;First Principles: DevOps&lt;/a&gt; - Third post in this series, questioning the conventions of modern&amp;nbsp;DevOps&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/datacontract/datacontract-cli"&gt;Data Contract &lt;span class="caps"&gt;CLI&lt;/span&gt;&lt;/a&gt; - Open-source tool for defining and validating data&amp;nbsp;contracts&lt;/li&gt;
&lt;li&gt;&lt;a href="https://greatexpectations.io/"&gt;Great Expectations&lt;/a&gt; - Data validation and profiling&amp;nbsp;framework&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.soda.io/"&gt;Soda&lt;/a&gt; - Data quality monitoring&amp;nbsp;platform&lt;/li&gt;
&lt;li&gt;&lt;a href="https://openlineage.io/"&gt;OpenLineage&lt;/a&gt; - Open standard for lineage metadata&amp;nbsp;collection&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pola.rs/"&gt;Polars&lt;/a&gt; - Fast DataFrame library built on&amp;nbsp;Rust&lt;/li&gt;
&lt;li&gt;&lt;a href="https://datafusion.apache.org/"&gt;Apache Arrow DataFusion&lt;/a&gt; - Embeddable query engine in&amp;nbsp;Rust&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/delta-io/delta-rs"&gt;Delta-rs&lt;/a&gt; - Delta Lake implementation in Rust, no &lt;span class="caps"&gt;JVM&lt;/span&gt;&amp;nbsp;required&lt;/li&gt;
&lt;li&gt;Zhamak Dehghani, &lt;em&gt;Data Mesh: Delivering Data-Driven Value at Scale&lt;/em&gt; - Origin of the domain-ownership argument applied to&amp;nbsp;data&lt;/li&gt;
&lt;/ol&gt;</content><category term="Engineering"/><category term="first-principles"/><category term="data-engineering"/><category term="etl"/><category term="pipelines"/><category term="polars"/><category term="rust"/></entry><entry><title>First Principles: DevOps</title><link href="https://alexsavio.github.io/first-principles-devops.html" rel="alternate"/><published>2026-03-30T12:00:00+02:00</published><updated>2026-03-30T12:00:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2026-03-30:/first-principles-devops.html</id><summary type="html">&lt;p&gt;Strip away the Kubernetes hype, the &amp;#8220;DevOps Engineer&amp;#8221; job titles, and the cargo-culted &lt;span class="caps"&gt;CI&lt;/span&gt;/&lt;span class="caps"&gt;CD&lt;/span&gt; pipelines. What&amp;#8217;s actually true about DevOps when you reason from first principles? Five irreducible truths, six design principles, and a clear framework for right-sizing your operational&amp;nbsp;complexity.&lt;/p&gt;</summary><content type="html">&lt;h2 id="tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;Most of what passes for &amp;#8220;DevOps&amp;#8221; is tool adoption dressed up as strategy. When you strip away inherited conventions and industry hype, only five truths survive: value dies in the gap between developer and user, feedback loops drive improvement, reproducibility reduces risk, handoffs cost superlinearly, and recovery beats prevention. Everything else, from Kubernetes to the &amp;#8220;DevOps Engineer&amp;#8221; job title, is implementation detail that should be proportional to your actual coordination&amp;nbsp;problem.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;This is the third post in my First Principles series, where I take a concept the industry treats as settled and strip it back to what&amp;#8217;s actually provable. The first one tackled &lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;Software Observability&lt;/a&gt;, the second one &lt;a href="https://alexsavio.github.io/first-principles-software-design.html"&gt;Software Design&lt;/a&gt;. DevOps felt like the natural next target, because few topics have a wider gap between what people say and what they actually&amp;nbsp;do.&lt;/em&gt;&lt;/p&gt;
&lt;div class="toc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-conventional-view"&gt;The Conventional&amp;nbsp;View&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-assumptions-we-carry"&gt;The Assumptions We&amp;nbsp;Carry&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-survives-scrutiny"&gt;What Survives&amp;nbsp;Scrutiny&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-falls-away"&gt;What Falls&amp;nbsp;Away&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-steel-case-for-convention"&gt;The Steel Case for&amp;nbsp;Convention&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#rebuilt-from-scratch"&gt;Rebuilt From&amp;nbsp;Scratch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-changes"&gt;What&amp;nbsp;Changes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#right-sizing-checklist"&gt;Right-Sizing&amp;nbsp;Checklist&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-to-do-about-it"&gt;What to Do About&amp;nbsp;It&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#references"&gt;References&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 id="the-conventional-view"&gt;The Conventional&amp;nbsp;View&lt;/h2&gt;
&lt;p&gt;DevOps is the practice of unifying software development and &lt;span class="caps"&gt;IT&lt;/span&gt; operations through shared tooling, culture, and automation. Most organizations interpret this as: adopt &lt;span class="caps"&gt;CI&lt;/span&gt;/&lt;span class="caps"&gt;CD&lt;/span&gt; pipelines, containerize everything, use Infrastructure as Code, monitor with dashboards, and hire people with &amp;#8220;DevOps Engineer&amp;#8221; in their&amp;nbsp;title.&lt;/p&gt;
&lt;p&gt;The conversation typically centers on tools (Kubernetes, Terraform, Jenkins, GitHub Actions) rather than on the underlying problem being solved. This is the first sign that something has gone wrong: when the answer comes before the&amp;nbsp;question.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve seen this pattern up close. Teams that spend months building elaborate &lt;span class="caps"&gt;CI&lt;/span&gt;/&lt;span class="caps"&gt;CD&lt;/span&gt; pipelines before asking whether their actual bottleneck is deployment or something else entirely. A startup with two developers and three microservices running on Kubernetes because &amp;#8220;that&amp;#8217;s what you do&amp;#8221;. An ops team automating a quarterly task into a script that took longer to debug than a year of doing it by hand. The tools aren&amp;#8217;t the problem. The problem is reaching for them before understanding what you&amp;#8217;re&amp;nbsp;solving.&lt;/p&gt;
&lt;h2 id="the-assumptions-we-carry"&gt;The Assumptions We&amp;nbsp;Carry&lt;/h2&gt;
&lt;p&gt;Before deconstructing, it helps to name the conventional wisdom. These are the beliefs most teams treat as&amp;nbsp;self-evident:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Assumption&lt;/th&gt;
&lt;th&gt;Origin&lt;/th&gt;
&lt;th&gt;Verdict&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;DevOps requires specialized &amp;#8220;DevOps Engineers&amp;#8221;&lt;/td&gt;
&lt;td&gt;Job market evolution; companies needed a hiring label&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;CI&lt;/span&gt;/&lt;span class="caps"&gt;CD&lt;/span&gt; pipelines are essential&lt;/td&gt;
&lt;td&gt;Continuous delivery movement (Humble &lt;span class="amp"&gt;&amp;amp;&lt;/span&gt; Farley, 2010)&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Containers (Docker/Kubernetes) are a prerequisite&lt;/td&gt;
&lt;td&gt;Industry trend post-2014; conference culture&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Infrastructure as Code is always better than manual config&lt;/td&gt;
&lt;td&gt;Repeatability arguments from config management era&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Dev and Ops must be merged into one team&lt;/td&gt;
&lt;td&gt;Reaction to siloed orgs; the original DevOps manifesto&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;More automation is always better&lt;/td&gt;
&lt;td&gt;Efficiency narrative; &amp;#8220;automate everything&amp;#8221; mantra&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;You need a complex observability stack (metrics, logs, traces)&lt;/td&gt;
&lt;td&gt;Microservices explosion; vendor marketing&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;Deployment frequency is a key measure of success&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;DORA&lt;/span&gt; metrics research (Forsgren et al.)&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;GitOps / declarative config is the correct paradigm&lt;/td&gt;
&lt;td&gt;Weaveworks marketing + Kubernetes ecosystem conventions&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;You should adopt the same practices as Google/Netflix/Meta&lt;/td&gt;
&lt;td&gt;Cargo-culting from tech conference talks&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Three categories&amp;nbsp;emerge:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Fundamental truth&lt;/strong&gt;: survives all scrutiny, keep&amp;nbsp;it&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Useful heuristic&lt;/strong&gt;: sometimes true, context-dependent, worth&amp;nbsp;questioning&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inherited baggage&lt;/strong&gt;: convention masquerading as truth, discard&amp;nbsp;it&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Four of ten assumptions are outright baggage. Five are heuristics that work in some contexts but get applied universally. None survived as fundamental truths, which means the bedrock of DevOps lies&amp;nbsp;elsewhere.&lt;/p&gt;
&lt;h2 id="what-survives-scrutiny"&gt;What Survives&amp;nbsp;Scrutiny&lt;/h2&gt;
&lt;p&gt;Strip away the heuristics and baggage, and five irreducible truths&amp;nbsp;remain:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. The gap between developer and user is where value is destroyed.&lt;/strong&gt; Software has zero value until it&amp;#8217;s running where users can reach it. Every delay, error, miscommunication, or manual step in that gap is pure&amp;nbsp;waste.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Feedback loops are the mechanism by which systems improve.&lt;/strong&gt; You cannot control what you cannot observe. Without knowing what broke, what&amp;#8217;s slow, or what users actually do, improvement is impossible. This is an information-theoretic truth. (I explored this deeply in &lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;First Principles: Software Observability&lt;/a&gt;, where I stripped observability down to its own irreducible&amp;nbsp;core.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Reproducibility reduces risk.&lt;/strong&gt; If you can recreate an environment or deployment exactly, you can reason about failures and recover from them. Identical inputs produce identical outputs in deterministic&amp;nbsp;systems.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. Coordination costs grow superlinearly with handoffs.&lt;/strong&gt; Every time work crosses a team boundary, information is lost, delays are introduced, and accountability diffuses. This is Brooks&amp;#8217;s Law and transaction cost economics in&amp;nbsp;action.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5. Systems fail. The question is recovery speed, not failure prevention.&lt;/strong&gt; Complex systems have emergent failure modes that cannot all be predicted. You cannot enumerate all states of a sufficiently complex&amp;nbsp;system.&lt;/p&gt;
&lt;h2 id="what-falls-away"&gt;What Falls&amp;nbsp;Away&lt;/h2&gt;
&lt;p&gt;With the bedrock established, it becomes clear what the industry has been carrying&amp;nbsp;unnecessarily.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;DevOps Engineer&amp;#8221; as a role.&lt;/strong&gt; The original insight was that the wall between Dev and Ops was the problem. Creating a third silo called &amp;#8220;DevOps&amp;#8221; that sits between them reintroduces the exact coordination cost the movement was trying to eliminate. This persists because it&amp;#8217;s easier to hire a person than to change a&amp;nbsp;culture.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Containers as prerequisite.&lt;/strong&gt; Containers are one mechanism for achieving reproducibility and isolation. A well-configured &lt;span class="caps"&gt;VM&lt;/span&gt;, a properly managed bare-metal server, or even a PaaS like Heroku can deliver the same fundamental properties. Containers won because they&amp;#8217;re composable and portable, but they&amp;#8217;re a means, not a truth. Many teams adopted Kubernetes before they had the problem Kubernetes&amp;nbsp;solves.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Automate everything&amp;#8221;.&lt;/strong&gt; Automation has a cost: it must be written, maintained, debugged, and understood. If a task is performed once a quarter, automating it may destroy more value than it creates (maintenance burden &amp;gt; time saved). The fundamental truth is reproducibility, not automation. A well-documented runbook can be more valuable than a brittle&amp;nbsp;script.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;GitOps / tool-specific paradigms.&lt;/strong&gt; These are implementations of reproducibility and auditability, not truths in themselves. The assumption that declarative &lt;span class="caps"&gt;YAML&lt;/span&gt; in a Git repo is the correct interface for all infrastructure is a convention that spread through the Kubernetes ecosystem, not a provable&amp;nbsp;law.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Copying Big Tech.&lt;/strong&gt; Google built Kubernetes because they run millions of containers across a global fleet. Netflix built Chaos Monkey because they operate at a scale where component failure is a statistical certainty. If you&amp;#8217;re running 3 services on 5 machines, adopting their toolchain adds complexity without solving a problem you&amp;nbsp;have.&lt;/p&gt;
&lt;h2 id="the-steel-case-for-convention"&gt;The Steel Case for&amp;nbsp;Convention&lt;/h2&gt;
&lt;p&gt;First-principles thinking is powerful, but it&amp;#8217;s also dangerous if applied lazily. Some of these conventions exist for good reasons that deserve honest&amp;nbsp;engagement.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;But &lt;span class="caps"&gt;DORA&lt;/span&gt; research &lt;em&gt;does&lt;/em&gt; show deployment frequency correlates with performance&amp;#8221;.&lt;/strong&gt; It does. Forsgren et al. collected real data across thousands of organizations. The correlation between deployment frequency, lead time, &lt;span class="caps"&gt;MTTR&lt;/span&gt;, and change failure rate is solid. The mistake isn&amp;#8217;t measuring these metrics. It&amp;#8217;s Goodharting them: optimizing deployment frequency as a goal rather than treating it as a signal that your delivery gap is shrinking. A team deploying 50 times a day through an automated pipeline that nobody understands hasn&amp;#8217;t improved, they&amp;#8217;ve just moved the&amp;nbsp;bottleneck.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Kubernetes complexity pays off at scale&amp;#8221;.&lt;/strong&gt; True, past a certain threshold. If you&amp;#8217;re running dozens of services across multiple teams with different scaling characteristics, container orchestration solves real coordination problems. The line I&amp;#8217;d draw: if you have a dedicated platform team &lt;em&gt;and&lt;/em&gt; enough services that manual deployment tracking becomes error-prone, Kubernetes starts earning its keep. Below that, it&amp;#8217;s&amp;nbsp;overhead.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;IaC prevents configuration drift&amp;#8221;.&lt;/strong&gt; It does, and configuration drift causes real outages. The first-principles argument isn&amp;#8217;t that IaC is bad, it&amp;#8217;s that IaC is one solution to the reproducibility problem, and sometimes a simpler one exists. A team running on a managed PaaS already has reproducibility without writing a single line of Terraform. The question is always: what&amp;#8217;s the cheapest mechanism that gets you reliable reproducibility at your&amp;nbsp;scale?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;The DevOps Engineer role fills a real skills gap&amp;#8221;.&lt;/strong&gt; Fair. Most developers don&amp;#8217;t know networking, and most ops people don&amp;#8217;t write application code. The role exists because the skills gap is real. But filling a skills gap by creating a permanent intermediary team is different from filling it by cross-training. The first scales linearly; the second&amp;nbsp;compounds.&lt;/p&gt;
&lt;p&gt;The point isn&amp;#8217;t that conventions are always wrong. It&amp;#8217;s that they should be &lt;em&gt;chosen&lt;/em&gt;, not &lt;em&gt;inherited&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id="rebuilt-from-scratch"&gt;Rebuilt From&amp;nbsp;Scratch&lt;/h2&gt;
&lt;p&gt;Starting from only the five truths, here&amp;#8217;s what DevOps looks like designed from&amp;nbsp;zero.&lt;/p&gt;
&lt;p&gt;The core insight is that operational complexity should scale with your coordination problem, not with industry trends. Most teams are somewhere on this spectrum but reaching for tools from the wrong&amp;nbsp;end:&lt;/p&gt;
&lt;pre class="mermaid"&gt;
quadrantChart
    title Automation Decision Matrix
    x-axis Low Frequency --&gt; High Frequency
    y-axis Low Complexity --&gt; High Complexity
    quadrant-1 Automate
    quadrant-2 Platform team territory
    quadrant-3 Just do it manually
    quadrant-4 Script it
    CI/CD pipelines: [0.9, 0.75]
    Deploys: [0.85, 0.5]
    Monitoring setup: [0.6, 0.8]
    DB migrations: [0.4, 0.7]
    Quarterly reports: [0.15, 0.3]
    SSL cert renewal: [0.2, 0.15]
    Log rotation: [0.7, 0.2]
    Dependency updates: [0.65, 0.35]
&lt;/pre&gt;

&lt;p&gt;The bottom-left quadrant is where most wasted automation effort lives: tasks that happen rarely and aren&amp;#8217;t complex, but somebody automated them anyway because &amp;#8220;automate everything&amp;#8221; sounded&amp;nbsp;right.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Minimize the gap, not the tools.&lt;/strong&gt;
The goal is: code to user with minimum waste. For a solo developer, that might&amp;nbsp;be &lt;code&gt;git push&lt;/code&gt; triggering a deploy to a PaaS. For a 500-person org, it might involve staged rollouts and canary analysis. The mechanism should be proportional to the coordination problem. Start with the simplest thing that closes the gap, and add complexity only when you hit a real&amp;nbsp;wall.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Make the people who build it responsible for running it.&lt;/strong&gt;
Not by creating a &amp;#8220;DevOps team,&amp;#8221; but by literally making developers own their service in production. This isn&amp;#8217;t a cultural aspiration, it&amp;#8217;s a structural decision. When the person who writes the code also gets paged at 2 &lt;span class="caps"&gt;AM&lt;/span&gt;, the feedback loop is zero-latency. The org chart should reflect this, not fight&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Invest in observability proportional to your ignorance.&lt;/strong&gt;
You need enough visibility to answer: &amp;#8220;Is it working? If not, where is it broken?&amp;#8221; For a monolith with 100 users, application logs and an uptime check may suffice. For a distributed system with millions of requests, you need traces, metrics, and structured logging. The investment should match your system&amp;#8217;s complexity, not an industry&amp;nbsp;benchmark.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. Reproducibility through the cheapest mechanism available.&lt;/strong&gt;
IaC is one option. So is imaging. So is a documented manual process with verification steps. So is a PaaS that abstracts infrastructure entirely. The question is: &amp;#8220;Can I recreate this environment reliably?&amp;#8221; The answer doesn&amp;#8217;t require&amp;nbsp;Terraform.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5. Optimize for recovery, not prevention.&lt;/strong&gt;
Instead of building elaborate approval gates and change advisory boards to prevent failures, invest in: fast rollbacks, blue-green deployments, feature flags, and the ability to detect problems within minutes. Accept that failures will happen and make them&amp;nbsp;cheap.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6. Automate only what earns its maintenance cost.&lt;/strong&gt;
Before automating, ask: How often does this run? What&amp;#8217;s the cost of doing it manually? What&amp;#8217;s the cost of maintaining the automation when it breaks? Many organizations have graveyards of &lt;span class="caps"&gt;CI&lt;/span&gt;/&lt;span class="caps"&gt;CD&lt;/span&gt; pipelines that no one understands and everyone is afraid to touch. A process you run manually but understand is better than automation you can&amp;#8217;t&amp;nbsp;debug.&lt;/p&gt;
&lt;h2 id="what-changes"&gt;What&amp;nbsp;Changes&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Conventional Thinking&lt;/th&gt;
&lt;th&gt;First-Principles Thinking&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hire DevOps Engineers&lt;/td&gt;
&lt;td&gt;Make developers own production&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Adopt Kubernetes&lt;/td&gt;
&lt;td&gt;Use the simplest deployment target that works&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Automate everything&lt;/td&gt;
&lt;td&gt;Automate what earns its maintenance cost&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Build a full observability stack&lt;/td&gt;
&lt;td&gt;Observe proportional to system complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Prevent failures with process&lt;/td&gt;
&lt;td&gt;Make failures cheap and recovery fast&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Follow &lt;span class="caps"&gt;DORA&lt;/span&gt; metrics&lt;/td&gt;
&lt;td&gt;Measure the gap between &amp;#8220;code done&amp;#8221; and &amp;#8220;user has it&amp;#8221; directly&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Adopt GitOps&lt;/td&gt;
&lt;td&gt;Achieve reproducibility by whatever means is cheapest&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Copy Big Tech practices&lt;/td&gt;
&lt;td&gt;Solve your actual problems at your actual scale&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The pattern is consistent: conventional DevOps optimizes for the wrong proxy. It measures deployment frequency instead of delivery gap. It adds tools instead of removing handoffs. It automates for automation&amp;#8217;s sake instead of for&amp;nbsp;value.&lt;/p&gt;
&lt;h2 id="right-sizing-checklist"&gt;Right-Sizing&amp;nbsp;Checklist&lt;/h2&gt;
&lt;p&gt;The hardest part of first-principles DevOps is knowing where you actually sit. Here&amp;#8217;s a rough&amp;nbsp;guide:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solo developer or small team (1-5 people, &amp;lt; 5&amp;nbsp;services)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;[ ] Deploy target: PaaS, single server, or managed container service. You don&amp;#8217;t need&amp;nbsp;Kubernetes.&lt;/li&gt;
&lt;li&gt;[ ] &lt;span class="caps"&gt;CI&lt;/span&gt;/&lt;span class="caps"&gt;CD&lt;/span&gt;: A simple pipeline that runs tests and deploys on merge. One file, not a &lt;span class="caps"&gt;YAML&lt;/span&gt;&amp;nbsp;empire.&lt;/li&gt;
&lt;li&gt;[ ] Observability: Application logs + uptime monitoring + error alerting. That&amp;#8217;s&amp;nbsp;it.&lt;/li&gt;
&lt;li&gt;[ ] IaC: Optional. If your infra fits in one cloud console page, a documented setup guide may be&amp;nbsp;enough.&lt;/li&gt;
&lt;li&gt;[ ] Automation: Automate the deploy. Script the rest only when it starts&amp;nbsp;hurting.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Growing team (5-20 people, 5-20&amp;nbsp;services)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;[ ] Deploy target: Containers start earning their keep here, especially if services have different scaling&amp;nbsp;needs.&lt;/li&gt;
&lt;li&gt;[ ] &lt;span class="caps"&gt;CI&lt;/span&gt;/&lt;span class="caps"&gt;CD&lt;/span&gt;: Standardized pipelines per service, but owned by the teams that use them, not a central DevOps&amp;nbsp;team.&lt;/li&gt;
&lt;li&gt;[ ] Observability: Structured logging + basic metrics + alerting on SLOs. Consider traces if debugging cross-service issues takes&amp;nbsp;hours.&lt;/li&gt;
&lt;li&gt;[ ] IaC: Worth it now. Configuration drift across 10+ services causes real&amp;nbsp;outages.&lt;/li&gt;
&lt;li&gt;[ ] Automation: Automate deployment, environment provisioning, and the tasks that run weekly or more. Runbooks for everything&amp;nbsp;else.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Scaling org (20+ people, 20+&amp;nbsp;services)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;[ ] Deploy target: Container orchestration (Kubernetes or equivalent) becomes justified. Consider a platform&amp;nbsp;team.&lt;/li&gt;
&lt;li&gt;[ ] &lt;span class="caps"&gt;CI&lt;/span&gt;/&lt;span class="caps"&gt;CD&lt;/span&gt;: Platform-provided golden paths that teams can customize, not&amp;nbsp;enforce.&lt;/li&gt;
&lt;li&gt;[ ] Observability: Full stack (metrics, logs, traces) with &lt;span class="caps"&gt;SLO&lt;/span&gt;-based alerting. The cost of &lt;em&gt;not&lt;/em&gt; having this exceeds the cost of running&amp;nbsp;it.&lt;/li&gt;
&lt;li&gt;[ ] IaC: Non-negotiable. Everything in code, reviewed,&amp;nbsp;versioned.&lt;/li&gt;
&lt;li&gt;[ ] Automation: Invest in self-service infrastructure. The platform team&amp;#8217;s job is to make the right thing the easy&amp;nbsp;thing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The boundaries are fuzzy. The principle is: match your operational investment to your actual coordination&amp;nbsp;complexity.&lt;/p&gt;
&lt;h2 id="what-to-do-about-it"&gt;What to Do About&amp;nbsp;It&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Audit your toolchain for cargo-culting.&lt;/strong&gt; For each tool in your stack, ask: &amp;#8220;What specific problem at our scale does this solve?&amp;#8221; If the answer is &amp;#8220;everyone uses it&amp;#8221; or &amp;#8220;we might need it someday,&amp;#8221; it&amp;#8217;s a candidate for removal. Simpler systems have fewer failure&amp;nbsp;modes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Kill the DevOps team (structurally, not the people).&lt;/strong&gt; Redistribute operational ownership to the teams that build the software. Platform engineering, building internal tools that reduce friction, is valuable. A team that acts as a gateway between dev and prod is&amp;nbsp;not.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Right-size your process to your coordination cost.&lt;/strong&gt; A 5-person startup and a 500-person enterprise have fundamentally different coordination problems. The startup&amp;#8217;s &amp;#8220;DevOps&amp;#8221; might be a Makefile and a deploy script. The enterprise&amp;#8217;s might be a platform team and a service mesh. Neither is wrong; what&amp;#8217;s wrong is applying one to the&amp;nbsp;other.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Measure the end-to-end gap, not proxy metrics.&lt;/strong&gt; Instead of tracking deployment frequency as an end in itself, measure: &amp;#8220;How long from a developer finishing a feature to a user being able to use it?&amp;#8221; Everything that extends that duration is waste to be examined, whether it&amp;#8217;s a slow &lt;span class="caps"&gt;CI&lt;/span&gt; pipeline, a manual approval, or a 3-week release&amp;nbsp;train.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Treat recovery speed as a first-class investment.&lt;/strong&gt; Every hour spent making rollbacks faster, deploys more reversible, and failures more detectable pays dividends that prevention-oriented processes (change advisory boards, multi-stage approvals) rarely&amp;nbsp;match.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;First-principles analysis generated&amp;nbsp;in-session&lt;/li&gt;
&lt;li&gt;Humble, J. &lt;span class="amp"&gt;&amp;amp;&lt;/span&gt; Farley, D. (2010). &lt;em&gt;Continuous Delivery&lt;/em&gt;.&amp;nbsp;Addison-Wesley&lt;/li&gt;
&lt;li&gt;Forsgren, N., Humble, J., &lt;span class="amp"&gt;&amp;amp;&lt;/span&gt; Kim, G. (2018). &lt;em&gt;Accelerate: The Science of Lean Software and DevOps&lt;/em&gt;. &lt;span class="caps"&gt;IT&lt;/span&gt; Revolution&amp;nbsp;Press&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;First Principles: Software Observability&lt;/a&gt; - Related post applying the same first-principles method to&amp;nbsp;observability&lt;/li&gt;
&lt;/ol&gt;</content><category term="Engineering"/><category term="first-principles"/><category term="devops"/><category term="automation"/><category term="infrastructure"/><category term="kubernetes"/><category term="ci-cd"/></entry><entry><title>First Principles: Software Design</title><link href="https://alexsavio.github.io/first-principles-software-design.html" rel="alternate"/><published>2026-03-21T11:00:00+01:00</published><updated>2026-03-21T11:00:00+01:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2026-03-21:/first-principles-software-design.html</id><summary type="html">&lt;p&gt;Strip away the design patterns, the &lt;span class="caps"&gt;SOLID&lt;/span&gt; principles, and the architecture astronautics. What&amp;#8217;s actually true about software design when you reason from fundamentals? Five irreducible truths, three reconstruction principles, and a framework for making design decisions based on cognitive load, not&amp;nbsp;convention.&lt;/p&gt;</summary><content type="html">&lt;h2 id="tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;Most software design advice is convention dressed up as truth. When you strip away the inherited thinking, only five things survive scrutiny: software transforms input to output, human working memory is limited, change costs dominate creation costs, coupling determines blast radius, and naming compresses complexity. Rebuilding from these truths produces a discipline centered on cognitive load management and deletability, not extensibility and pattern&amp;nbsp;compliance.&lt;/p&gt;
&lt;div class="toc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-conventional-view"&gt;The Conventional&amp;nbsp;View&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-assumptions-we-carry"&gt;The Assumptions We&amp;nbsp;Carry&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-survives-scrutiny"&gt;What Survives&amp;nbsp;Scrutiny&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-falls-away"&gt;What Falls&amp;nbsp;Away&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-heuristics-handle-with-care"&gt;The Heuristics: Handle With&amp;nbsp;Care&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#rebuilt-from-scratch"&gt;Rebuilt From Scratch&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#principle-1-optimize-for-deletion-not-extension"&gt;Principle 1: Optimize for Deletion, Not&amp;nbsp;Extension&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#principle-2-inline-until-it-hurts-then-extract"&gt;Principle 2: Inline Until It Hurts, Then&amp;nbsp;Extract&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#principle-3-make-dependencies-visible-and-explicit"&gt;Principle 3: Make Dependencies Visible and&amp;nbsp;Explicit&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-design-process-that-follows"&gt;The Design Process That Follows&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#should-i-abstract-this"&gt;Should I Abstract&amp;nbsp;This?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#evidence-from-the-wild"&gt;Evidence From the&amp;nbsp;Wild&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#but-what-about-large-systems"&gt;But What About Large&amp;nbsp;Systems?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-changes"&gt;What&amp;nbsp;Changes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#implications"&gt;Implications&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#references"&gt;References&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 id="the-conventional-view"&gt;The Conventional&amp;nbsp;View&lt;/h2&gt;
&lt;p&gt;Software design, as typically taught and practiced, is about organizing code into clean abstractions, following established patterns (&lt;span class="caps"&gt;MVC&lt;/span&gt;, microservices, hexagonal architecture), applying &lt;span class="caps"&gt;SOLID&lt;/span&gt; principles, and writing extensible systems that anticipate future change. Good design means separation of concerns, low coupling, high cohesion, and layers of indirection that make the system&amp;nbsp;&amp;#8220;flexible&amp;#8221;.&lt;/p&gt;
&lt;p&gt;Most of this is convention. Some of it is useful. Very little of it is&amp;nbsp;fundamental.&lt;/p&gt;
&lt;h2 id="the-assumptions-we-carry"&gt;The Assumptions We&amp;nbsp;Carry&lt;/h2&gt;
&lt;p&gt;Before deconstructing, let&amp;#8217;s name the beliefs most developers absorb without&amp;nbsp;questioning:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Assumption&lt;/th&gt;
&lt;th&gt;Origin&lt;/th&gt;
&lt;th&gt;Verdict&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Good design means anticipating future requirements&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;OOP&lt;/span&gt; textbooks, enterprise culture&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;More abstraction = better design&lt;/td&gt;
&lt;td&gt;Academic &lt;span class="caps"&gt;CS&lt;/span&gt;, design pattern movement&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Code should be &lt;span class="caps"&gt;DRY&lt;/span&gt; (Don&amp;#8217;t Repeat Yourself)&lt;/td&gt;
&lt;td&gt;The Pragmatic Programmer (1999)&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Separation of concerns produces better systems&lt;/td&gt;
&lt;td&gt;Dijkstra (1974), proven by experience&lt;/td&gt;
&lt;td&gt;Fundamental&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Design patterns are the vocabulary of good design&lt;/td&gt;
&lt;td&gt;Gang of Four (1994), Java enterprise culture&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Systems should be loosely coupled&lt;/td&gt;
&lt;td&gt;Parnas (1972), empirically validated&lt;/td&gt;
&lt;td&gt;Fundamental&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;You need an architecture before you write code&lt;/td&gt;
&lt;td&gt;Waterfall legacy, enterprise planning culture&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;Good code is reusable code&lt;/td&gt;
&lt;td&gt;Library/framework culture, &lt;span class="caps"&gt;DRY&lt;/span&gt; extrapolation&lt;/td&gt;
&lt;td&gt;Baggage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;Complexity must be managed through indirection&lt;/td&gt;
&lt;td&gt;Enterprise Java, layered architecture dogma&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;Tests prove your design is correct&lt;/td&gt;
&lt;td&gt;&lt;span class="caps"&gt;TDD&lt;/span&gt; movement, Agile culture&lt;/td&gt;
&lt;td&gt;Heuristic&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;That&amp;#8217;s three fundamentals, three heuristics, and four pieces of baggage. Let&amp;#8217;s see what&amp;nbsp;survives.&lt;/p&gt;
&lt;h2 id="what-survives-scrutiny"&gt;What Survives&amp;nbsp;Scrutiny&lt;/h2&gt;
&lt;p&gt;Each assumption was tested against three questions: Is this a law or a convention? What&amp;#8217;s the evidence? What function does the assumption&amp;nbsp;serve?&lt;/p&gt;
&lt;p&gt;Five irreducible truths&amp;nbsp;emerged:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Software exists to model a transformation from input to output.&lt;/strong&gt; At its most fundamental, every program takes some state of the world and produces a different state. Design is the act of choosing how to decompose that transformation. This is mathematical, it survives regardless of language, paradigm, or&amp;nbsp;era.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Humans have limited working memory (~4-7 chunks).&lt;/strong&gt; This is cognitive science, not convention. Miller&amp;#8217;s 1956 research established the limits, and John Sweller&amp;#8217;s &lt;strong&gt;Cognitive Load Theory&lt;/strong&gt; refined the model into three types: &lt;em&gt;intrinsic&lt;/em&gt; load (the inherent complexity of the problem), &lt;em&gt;extraneous&lt;/em&gt; load (complexity added by how information is presented), and &lt;em&gt;germane&lt;/em&gt; load (effort spent building mental models). Software design&amp;#8217;s job is to minimize extraneous cognitive load, the complexity that exists because of &lt;em&gt;how the code is organized&lt;/em&gt; rather than &lt;em&gt;what the code does&lt;/em&gt;. Any system that requires a person to hold more than 4-7 chunks in their head simultaneously will produce errors. This is the actual root reason separation of concerns works. Not because it&amp;#8217;s &amp;#8220;clean,&amp;#8221; but because human brains have hard&amp;nbsp;limits.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. The cost of change dominates the cost of creation.&lt;/strong&gt; Empirically, across decades of industry data, modifying existing systems costs far more than writing them initially. Design choices compound: each decision constrains or enables future&amp;nbsp;decisions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. Coupling between components determines the blast radius of change.&lt;/strong&gt; When A depends on B, changing B risks breaking A. This is structural, not opinion. The fewer dependencies a component has, the cheaper it is to change in isolation. Parnas demonstrated this in 1972 and nothing has invalidated&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5. Naming is compression.&lt;/strong&gt; A name (function, module, variable) lets humans treat a complex thing as a single chunk in working memory. Good names reduce cognitive load. Bad names increase it. This follows directly from truth&amp;nbsp;#2.&lt;/p&gt;
&lt;h2 id="what-falls-away"&gt;What Falls&amp;nbsp;Away&lt;/h2&gt;
&lt;p&gt;Four assumptions classified as baggage, and the reasons they&amp;nbsp;persisted:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Anticipate future requirements&amp;#8221;.&lt;/strong&gt; This feels responsible and professional. In practice, humans are terrible at predicting what will change. Studies show that speculative generality creates more waste than it prevents. The assumption confuses &lt;em&gt;making change cheap&lt;/em&gt; (valuable) with &lt;em&gt;predicting what will change&lt;/em&gt;&amp;nbsp;(impossible).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;More abstraction = better design&amp;#8221;.&lt;/strong&gt; Abstraction has a cost: indirection. Every layer you add is a layer someone must navigate to understand the system. Abstractions feel intellectually satisfying and they&amp;#8217;re easy to teach. But abstraction is only valuable when it reduces net cognitive load, when the thing being hidden is more complex than the interface replacing it. Premature abstraction &lt;em&gt;increases&lt;/em&gt; total&amp;nbsp;complexity.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Design patterns are the vocabulary&amp;#8221;.&lt;/strong&gt; The Gang of Four patterns were documented as recurring solutions in C++ and Smalltalk in 1994. Many exist to work around language limitations: Visitor, Strategy, and Observer are all compensating for missing first-class functions or pattern matching. Reaching for a pattern before understanding the problem adds accidental&amp;nbsp;complexity.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Good code is reusable code&amp;#8221;.&lt;/strong&gt; Reusability requires predicting how code will be reused, a form of future prediction. Making code reusable adds generality, parameters, and configuration that increase complexity &lt;em&gt;now&lt;/em&gt; for hypothetical benefit &lt;em&gt;later&lt;/em&gt;. Most &amp;#8220;reusable&amp;#8221; code is used exactly once. The assumption persists because reusability sounds&amp;nbsp;economical.&lt;/p&gt;
&lt;h2 id="the-heuristics-handle-with-care"&gt;The Heuristics: Handle With&amp;nbsp;Care&lt;/h2&gt;
&lt;p&gt;Three assumptions survived as context-dependent guidelines, not&amp;nbsp;laws:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;DRY&lt;/span&gt;&lt;/strong&gt; is useful when duplication causes &lt;em&gt;bugs&lt;/em&gt; (changing one copy but forgetting the other). It&amp;#8217;s harmful when it creates premature abstractions that couple unrelated things. The question is not &amp;#8220;is this duplicated?&amp;#8221; but &amp;#8220;is this duplication causing actual&amp;nbsp;problems?&amp;#8221;&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s what happens when &lt;span class="caps"&gt;DRY&lt;/span&gt; goes wrong. You notice three functions that look similar, so you &amp;#8220;extract the&amp;nbsp;commonality&amp;#8221;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# The DRY trap: one function, 16 code paths, nobody understands it&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;process_record&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;enrich&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;emit_event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;_validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;enrich&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_fetch_enrichment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;enrich&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_special_case_enriched_unnormalized&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;emit_event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;_publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;record&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Versus the &amp;#8220;duplicated&amp;#8221;&amp;nbsp;version:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# Three functions, each trivially understandable&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;ingest_from_api&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;ingest_from_partner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fetch_enrichment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;ingest_from_migration&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;record&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The first version is &amp;#8220;&lt;span class="caps"&gt;DRY&lt;/span&gt;&amp;#8221;. It&amp;#8217;s also a combinatorial minefield where every new caller adds another boolean flag and another implicit code path. The second version has some repeated lines, but each function fits entirely in working memory. You can&amp;nbsp;change &lt;code&gt;ingest_from_migration&lt;/code&gt; without any risk of breaking the &lt;span class="caps"&gt;API&lt;/span&gt; ingestion&amp;nbsp;path.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Indirection for complexity management&lt;/strong&gt; works when the thing being hidden is genuinely complex. It fails when the indirection itself becomes the complexity. Every layer of indirection is a cognitive tax, justified only when the tax is less than the complexity it&amp;nbsp;hides.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Tests as design validation&lt;/strong&gt; provides signal about the external behavior of a system, not about its internal design quality. Tests can pass for poorly designed systems and fail for well-designed ones during refactoring. Tests verify &lt;em&gt;what&lt;/em&gt; the system does, not &lt;em&gt;how well&lt;/em&gt; it&amp;#8217;s&amp;nbsp;structured.&lt;/p&gt;
&lt;h2 id="rebuilt-from-scratch"&gt;Rebuilt From&amp;nbsp;Scratch&lt;/h2&gt;
&lt;p&gt;Starting from only the five truths, here&amp;#8217;s software design rebuilt from the ground&amp;nbsp;up:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Design is cognitive load management.&lt;/strong&gt; Every design decision should be evaluated by one question: &lt;em&gt;does this make the system easier or harder for a human to hold in their head?&lt;/em&gt; Not &amp;#8220;is this clean,&amp;#8221; not &amp;#8220;does this follow &lt;span class="caps"&gt;SOLID&lt;/span&gt;,&amp;#8221; not &amp;#8220;is this extensible,&amp;#8221; but does it reduce the number of things a person must simultaneously understand to make a correct&amp;nbsp;change?&lt;/p&gt;
&lt;p&gt;This produces three&amp;nbsp;principles:&lt;/p&gt;
&lt;h3 id="principle-1-optimize-for-deletion-not-extension"&gt;Principle 1: Optimize for Deletion, Not&amp;nbsp;Extension&lt;/h3&gt;
&lt;p&gt;Since we can&amp;#8217;t predict what will change but we know change will happen, the best design makes components easy to &lt;em&gt;remove and replace&lt;/em&gt; rather than easy to extend. Small, independent units with clear boundaries. If you can delete a module and replace it with a different implementation without touching other modules, your design is good. You don&amp;#8217;t need plugin architectures or abstract factories. You need components small enough to throw&amp;nbsp;away.&lt;/p&gt;
&lt;pre class="mermaid"&gt;
flowchart LR
    subgraph Conventional["Conventional: Extend"]
        A[Base Class] --&gt; B[Extension A]
        A --&gt; C[Extension B]
        A --&gt; D[Extension C]
        style A fill:#e74c3c,color:#fff
    end
    subgraph FirstPrinciples["First Principles: Delete &amp; Replace"]
        E[Module A] ~~~ F[Module B]
        E ~~~ G[Module C]
        style E fill:#2ecc71,color:#fff
        style F fill:#2ecc71,color:#fff
        style G fill:#2ecc71,color:#fff
    end
&lt;/pre&gt;

&lt;p&gt;In the conventional model, the base class is a single point of failure for change. In the first-principles model, any module can be deleted and rewritten without cascading&amp;nbsp;effects.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s the difference in code. The &amp;#8220;extensible&amp;#8221;&amp;nbsp;version:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# The Strategy Pattern way: 5 files, 3 abstractions, 1 actual behavior&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;NotificationStrategy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ABC&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nd"&gt;@abstractmethod&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;EmailStrategy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NotificationStrategy&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;smtp_client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;NotificationService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="fm"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;strategy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;NotificationStrategy&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_strategy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;strategy&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_strategy&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Usage: requires a factory or DI container to wire up&lt;/span&gt;
&lt;span class="n"&gt;service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;NotificationService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EmailStrategy&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The &amp;#8220;deletable&amp;#8221;&amp;nbsp;version:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# The direct way: 1 file, 0 abstractions, same behavior&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;send_email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;smtp_client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Usage: call the function&lt;/span&gt;
&lt;span class="n"&gt;send_email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The second version is three lines. A new developer understands it instantly. When you need &lt;span class="caps"&gt;SMS&lt;/span&gt; notifications six months from now, you&amp;nbsp;write &lt;code&gt;send_sms()&lt;/code&gt; next to it. You don&amp;#8217;t need to predict whether notifications will vary by channel, by urgency, by user preference, or by some axis you haven&amp;#8217;t imagined yet. You just write the next function when you need&amp;nbsp;it.&lt;/p&gt;
&lt;h3 id="principle-2-inline-until-it-hurts-then-extract"&gt;Principle 2: Inline Until It Hurts, Then&amp;nbsp;Extract&lt;/h3&gt;
&lt;p&gt;Since abstraction has a cost (cognitive load of indirection) and a benefit (cognitive load reduction via naming), the right time to abstract is when the &lt;em&gt;concrete&lt;/em&gt; code exceeds working memory, not before. Start with the simplest, most direct implementation. Duplicate if necessary. When you see &lt;em&gt;actual&lt;/em&gt; repetition causing &lt;em&gt;actual&lt;/em&gt; bugs or &lt;em&gt;actual&lt;/em&gt; difficulty understanding the code, extract an abstraction. The abstraction is justified by present pain, not hypothetical future&amp;nbsp;benefit.&lt;/p&gt;
&lt;h3 id="principle-3-make-dependencies-visible-and-explicit"&gt;Principle 3: Make Dependencies Visible and&amp;nbsp;Explicit&lt;/h3&gt;
&lt;p&gt;Since coupling determines blast radius, and since humans need to understand impact before making changes, dependencies should be obvious in the code structure. No action-at-a-distance. No implicit global state. No &amp;#8220;magic&amp;#8221; that connects things behind the scenes. A developer reading a module should be able to see, without tooling, what it depends on and what depends on&amp;nbsp;it.&lt;/p&gt;
&lt;h2 id="the-design-process-that-follows"&gt;The Design Process That&amp;nbsp;Follows&lt;/h2&gt;
&lt;p&gt;Combining these principles produces a&amp;nbsp;process:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Write the simplest code that transforms input to output&amp;nbsp;correctly&lt;/li&gt;
&lt;li&gt;When a single unit exceeds what you can hold in your head, extract and name a&amp;nbsp;sub-unit&lt;/li&gt;
&lt;li&gt;When changing one thing keeps breaking another, introduce a&amp;nbsp;boundary&lt;/li&gt;
&lt;li&gt;When you find yourself making the same change in multiple places and getting it wrong, &lt;em&gt;then&lt;/em&gt;&amp;nbsp;deduplicate&lt;/li&gt;
&lt;li&gt;Regularly ask: &amp;#8220;could I delete this component and rewrite it in a day?&amp;#8221; If not, it&amp;#8217;s too&amp;nbsp;big&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This is not &amp;#8220;no design&amp;#8221;. It&amp;#8217;s design driven by empirical signals rather than speculative&amp;nbsp;principles.&lt;/p&gt;
&lt;h3 id="should-i-abstract-this"&gt;Should I Abstract&amp;nbsp;This?&lt;/h3&gt;
&lt;p&gt;When you&amp;#8217;re staring at similar code and feeling the &lt;span class="caps"&gt;DRY&lt;/span&gt; reflex, run through&amp;nbsp;this:&lt;/p&gt;
&lt;pre class="mermaid"&gt;
flowchart TD
    A["I see similar code"] --&gt; B{"Is the duplication&lt;br/&gt;causing actual bugs?"}
    B -- No --&gt; C["Leave it. Duplication&lt;br/&gt;is fine for now."]
    B -- Yes --&gt; D{"Do you have 3+&lt;br/&gt;concrete cases?"}
    D -- No --&gt; E["Wait. Two cases&lt;br/&gt;aren't enough to see&lt;br/&gt;the real pattern."]
    D -- Yes --&gt; F{"Can you name the&lt;br/&gt;axis of variation?"}
    F -- No --&gt; G["You don't understand&lt;br/&gt;the abstraction yet.&lt;br/&gt;Keep it concrete."]
    F -- Yes --&gt; H{"Does the concrete code&lt;br/&gt;exceed working memory&lt;br/&gt;~4-7 chunks?"}
    H -- No --&gt; I["The cost of indirection&lt;br/&gt;outweighs the benefit.&lt;br/&gt;Keep it inline."]
    H -- Yes --&gt; J["Extract the abstraction.&lt;br/&gt;Name it after what&lt;br/&gt;varies, not what's shared."]
&lt;/pre&gt;

&lt;p&gt;Most of the time, you end up on the left side. That&amp;#8217;s the&amp;nbsp;point.&lt;/p&gt;
&lt;h2 id="evidence-from-the-wild"&gt;Evidence From the&amp;nbsp;Wild&lt;/h2&gt;
&lt;p&gt;These principles aren&amp;#8217;t theoretical. Some of the most successful software projects in history embody them, often without using the&amp;nbsp;vocabulary.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;SQLite&lt;/strong&gt; is a single C file (amalgamation) with no external dependencies. It&amp;#8217;s the most deployed database in the world, running on every smartphone, browser, and embedded device. Its design optimizes ruthlessly for understandability: one file, clear module boundaries within that file, and zero abstraction layers between you and the &lt;span class="caps"&gt;SQL&lt;/span&gt; engine. Any developer can read it top to bottom. The result? Decades of reliability with a tiny&amp;nbsp;team.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Redis&lt;/strong&gt; started as a flat, single-threaded C codebase with almost no abstraction layers. Salvatore Sanfilippo famously resisted adding features that would require architectural complexity. Each data structure is its own self-contained implementation. The result is a system that a single developer can hold in their head, which is why it has remarkably few bugs for its&amp;nbsp;ubiquity.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Go&amp;#8217;s standard library&lt;/strong&gt; takes the opposite approach from Java&amp;#8217;s. Instead of deep inheritance hierarchies and abstract factories, it uses flat packages with concrete types.&amp;nbsp;The &lt;code&gt;net/http&lt;/code&gt; package is a good example: you can read the Handler interface (two lines) and start building. No framework, no middleware abstractions, no dependency injection. When you need middleware, you write a function that wraps a Handler. The &amp;#8220;design pattern&amp;#8221; is just functions calling&amp;nbsp;functions.&lt;/p&gt;
&lt;p&gt;Contrast these with &lt;strong&gt;early Enterprise Java&lt;/strong&gt; (&lt;span class="caps"&gt;EJB&lt;/span&gt; 2.x era), where a simple &amp;#8220;save a record to a database&amp;#8221; required a Home interface, a Remote interface, a Bean implementation, a deployment descriptor, and a &lt;span class="caps"&gt;JNDI&lt;/span&gt; lookup. Six files and three abstraction layers for something that should be one function call. The cognitive load was so extreme that an entire cottage industry of &amp;#8220;simplification&amp;#8221; frameworks (Spring, Hibernate) emerged just to make Java usable, each adding their own layers of&amp;nbsp;indirection.&lt;/p&gt;
&lt;p&gt;The pattern is consistent: systems that optimize for human understanding over architectural purity tend to be more reliable, longer-lived, and maintained by smaller&amp;nbsp;teams.&lt;/p&gt;
&lt;h2 id="but-what-about-large-systems"&gt;But What About Large&amp;nbsp;Systems?&lt;/h2&gt;
&lt;p&gt;The biggest objection to this approach: &amp;#8220;This works for small projects, but real systems at scale need&amp;nbsp;architecture&amp;#8221;.&lt;/p&gt;
&lt;p&gt;This conflates two things. Large systems &lt;em&gt;do&lt;/em&gt; need structure. But that structure doesn&amp;#8217;t need to come from speculative upfront architecture or pattern catalogs. It can emerge from the same principles applied&amp;nbsp;recursively.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Linux kernel&lt;/strong&gt; is over 30 million lines of code. It has no grand architectural diagram that was designed before coding started. Instead, it&amp;#8217;s organized as subsystems (networking, filesystems, drivers, scheduling) where each subsystem is relatively independent, with clear interfaces at the boundaries. Individual subsystems are small enough that their maintainers can hold them in their heads. The macro structure emerged from decades of applying &amp;#8220;keep components independent and boundaries clear&amp;#8221; at every&amp;nbsp;scale.&lt;/p&gt;
&lt;p&gt;The key insight: &lt;strong&gt;a large system is not a large component. It&amp;#8217;s many small components with clear boundaries between them.&lt;/strong&gt; The principles don&amp;#8217;t change at scale, they&amp;#8217;re applied&amp;nbsp;recursively:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Each component should be deletable and&amp;nbsp;replaceable&lt;/li&gt;
&lt;li&gt;Each component should fit in one developer&amp;#8217;s working&amp;nbsp;memory&lt;/li&gt;
&lt;li&gt;Dependencies between components should be visible and&amp;nbsp;explicit&lt;/li&gt;
&lt;li&gt;When a component gets too big to understand, split&amp;nbsp;it&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The difference between a well-structured large system and a &amp;#8220;big ball of mud&amp;#8221; is not the presence of design patterns or architectural frameworks. It&amp;#8217;s whether each piece is small enough to understand and independent enough to change&amp;nbsp;safely.&lt;/p&gt;
&lt;h2 id="what-changes"&gt;What&amp;nbsp;Changes&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Conventional Thinking&lt;/th&gt;
&lt;th&gt;First-Principles Thinking&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Plan the architecture upfront&lt;/td&gt;
&lt;td&gt;Let structure emerge from actual needs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Abstract early to enable flexibility&lt;/td&gt;
&lt;td&gt;Inline until concrete pain forces extraction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Design for extensibility&lt;/td&gt;
&lt;td&gt;Design for deletability&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Apply patterns as building blocks&lt;/td&gt;
&lt;td&gt;Solve the specific problem; patterns may emerge&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span class="caps"&gt;DRY&lt;/span&gt; as a rule&lt;/td&gt;
&lt;td&gt;Duplication is cheaper than the wrong abstraction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Layers and indirection for &amp;#8220;clean&amp;#8221; separation&lt;/td&gt;
&lt;td&gt;Indirection only when it reduces net cognitive load&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reusable components are an asset&lt;/td&gt;
&lt;td&gt;Single-purpose, throwaway components are an asset&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Good design prevents future problems&lt;/td&gt;
&lt;td&gt;Good design makes future problems cheap to fix&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="implications"&gt;Implications&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Measure design quality by time-to-understand.&lt;/strong&gt; When reviewing code, ask: &amp;#8220;How long would it take a new team member to understand this module well enough to change it safely?&amp;#8221; That&amp;#8217;s your design quality metric. Not how many &lt;span class="caps"&gt;SOLID&lt;/span&gt; principles it&amp;nbsp;follows.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Treat duplication as a feature until it isn&amp;#8217;t.&lt;/strong&gt; Two similar functions are easier to understand than one generic function with a boolean parameter. Wait until you have &lt;em&gt;three&lt;/em&gt; cases and can see the &lt;em&gt;actual&lt;/em&gt; axis of variation before&amp;nbsp;abstracting.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Invest in naming over structure.&lt;/strong&gt; A well-named function in a flat file is often better design than a poorly-named class in a perfect inheritance hierarchy. Naming is the highest-leverage design tool because it directly addresses the cognitive load&amp;nbsp;constraint.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Design for the team you have.&lt;/strong&gt; If your team struggles with complex type hierarchies, simpler designs with more duplication will produce fewer bugs. Design quality is relative to the humans who must work with&amp;nbsp;it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Stop designing for requirements you don&amp;#8217;t have.&lt;/strong&gt; The next time you&amp;#8217;re tempted to add a parameter, interface, or configuration option &amp;#8220;in case we need it,&amp;#8221; don&amp;#8217;t. You&amp;#8217;re adding complexity now to solve a problem that probably won&amp;#8217;t arrive, and if it does, you&amp;#8217;ll probably solve it differently than you&amp;nbsp;imagined.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This approach connects to the same reasoning in &lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;First Principles: Software Observability&lt;/a&gt;, where stripping away the &amp;#8220;three pillars&amp;#8221; marketing reveals that observability is really about answering novel questions about system behavior. Both disciplines converge on the same meta-principle: optimize for human understanding of complex systems, not for adherence to inherited&amp;nbsp;frameworks.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Parnas, &lt;span class="caps"&gt;D.L.&lt;/span&gt;(1972). &amp;#8220;On the Criteria To Be Used in Decomposing Systems into Modules&amp;#8221; - foundational work on information hiding and&amp;nbsp;coupling&lt;/li&gt;
&lt;li&gt;Gamma, E. et al. (1994). &amp;#8220;Design Patterns: Elements of Reusable Object-Oriented Software&amp;#8221; - the Gang of Four&amp;nbsp;book&lt;/li&gt;
&lt;li&gt;Hunt, A. &lt;span class="amp"&gt;&amp;amp;&lt;/span&gt; Thomas, D. (1999). &amp;#8220;The Pragmatic Programmer&amp;#8221; - origin of &lt;span class="caps"&gt;DRY&lt;/span&gt;&amp;nbsp;principle&lt;/li&gt;
&lt;li&gt;Dijkstra, &lt;span class="caps"&gt;E.W.&lt;/span&gt;(1974). &amp;#8220;On the role of scientific thought&amp;#8221; - origin of separation of&amp;nbsp;concerns&lt;/li&gt;
&lt;li&gt;Miller, &lt;span class="caps"&gt;G.A.&lt;/span&gt;(1956). &amp;#8220;The Magical Number Seven, Plus or Minus Two&amp;#8221; - working memory&amp;nbsp;limits&lt;/li&gt;
&lt;li&gt;Sweller, J. (1988). &amp;#8220;Cognitive Load During Problem Solving&amp;#8221; - Cognitive Load Theory, distinguishing intrinsic, extraneous, and germane&amp;nbsp;load&lt;/li&gt;
&lt;li&gt;Sandi Metz (2014). &amp;#8220;The Wrong Abstraction&amp;#8221; - duplication vs wrong abstraction&amp;nbsp;argument&lt;/li&gt;
&lt;li&gt;&lt;a href="https://alexsavio.github.io/first-principles-software-observability.html"&gt;First Principles: Software Observability&lt;/a&gt; - related first-principles&amp;nbsp;analysis&lt;/li&gt;
&lt;/ol&gt;</content><category term="Engineering"/><category term="first-principles"/><category term="software-design"/><category term="architecture"/><category term="complexity"/><category term="cognitive-load"/></entry><entry><title>First Principles: Software Observability</title><link href="https://alexsavio.github.io/first-principles-software-observability.html" rel="alternate"/><published>2026-03-19T20:45:00+01:00</published><updated>2026-03-19T20:45:00+01:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2026-03-19:/first-principles-software-observability.html</id><summary type="html">&lt;p&gt;Everyone knows observability means logs, metrics, and traces. But what if you strip away the vendor marketing, the inherited conventions, and the cargo-culted dashboards? What&amp;#8217;s actually true? A first-principles deconstruction of software&amp;nbsp;observability.&lt;/p&gt;</summary><content type="html">&lt;h2 id="tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;The &amp;#8220;three pillars&amp;#8221; of observability (logs, metrics, traces) describe data formats, not observability itself. When you strip the concept down to what&amp;#8217;s provably true and rebuild from scratch, you get a fundamentally different approach: instrument decisions instead of outcomes, explore instead of monitor, alert on invariants instead of thresholds, and treat observability as a design property, not an ops&amp;nbsp;afterthought.&lt;/p&gt;
&lt;div class="toc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#tldr"&gt;&lt;span class="caps"&gt;TL&lt;/span&gt;;&lt;span class="caps"&gt;DR&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-conventional-view"&gt;The Conventional&amp;nbsp;View&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-assumptions-we-carry"&gt;The Assumptions We&amp;nbsp;Carry&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-survives-scrutiny"&gt;What Survives Scrutiny&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#1-a-system-is-observable-if-you-can-determine-its-internal-state-from-its-external-outputs"&gt;1. A system is observable if you can determine its internal state from its external&amp;nbsp;outputs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#2-you-cannot-debug-what-you-cannot-distinguish"&gt;2. You cannot debug what you cannot&amp;nbsp;distinguish&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#3-the-value-of-observability-is-proportional-to-the-speed-of-the-feedback-loop"&gt;3. The value of observability is proportional to the speed of the feedback&amp;nbsp;loop&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#4-systems-fail-in-ways-you-didnt-predict"&gt;4. Systems fail in ways you didn&amp;#8217;t&amp;nbsp;predict&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#5-signal-costs-attention-and-attention-is-finite"&gt;5. Signal costs attention, and attention is&amp;nbsp;finite&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-falls-away"&gt;What Falls&amp;nbsp;Away&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#rebuilt-from-scratch"&gt;Rebuilt From Scratch&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#build-systems-that-explain-themselves"&gt;Build systems that explain&amp;nbsp;themselves&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#one-event-model-not-three-pillars"&gt;One event model, not three&amp;nbsp;pillars&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#explore-dont-monitor"&gt;Explore, don&amp;#8217;t&amp;nbsp;monitor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#alerts-from-invariants-not-thresholds"&gt;Alerts from invariants, not&amp;nbsp;thresholds&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#cost-is-proportional-to-questions-answered-not-data-stored"&gt;Cost is proportional to questions answered, not data&amp;nbsp;stored&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-developer-is-the-operator"&gt;The developer is the&amp;nbsp;operator&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#the-delta"&gt;The&amp;nbsp;Delta&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#what-you-can-do-monday-morning"&gt;What You Can Do Monday&amp;nbsp;Morning&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#references"&gt;References&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id="the-conventional-view"&gt;The Conventional&amp;nbsp;View&lt;/h2&gt;
&lt;p&gt;Ask any engineer what &amp;#8220;observability&amp;#8221; means and you&amp;#8217;ll get the same answer: logs, metrics, and traces, the &amp;#8220;three pillars&amp;#8221;. Ship them to Datadog or Grafana, build dashboards, set up alerts, and you&amp;#8217;re observable. This is the version you&amp;#8217;ll hear at every conference talk and read in every vendor blog&amp;nbsp;post.&lt;/p&gt;
&lt;p&gt;The framing traces back to Peter Bourgon&amp;#8217;s 2017 blog post &lt;a href="https://peter.bourgon.org/blog/2017/02/21/metrics-tracing-and-logging.html"&gt;&amp;#8220;Metrics, tracing, and logging&amp;#8221;&lt;/a&gt;, which drew a Venn diagram of the three signal types and their overlaps. It was a useful taxonomy for a talk. Then the vendor ecosystem adopted it as gospel, and now teams treat it like a checklist: ✓ logs ✓ metrics ✓ traces →&amp;nbsp;done.&lt;/p&gt;
&lt;p&gt;But how much of this is actually true, and how much is convention dressed up as&amp;nbsp;truth?&lt;/p&gt;
&lt;h2 id="the-assumptions-we-carry"&gt;The Assumptions We&amp;nbsp;Carry&lt;/h2&gt;
&lt;p&gt;Before deconstructing, let&amp;#8217;s name the baggage. These are beliefs most engineers treat as&amp;nbsp;self-evident:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Assumption&lt;/th&gt;
&lt;th&gt;Origin&lt;/th&gt;
&lt;th&gt;Verdict&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Observability = logs + metrics + traces&lt;/td&gt;
&lt;td&gt;Industry vendors, circa 2017-2018&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Heuristic&lt;/strong&gt; - useful taxonomy, but the pillar count is arbitrary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;More data means better observability&lt;/td&gt;
&lt;td&gt;Analogy from data science (&amp;#8220;collect everything, decide later&amp;#8221;)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Baggage&lt;/strong&gt; - more data often means more noise and higher cost&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;You need a centralized observability platform&lt;/td&gt;
&lt;td&gt;Vendor marketing + operational convenience&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Heuristic&lt;/strong&gt; - centralization helps, but the platform isn&amp;#8217;t the observability&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Dashboards are how you understand systems&lt;/td&gt;
&lt;td&gt;Inherited from physical control rooms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Baggage&lt;/strong&gt; - dashboards show what you already know to ask about&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Alerts should fire when thresholds are breached&lt;/td&gt;
&lt;td&gt;Infrastructure monitoring (Nagios era)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Heuristic&lt;/strong&gt; - works for known failure modes, useless for novel ones&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Observability is an ops/&lt;span class="caps"&gt;SRE&lt;/span&gt; concern&lt;/td&gt;
&lt;td&gt;Historical &amp;#8220;build it&amp;#8221; vs &amp;#8220;run it&amp;#8221; separation&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Baggage&lt;/strong&gt; - broken feedback loop if builders can&amp;#8217;t observe&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;Instrumentation is overhead that slows development&lt;/td&gt;
&lt;td&gt;Perception that observability is separate from feature work&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Baggage&lt;/strong&gt; - confuses bad instrumentation with instrumentation itself&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;You should monitor everything in production&lt;/td&gt;
&lt;td&gt;Defensive posture (&amp;#8220;we might need it someday&amp;#8221;)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Baggage&lt;/strong&gt; - monitoring everything is monitoring nothing with extra cost&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;Observability is about finding bugs in production&lt;/td&gt;
&lt;td&gt;Narrow framing from incident response culture&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Heuristic&lt;/strong&gt; - incident response is one use case, not the definition&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;Sampling loses important information&lt;/td&gt;
&lt;td&gt;Fear from teams burned by missing data&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Heuristic&lt;/strong&gt; - true for rare events, false for high-volume steady-state&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Three categories emerge: &lt;strong&gt;fundamental truths&lt;/strong&gt; that survive scrutiny, &lt;strong&gt;useful heuristics&lt;/strong&gt; that are context-dependent, and &lt;strong&gt;inherited baggage&lt;/strong&gt;, conventions masquerading as&amp;nbsp;truth.&lt;/p&gt;
&lt;h2 id="what-survives-scrutiny"&gt;What Survives&amp;nbsp;Scrutiny&lt;/h2&gt;
&lt;p&gt;After stripping away heuristics and baggage, five things are provably, irreducibly true about&amp;nbsp;observability.&lt;/p&gt;
&lt;h3 id="1-a-system-is-observable-if-you-can-determine-its-internal-state-from-its-external-outputs"&gt;1. A system is observable if you can determine its internal state from its external&amp;nbsp;outputs&lt;/h3&gt;
&lt;p&gt;This is the control-theory definition, and it&amp;#8217;s the real one. Rudolf Kalman formalized it in 1960 in his work on linear dynamical systems &lt;a href="https://doi.org/10.1016/S1474-6670(17)70094-8"&gt;Kalman, 1960&lt;/a&gt;: a system is observable if, for every possible sequence of state transitions, the current state can be determined in finite time using only the outputs. It says nothing about tools, pillars, or vendors. It&amp;#8217;s a property of the &lt;em&gt;system itself&lt;/em&gt;, not of the monitoring infrastructure bolted onto&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;The distinction matters. When you buy a monitoring platform, you haven&amp;#8217;t made your system observable. You&amp;#8217;ve added a receiver for signals your system may or may not be emitting. The observability is in the system&amp;#8217;s design. The platform is just a&amp;nbsp;lens.&lt;/p&gt;
&lt;h3 id="2-you-cannot-debug-what-you-cannot-distinguish"&gt;2. You cannot debug what you cannot&amp;nbsp;distinguish&lt;/h3&gt;
&lt;p&gt;This is the insight Charity Majors and the Honeycomb team have been hammering on for years &lt;a href="https://www.honeycomb.io/blog/observability-a-manifesto"&gt;Honeycomb, &amp;#8220;Observability: A Manifesto&amp;#8221;&lt;/a&gt;: the fundamental purpose of observability data is to tell apart &lt;em&gt;this request&lt;/em&gt; from &lt;em&gt;that request&lt;/em&gt;, &lt;em&gt;this state&lt;/em&gt; from &lt;em&gt;that state&lt;/em&gt;. If your data collapses distinct behaviors into pre-aggregated metrics, you&amp;#8217;ve lost the ability to reason about&amp;nbsp;specifics.&lt;/p&gt;
&lt;p&gt;This is why high-cardinality, high-dimensionality data matters. It preserves the ability to ask questions you didn&amp;#8217;t anticipate. A metric that says &amp;#8220;p99 latency is 800ms&amp;#8221; tells you there&amp;#8217;s a problem. An event that says &amp;#8220;request abc123 from user xyz, hitting service-payments via endpoint /charge, took 1200ms because the database query plan chose a sequential scan on a 4M-row table&amp;#8221; tells you &lt;em&gt;why&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id="3-the-value-of-observability-is-proportional-to-the-speed-of-the-feedback-loop"&gt;3. The value of observability is proportional to the speed of the feedback&amp;nbsp;loop&lt;/h3&gt;
&lt;p&gt;Data that arrives 10 minutes after the fact is categorically less useful than data available in real time. The faster you can go from &amp;#8220;something is wrong&amp;#8221; to &amp;#8220;I understand why,&amp;#8221; the less damage the system takes. &lt;span class="caps"&gt;MTTR&lt;/span&gt; (Mean Time To Recovery) directly correlates with blast&amp;nbsp;radius.&lt;/p&gt;
&lt;p&gt;The Google &lt;span class="caps"&gt;SRE&lt;/span&gt; book makes this concrete in its chapter on monitoring distributed systems &lt;a href="https://sre.google/sre-book/monitoring-distributed-systems/"&gt;Beyer et al., 2016&lt;/a&gt;: the ideal monitoring system minimizes the time between a problem occurring, being detected, being understood, and being fixed. Every delay in that chain&amp;nbsp;compounds.&lt;/p&gt;
&lt;h3 id="4-systems-fail-in-ways-you-didnt-predict"&gt;4. Systems fail in ways you didn&amp;#8217;t&amp;nbsp;predict&lt;/h3&gt;
&lt;p&gt;If you could enumerate all failure modes in advance, you&amp;#8217;d prevent them. Observability exists precisely because you can&amp;#8217;t. This is what Charity Majors calls the distinction between &amp;#8220;known unknowns&amp;#8221; and &amp;#8220;unknown unknowns&amp;#8221; &lt;a href="https://charity.wtf/2020/03/03/observability-is-a-many-splendored-thing/"&gt;Majors, 2020&lt;/a&gt;. Monitoring handles the former, observability handles the&amp;nbsp;latter.&lt;/p&gt;
&lt;p&gt;Any approach that only works for anticipated failures (static dashboards, threshold-based alerts, pre-built runbooks) is structurally incomplete. It&amp;#8217;s building a flashlight that only illuminates rooms you&amp;#8217;ve already been&amp;nbsp;in.&lt;/p&gt;
&lt;h3 id="5-signal-costs-attention-and-attention-is-finite"&gt;5. Signal costs attention, and attention is&amp;nbsp;finite&lt;/h3&gt;
&lt;p&gt;Every metric, log line, and alert competes for a human&amp;#8217;s cognitive bandwidth. An observability system that produces more signal than a human can process is functionally equivalent to one that produces&amp;nbsp;none.&lt;/p&gt;
&lt;p&gt;This is the overlooked constraint that makes &amp;#8220;collect everything&amp;#8221; actively harmful. More data doesn&amp;#8217;t mean better observability. It means more noise to filter before you can think. The art is in emitting the right signals, not all&amp;nbsp;signals.&lt;/p&gt;
&lt;h2 id="what-falls-away"&gt;What Falls&amp;nbsp;Away&lt;/h2&gt;
&lt;p&gt;With only five truths remaining, the conventional view takes some&amp;nbsp;hits.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Three pillars&amp;#8221; as a definition.&lt;/strong&gt; This taxonomy describes data formats, not observability. You can have all three pillars and still be blind to production issues if the data lacks context, correlation, or queryability. Cindy Sridharan made this point in &lt;em&gt;Distributed Systems Observability&lt;/em&gt; &lt;a href="https://www.oreilly.com/library/view/distributed-systems-observability/9781492033431/"&gt;Sridharan, 2018&lt;/a&gt;: the pillars framework tricks teams into thinking the job is done once they&amp;#8217;ve checked three boxes. It conflates the &lt;em&gt;representation&lt;/em&gt; of signals with the &lt;em&gt;property&lt;/em&gt; of being&amp;nbsp;observable.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Collect everything&amp;#8221;.&lt;/strong&gt; This is storage-vendor thinking. It produces massive cost, massive noise, and a false sense of security. Teams drown in data they never query while missing the specific signals that would have caught the outage. The constraint from Truth #5 (attention is finite) kills this approach on&amp;nbsp;contact.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Dashboards = understanding&amp;#8221;.&lt;/strong&gt; Dashboards are answers to questions you&amp;#8217;ve already asked. They excel at confirming known patterns and fail completely at surfacing unknown ones. Over-reliance on dashboards creates a dangerous illusion: the team feels informed because the screens look green, but the failure mode that takes them down won&amp;#8217;t have a&amp;nbsp;panel.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Observability is an ops problem&amp;#8221;.&lt;/strong&gt; If the developer who writes the code doesn&amp;#8217;t think about how it will be observed in production, no amount of post-hoc instrumentation fixes it. Observability is a design property (Truth #1), not an operational afterthought. Separating &amp;#8220;who builds it&amp;#8221; from &amp;#8220;who observes it&amp;#8221; guarantees that the wrong things get&amp;nbsp;instrumented.&lt;/p&gt;
&lt;h2 id="rebuilt-from-scratch"&gt;Rebuilt From&amp;nbsp;Scratch&lt;/h2&gt;
&lt;p&gt;Starting from only the five fundamental truths, here&amp;#8217;s what observability looks like when designed from zero, as if the existing tools and conventions had never&amp;nbsp;existed.&lt;/p&gt;
&lt;h3 id="build-systems-that-explain-themselves"&gt;Build systems that explain&amp;nbsp;themselves&lt;/h3&gt;
&lt;p&gt;Observability isn&amp;#8217;t a layer you add. It&amp;#8217;s a property you design in (Truth #1). Every meaningful state transition, decision branch, and external interaction should emit a structured event that captures enough context to reconstruct &lt;em&gt;why&lt;/em&gt; the system did what it did. Not &amp;#8220;log everything&amp;#8221;. Emit the &lt;em&gt;decisions&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;When a rate limiter throttles a request, that&amp;#8217;s a decision. When a circuit breaker opens, that&amp;#8217;s a decision. When a feature flag routes a user to variant B, that&amp;#8217;s a decision. When a cache lookup misses, &lt;em&gt;that&amp;#8217;s diagnostic information&lt;/em&gt;. These are the events that&amp;nbsp;matter.&lt;/p&gt;
&lt;h3 id="one-event-model-not-three-pillars"&gt;One event model, not three&amp;nbsp;pillars&lt;/h3&gt;
&lt;p&gt;Instead of separate logs, metrics, and traces, emit &lt;strong&gt;rich structured events&lt;/strong&gt; with high-cardinality fields: user &lt;span class="caps"&gt;ID&lt;/span&gt;, request &lt;span class="caps"&gt;ID&lt;/span&gt;, feature flag state, query plan, service version, deployment &lt;span class="caps"&gt;SHA&lt;/span&gt;, whatever gives you the ability to distinguish (Truth #2). From these&amp;nbsp;events:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Metrics&lt;/strong&gt; are aggregations derived from events (count events&amp;nbsp;where &lt;code&gt;status=500&lt;/code&gt;, compute p99&amp;nbsp;of &lt;code&gt;duration_ms&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Traces&lt;/strong&gt; are events correlated by a&amp;nbsp;shared &lt;code&gt;trace_id&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Logs&lt;/strong&gt; are events rendered as&amp;nbsp;text&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The underlying primitive is the same: a timestamped, context-rich structured event. This isn&amp;#8217;t theoretical. It&amp;#8217;s the architecture Honeycomb was built on, and it&amp;#8217;s the direction &lt;a href="https://opentelemetry.io/"&gt;OpenTelemetry&lt;/a&gt; is converging toward with its unified signal&amp;nbsp;model.&lt;/p&gt;
&lt;h3 id="explore-dont-monitor"&gt;Explore, don&amp;#8217;t&amp;nbsp;monitor&lt;/h3&gt;
&lt;p&gt;The primary interaction model should be ad-hoc querying (Truth #4, failures are unpredicted). &amp;#8220;Show me all requests from user X that hit service Y in the last hour, broken down by response code and latency percentile&amp;#8221;. Dashboards become saved queries that proved useful, not the starting point. The system should support questions you&amp;#8217;ve never asked&amp;nbsp;before.&lt;/p&gt;
&lt;p&gt;This is a fundamental shift in posture: from passive monitoring (&amp;#8220;stare at dashboards and wait for red&amp;#8221;) to active exploration (&amp;#8220;I have a hypothesis, let me test it against production&amp;nbsp;data&amp;#8221;).&lt;/p&gt;
&lt;h3 id="alerts-from-invariants-not-thresholds"&gt;Alerts from invariants, not&amp;nbsp;thresholds&lt;/h3&gt;
&lt;p&gt;Instead of &amp;#8220;alert when latency &amp;gt; 500ms&amp;#8221; (a threshold you guessed), define &lt;strong&gt;invariants&lt;/strong&gt;: relationships that should always&amp;nbsp;hold.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Every request must complete within the &lt;span class="caps"&gt;SLO&lt;/span&gt;&amp;nbsp;budget&amp;#8221;&lt;/li&gt;
&lt;li&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;Error rate should be proportional to traffic, not&amp;nbsp;absolute&amp;#8221;&lt;/li&gt;
&lt;li&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;No single dependency should account for &amp;gt;40% of total&amp;nbsp;latency&amp;#8221;&lt;/li&gt;
&lt;li&gt;&lt;span class="dquo"&gt;&amp;#8220;&lt;/span&gt;No data ingested for entity X in 2× the expected&amp;nbsp;interval&amp;#8221;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Invariant violations are structurally more robust than static thresholds because they encode &lt;em&gt;relationships&lt;/em&gt;, not &lt;em&gt;numbers&lt;/em&gt; (Truth #4). &amp;#8220;No data in 2× the expected interval&amp;#8221; adapts automatically when you change the ingestion schedule. &amp;#8220;Data count &amp;lt; 100&amp;#8221; breaks the moment your input set changes&amp;nbsp;size.&lt;/p&gt;
&lt;p&gt;Rob Ewaschuk&amp;#8217;s influential &amp;#8220;My Philosophy on Alerting&amp;#8221; &lt;a href="https://docs.google.com/document/d/199PqyG3UsyXlwieHaqbGiWVa8eMWi8zzAn0YfcApr8Q/edit"&gt;Ewaschuk, 2013&lt;/a&gt; laid the groundwork for this thinking at Google: alert on symptoms (user-visible impact), not causes or static numbers. &lt;span class="caps"&gt;SLO&lt;/span&gt;-based alerting, burn rate alerts on error budgets as described in the Google &lt;span class="caps"&gt;SRE&lt;/span&gt; Workbook &lt;a href="https://sre.google/workbook/alerting-on-slos/"&gt;Beyer et al., 2018&lt;/a&gt;, is one concrete implementation of this principle. Instead of alerting on individual threshold violations, you alert on the &lt;em&gt;rate at which you&amp;#8217;re consuming your error budget&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id="cost-is-proportional-to-questions-answered-not-data-stored"&gt;Cost is proportional to questions answered, not data&amp;nbsp;stored&lt;/h3&gt;
&lt;p&gt;Intelligent sampling keeps costs bounded while preserving diagnostic power (Truth #5). The&amp;nbsp;strategy:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;100% capture&lt;/strong&gt; for state transitions, errors, slow requests, and new&amp;nbsp;deployments&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sample broadly&lt;/strong&gt; (1-10%) for routine, healthy&amp;nbsp;traffic&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic instrumentation&lt;/strong&gt; to temporarily increase detail in areas of&amp;nbsp;interest&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The optimization target is &amp;#8220;can I answer the question I have right now?&amp;#8221;, not &amp;#8220;did I store&amp;nbsp;everything?&amp;#8221;&lt;/p&gt;
&lt;h3 id="the-developer-is-the-operator"&gt;The developer is the&amp;nbsp;operator&lt;/h3&gt;
&lt;p&gt;Instrumentation is part of the code review. &amp;#8220;How will we know this works in production?&amp;#8221; is a design question, asked at the same time as &amp;#8220;how will we test this?&amp;#8221; The feedback loop runs from code → production → understanding → code. If the person who writes the code can&amp;#8217;t observe it running, the loop is broken (Truth&amp;nbsp;#3).&lt;/p&gt;
&lt;h2 id="the-delta"&gt;The&amp;nbsp;Delta&lt;/h2&gt;
&lt;p&gt;Here&amp;#8217;s what changes when you swap conventional thinking for first-principles&amp;nbsp;thinking:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Conventional&lt;/th&gt;
&lt;th&gt;First Principles&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Adopt a platform, instrument with its &lt;span class="caps"&gt;SDK&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;Design systems to emit rich structured events; the platform is a queryable store&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Three separate pipelines (logs, metrics, traces)&lt;/td&gt;
&lt;td&gt;One event pipeline, derive metrics and traces from events&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Build dashboards for every service&lt;/td&gt;
&lt;td&gt;Default to ad-hoc exploration; save queries that prove useful&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alert on static thresholds&lt;/td&gt;
&lt;td&gt;Alert on invariant violations and &lt;span class="caps"&gt;SLO&lt;/span&gt; burn rates&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Collect everything, filter later&lt;/td&gt;
&lt;td&gt;Emit decisions and boundaries; sample intelligently&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ops team owns observability&lt;/td&gt;
&lt;td&gt;Developers own observability of what they build&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&amp;#8220;We need more monitoring&amp;#8221;&lt;/td&gt;
&lt;td&gt;&amp;#8220;We need better questions&amp;#8221;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="what-you-can-do-monday-morning"&gt;What You Can Do Monday&amp;nbsp;Morning&lt;/h2&gt;
&lt;p&gt;This isn&amp;#8217;t abstract philosophy. Here&amp;#8217;s what changes in&amp;nbsp;practice:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Instrument decisions, not just outcomes.&lt;/strong&gt; When your system skips an item, when a rule evaluates but doesn&amp;#8217;t fire, when a candidate is considered but filtered out, those non-events are often more diagnostic than the events you&amp;#8217;re already logging. The question to ask at every code review: &amp;#8220;if this path executes in production and something goes wrong, do we have enough context to understand&amp;nbsp;why?&amp;#8221;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Before adding a dashboard panel, write down the question it answers.&lt;/strong&gt; If you can&amp;#8217;t state the question, you&amp;#8217;re adding noise. Audit your existing dashboards with this lens. You&amp;#8217;ll likely find panels nobody looks at and gaps where real questions go&amp;nbsp;unanswered.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Encode relationships in your alerts.&lt;/strong&gt; Replace absolute thresholds with relative invariants that adapt to your system&amp;#8217;s current configuration. &amp;#8220;Error rate &amp;gt; 1% of traffic&amp;#8221; beats &amp;#8220;errors &amp;gt; 50/min&amp;#8221; because it scales with your system. Your future self, debugging at 2am, will thank&amp;nbsp;you.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Design for correlation.&lt;/strong&gt; Every event should carry enough context to link it to the request, user, deployment, and feature flags that were active. When something goes wrong at step 5 of a pipeline, you should be able to follow the thread back to step 1 without&amp;nbsp;guessing.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Capture 100% of state transitions, sample everything else.&lt;/strong&gt; This is the scaling strategy that preserves diagnostic power while keeping costs bounded. Every order fill, every state change, every error, captured. Every routine health check on a quiet Tuesday,&amp;nbsp;sampled.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The goal isn&amp;#8217;t more data. It&amp;#8217;s better&amp;nbsp;questions.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://doi.org/10.1016/S1474-6670(17)70094-8"&gt;Rudolf Kalman, &amp;#8220;On the General Theory of Control Systems,&amp;#8221; &lt;em&gt;Proceedings of the First &lt;span class="caps"&gt;IFAC&lt;/span&gt; Congress&lt;/em&gt;, 1960&lt;/a&gt; - The original formalization of observability and controllability in linear dynamical&amp;nbsp;systems.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://peter.bourgon.org/blog/2017/02/21/metrics-tracing-and-logging.html"&gt;Peter Bourgon, &amp;#8220;Metrics, tracing, and logging,&amp;#8221; 2017&lt;/a&gt; - The blog post that introduced the widely adopted &amp;#8220;three pillars&amp;#8221; Venn&amp;nbsp;diagram.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.honeycomb.io/blog/observability-a-manifesto"&gt;Honeycomb, &amp;#8220;Observability: A Manifesto&amp;#8221;&lt;/a&gt; - Honeycomb&amp;#8217;s case for why observability is about asking new questions, not collecting known&amp;nbsp;signals.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://charity.wtf/2020/03/03/observability-is-a-many-splendored-thing/"&gt;Charity Majors, &amp;#8220;Observability is a Many-Splendored Thing,&amp;#8221; 2020&lt;/a&gt; - The case for observability as the tool for unknown&amp;nbsp;unknowns.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.oreilly.com/library/view/distributed-systems-observability/9781492033431/"&gt;Cindy Sridharan, &lt;em&gt;Distributed Systems Observability&lt;/em&gt;, O&amp;#8217;Reilly, 2018&lt;/a&gt; - Free book providing a thorough treatment of observability beyond the three-pillar&amp;nbsp;framing.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://sre.google/sre-book/monitoring-distributed-systems/"&gt;Betsy Beyer et al., &amp;#8220;Monitoring Distributed Systems,&amp;#8221; &lt;em&gt;Site Reliability Engineering&lt;/em&gt;, O&amp;#8217;Reilly, 2016&lt;/a&gt; - Google&amp;#8217;s approach to monitoring, including the white-box vs. black-box distinction and the four golden&amp;nbsp;signals.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://sre.google/workbook/alerting-on-slos/"&gt;Betsy Beyer et al., &amp;#8220;Alerting on SLOs,&amp;#8221; &lt;em&gt;The Site Reliability Workbook&lt;/em&gt;, O&amp;#8217;Reilly, 2018&lt;/a&gt; - Practical guide to burn-rate alerting and &lt;span class="caps"&gt;SLO&lt;/span&gt;-based operational&amp;nbsp;practices.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/document/d/199PqyG3UsyXlwieHaqbGiWVa8eMWi8zzAn0YfcApr8Q/edit"&gt;Rob Ewaschuk, &amp;#8220;My Philosophy on Alerting,&amp;#8221; 2013&lt;/a&gt; - Influential Google &lt;span class="caps"&gt;SRE&lt;/span&gt; document arguing alerts should be based on symptoms and user-visible impact, not static&amp;nbsp;thresholds.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.honeycomb.io/blog/how-are-structured-logs-different-from-events"&gt;Honeycomb, &amp;#8220;How Are Structured Logs Different From Events?&amp;#8221;&lt;/a&gt; - Why wide structured events, not log lines or pre-aggregated metrics, are the correct primitive for&amp;nbsp;observability.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://opentelemetry.io/"&gt;OpenTelemetry Project&lt;/a&gt; - The &lt;span class="caps"&gt;CNCF&lt;/span&gt; project converging logs, metrics, and traces into a unified observability&amp;nbsp;framework.&lt;/li&gt;
&lt;/ol&gt;</content><category term="Engineering"/><category term="first-principles"/><category term="observability"/><category term="monitoring"/><category term="logging"/><category term="metrics"/><category term="tracing"/></entry><entry><title>Taming Your Dev Chaos with direnv, .env, and .envrc (Plus a Sneak Peek at mise-en-place)</title><link href="https://alexsavio.github.io/direnv-dotenv-envrc.html" rel="alternate"/><published>2026-01-18T00:00:00+01:00</published><updated>2026-01-18T00:00:00+01:00</updated><author><name>Alexandre Manhães Savio</name></author><id>tag:alexsavio.github.io,2026-01-18:/direnv-dotenv-envrc.html</id><summary type="html">&lt;p&gt;Stop manually juggling env vars like a clown — learn how direnv auto-magically handles your dev environments with .env and .envrc files. Includes a sick custom layout uv function for Python projects and a teaser on mise-en-place, the dev tool that does it&amp;nbsp;all.&lt;/p&gt;</summary><content type="html">&lt;h1 id="taming-your-dev-chaos-with-direnv-env-and-envrc"&gt;Taming Your Dev Chaos with direnv, .env, and&amp;nbsp;.envrc&lt;/h1&gt;
&lt;p&gt;Ever felt like you&amp;#8217;re playing whack-a-mole with environment variables across a dozen projects? One project&amp;#8217;s&amp;nbsp;got &lt;code&gt;DEBUG=true&lt;/code&gt;, another&amp;#8217;s screaming&amp;nbsp;for &lt;code&gt;API_KEY=secret-sauce&lt;/code&gt;, and you&amp;#8217;re just there manually sourcing shit like it&amp;#8217;s 1999? Yeah, we&amp;#8217;ve all been there, sweating bullets trying not to mix up prod and dev configs.
Enter &lt;strong&gt;direnv&lt;/strong&gt; — the lazy dev&amp;#8217;s best friend that automatically loads and unloads your env vars based on where&amp;nbsp;you &lt;code&gt;cd&lt;/code&gt;. It&amp;#8217;s like having a personal assistant that whispers &amp;#8220;you&amp;#8217;re in the wrong project, dumbass&amp;#8221; before you fuck&amp;nbsp;up.&lt;/p&gt;
&lt;h2 id="what-the-hell-is-direnv"&gt;What the Hell is&amp;nbsp;direnv?&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://direnv.net/"&gt;direnv&lt;/a&gt; is basically a shell extension that gives your terminal superpowers. It hooks into bash, zsh, fish, and whatever else you&amp;#8217;re using, automatically loading or unloading environment variables as you bounce between directories. No more &amp;#8220;oh shit, I forgot to activate the venv&amp;#8221; moments.&amp;nbsp;Just &lt;code&gt;cd&lt;/code&gt; and boom — your environment&amp;#8217;s ready to&amp;nbsp;party.&lt;/p&gt;
&lt;h3 id="getting-this-bad-boy-installed"&gt;Getting This Bad Boy&amp;nbsp;Installed&lt;/h3&gt;
&lt;p&gt;On macOS with Homebrew (because who doesn&amp;#8217;t love&amp;nbsp;brew?):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;brew&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;direnv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;On Ubuntu/Debian (for you Linux&amp;nbsp;warriors):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;apt&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;direnv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now hook it into your shell. For zsh (the cool kids&amp;#8217; choice), slap this in&amp;nbsp;your &lt;code&gt;~/.zshrc&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nb"&gt;eval&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;direnv&lt;span class="w"&gt; &lt;/span&gt;hook&lt;span class="w"&gt; &lt;/span&gt;zsh&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Restart your terminal and you&amp;#8217;re golden. Pro tip: If you&amp;#8217;re still using bash, no judgment, but maybe upgrade your life while you&amp;#8217;re at&amp;nbsp;it.&lt;/p&gt;
&lt;h2 id="the-envrc-file-your-new-bestie"&gt;The .envrc File: Your New&amp;nbsp;Bestie&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;.envrc&lt;/code&gt; file is direnv&amp;#8217;s command center — it&amp;#8217;s basically a bash script that runs every time you enter the directory. Think of it as your project&amp;#8217;s personal hype man. Here&amp;#8217;s a basic&amp;nbsp;example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# .envrc&lt;/span&gt;
&lt;span class="nb"&gt;export&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"postgres://localhost/mydb"&lt;/span&gt;
&lt;span class="nb"&gt;export&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;DEBUG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;After you create or tweak&amp;nbsp;your &lt;code&gt;.envrc&lt;/code&gt;, you gotta approve&amp;nbsp;it:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;direnv&lt;span class="w"&gt; &lt;/span&gt;allow
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Yeah, it&amp;#8217;s got security vibes — direnv ain&amp;#8217;t about to run random code without your say-so. Smart move, prevents you from accidentally nuking your system with some sketchy&amp;nbsp;project&amp;#8217;s &lt;code&gt;.envrc&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="the-env-file-and-that-sweet-dotenv_if_exists-magic"&gt;The .env File and That&amp;nbsp;Sweet &lt;code&gt;dotenv_if_exists&lt;/code&gt; Magic&lt;/h2&gt;
&lt;p&gt;Most apps these days&amp;nbsp;use &lt;code&gt;.env&lt;/code&gt; files for their secrets (thanks to that &lt;a href="https://12factor.net/config"&gt;twelve-factor app&lt;/a&gt; gospel). It&amp;#8217;s just key-value pairs, no&amp;nbsp;frills:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# .env&lt;/span&gt;
&lt;span class="nv"&gt;SECRET_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mysupersecretkey
&lt;span class="nv"&gt;API_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;abc123
&lt;span class="nv"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;postgres://user:pass@localhost/db
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Direnv can slurp these up automatically&amp;nbsp;with &lt;code&gt;dotenv_if_exists&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# .envrc&lt;/span&gt;
dotenv_if_exists
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;What it&amp;nbsp;does:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Checks&amp;nbsp;if &lt;code&gt;.env&lt;/code&gt; exists in your current&amp;nbsp;dir&lt;/li&gt;
&lt;li&gt;If yes, loads all the&amp;nbsp;vars&lt;/li&gt;
&lt;li&gt;If no, shrugs and moves on (no&amp;nbsp;drama)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Why this&amp;nbsp;slaps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;.env&lt;/code&gt; goes&amp;nbsp;in &lt;code&gt;.gitignore&lt;/code&gt; (secrets stay secret,&amp;nbsp;duh)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.envrc&lt;/code&gt; gets committed (tells your team what vars they&amp;nbsp;need)&lt;/li&gt;
&lt;li&gt;Everyone on the team can have their&amp;nbsp;own &lt;code&gt;.env&lt;/code&gt; with different values — no more &amp;#8220;why is this broken on my&amp;nbsp;machine?&amp;#8221;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="leveling-up-python-projects-with-layout-uv"&gt;Leveling Up Python Projects&amp;nbsp;with &lt;code&gt;layout uv&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;With &lt;a href="https://github.com/astral-sh/uv"&gt;uv&lt;/a&gt; dropping like a boss as the fastest Python package manager around, I cooked up a&amp;nbsp;custom &lt;code&gt;layout uv&lt;/code&gt; function that pairs perfectly with direnv. It&amp;#8217;s&amp;nbsp;lit.&lt;/p&gt;
&lt;p&gt;Drop this in&amp;nbsp;your &lt;code&gt;~/.config/direnv/direnvrc&lt;/code&gt; (or &lt;code&gt;~/.direnvrc&lt;/code&gt; if you&amp;#8217;re old&amp;nbsp;school):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;layout_uv&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-gt&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;shift&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-d&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;".venv"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nv"&gt;VIRTUAL_ENV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$UV_PROJECT_ENVIRONMENT&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-z&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$VIRTUAL_ENV&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;||&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;!&lt;span class="w"&gt; &lt;/span&gt;-d&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$VIRTUAL_ENV&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;log_status&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"No virtual environment exists. Executing \`uv venv\` to create one."&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;uv&lt;span class="w"&gt; &lt;/span&gt;venv&lt;span class="w"&gt; &lt;/span&gt;--allow-existing
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nv"&gt;VIRTUAL_ENV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$UV_PROJECT_ENVIRONMENT&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;PATH_add&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$VIRTUAL_ENV&lt;/span&gt;&lt;span class="s2"&gt;/bin"&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;export&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;UV_ACTIVE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# or VENV_ACTIVE=1&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;export&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;VIRTUAL_ENV
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Then in your&amp;nbsp;project&amp;#8217;s &lt;code&gt;.envrc&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# .envrc&lt;/span&gt;
dotenv_if_exists
layout&lt;span class="w"&gt; &lt;/span&gt;uv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="what-does-this-layout-uv-sorcery-actually-do"&gt;What Does&amp;nbsp;This &lt;code&gt;layout uv&lt;/code&gt; Sorcery Actually&amp;nbsp;Do?&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Checks for existing venv&lt;/strong&gt;:&amp;nbsp;If &lt;code&gt;.venv&lt;/code&gt; is already chilling there, it rolls with&amp;nbsp;it&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Creates one if needed&lt;/strong&gt;: No venv? No problem —&amp;nbsp;runs &lt;code&gt;uv venv&lt;/code&gt; and makes&amp;nbsp;one&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Activates it&lt;/strong&gt;: Slaps the&amp;nbsp;venv&amp;#8217;s &lt;code&gt;bin&lt;/code&gt; into&amp;nbsp;your &lt;code&gt;PATH&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sets the flags&lt;/strong&gt;:&amp;nbsp;Exports &lt;code&gt;UV_ACTIVE=1&lt;/code&gt; and &lt;code&gt;VIRTUAL_ENV&lt;/code&gt; for tools that&amp;nbsp;care&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="watch-the-magic-happen"&gt;Watch the Magic&amp;nbsp;Happen&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;$&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;~/projects/my-python-project
direnv:&lt;span class="w"&gt; &lt;/span&gt;loading&lt;span class="w"&gt; &lt;/span&gt;~/projects/my-python-project/.envrc
direnv:&lt;span class="w"&gt; &lt;/span&gt;No&lt;span class="w"&gt; &lt;/span&gt;virtual&lt;span class="w"&gt; &lt;/span&gt;environment&lt;span class="w"&gt; &lt;/span&gt;exists.&lt;span class="w"&gt; &lt;/span&gt;Executing&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;uv&lt;span class="w"&gt; &lt;/span&gt;venv&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;to&lt;span class="w"&gt; &lt;/span&gt;create&lt;span class="w"&gt; &lt;/span&gt;one.
Using&lt;span class="w"&gt; &lt;/span&gt;CPython&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;.13.0
Creating&lt;span class="w"&gt; &lt;/span&gt;virtual&lt;span class="w"&gt; &lt;/span&gt;environment&lt;span class="w"&gt; &lt;/span&gt;at:&lt;span class="w"&gt; &lt;/span&gt;.venv
Activate&lt;span class="w"&gt; &lt;/span&gt;with:&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;source&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;.venv/bin/activate
direnv:&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;export&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;+UV_ACTIVE&lt;span class="w"&gt; &lt;/span&gt;+VIRTUAL_ENV&lt;span class="w"&gt; &lt;/span&gt;~PATH

$&lt;span class="w"&gt; &lt;/span&gt;which&lt;span class="w"&gt; &lt;/span&gt;python
/Users/alex/projects/my-python-project/.venv/bin/python

$&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;~
direnv:&lt;span class="w"&gt; &lt;/span&gt;unloading

$&lt;span class="w"&gt; &lt;/span&gt;which&lt;span class="w"&gt; &lt;/span&gt;python
/usr/bin/python
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Boom. Automatic venv activation. Your future self will thank&amp;nbsp;you.&lt;/p&gt;
&lt;h2 id="pro-tips-to-not-fuck-this-up"&gt;Pro Tips to Not Fuck This&amp;nbsp;Up&lt;/h2&gt;
&lt;h3 id="1-secrets-in-env-structure-in-envrc"&gt;1. Secrets&amp;nbsp;in &lt;code&gt;.env&lt;/code&gt;, Structure&amp;nbsp;in &lt;code&gt;.envrc&lt;/code&gt;&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# .envrc (commit this shit)&lt;/span&gt;
dotenv_if_exists
layout&lt;span class="w"&gt; &lt;/span&gt;uv

&lt;span class="c1"&gt;# Required environment variables (document this for your team)&lt;/span&gt;
&lt;span class="c1"&gt;# DATABASE_URL - PostgreSQL connection string&lt;/span&gt;
&lt;span class="c1"&gt;# API_KEY - Your API key from example.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# .env (keep this out of git, you idiot)&lt;/span&gt;
&lt;span class="nv"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;postgres://localhost/mydb
&lt;span class="nv"&gt;API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;secret123
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="2-drop-a-envexample-template"&gt;2. Drop&amp;nbsp;a &lt;code&gt;.env.example&lt;/code&gt; Template&lt;/h3&gt;
&lt;p&gt;Make&amp;nbsp;a &lt;code&gt;.env.example&lt;/code&gt; that shows what vars are needed, minus the actual&amp;nbsp;secrets:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# .env.example&lt;/span&gt;
&lt;span class="nv"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;postgres://user:password@localhost/dbname
&lt;span class="nv"&gt;API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-api-key-here
&lt;span class="nv"&gt;DEBUG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="3-use-direnv-allow-like-your-life-depends-on-it"&gt;3.&amp;nbsp;Use &lt;code&gt;direnv allow&lt;/code&gt; Like Your Life Depends on&amp;nbsp;It&lt;/h3&gt;
&lt;p&gt;Only&amp;nbsp;allow &lt;code&gt;.envrc&lt;/code&gt; files from projects you trust. This ain&amp;#8217;t a free-for-all — malicious code could ruin your&amp;nbsp;day.&lt;/p&gt;
&lt;h3 id="4-team-up-with-uvs-pyprojecttoml"&gt;4. Team Up with uv&amp;#8217;s&amp;nbsp;pyproject.toml&lt;/h3&gt;
&lt;p&gt;With &lt;code&gt;layout uv&lt;/code&gt; and&amp;nbsp;a &lt;code&gt;pyproject.toml&lt;/code&gt;, your whole Python setup is declarative &lt;span class="caps"&gt;AF&lt;/span&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# pyproject.toml&lt;/span&gt;
&lt;span class="k"&gt;[project]&lt;/span&gt;
&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"my-project"&lt;/span&gt;
&lt;span class="n"&gt;requires-python&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;gt;=3.11"&lt;/span&gt;
&lt;span class="n"&gt;dependencies&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="s2"&gt;"requests&amp;gt;=2.31.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="s2"&gt;"click&amp;gt;=8.1.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;cd&lt;/code&gt; into your project and everything&amp;#8217;s ready to roll. No more &amp;#8220;pip install&amp;#8221;&amp;nbsp;nightmares.&lt;/p&gt;
&lt;h2 id="wrapping-this-shit-up"&gt;Wrapping This Shit&amp;nbsp;Up&lt;/h2&gt;
&lt;p&gt;Direnv&amp;nbsp;+ &lt;code&gt;.env&lt;/code&gt; +&amp;nbsp;custom &lt;code&gt;layout uv&lt;/code&gt; = dev environment&amp;nbsp;heaven:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Automatic &lt;span class="caps"&gt;AF&lt;/span&gt;&lt;/strong&gt;: No more forgetting to activate&amp;nbsp;venvs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Secure as Fuck&lt;/strong&gt;: Secrets stay out of&amp;nbsp;git&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Blazing Fast&lt;/strong&gt;: uv creates venvs in the blink of an&amp;nbsp;eye&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Team-Friendly&lt;/strong&gt;:&amp;nbsp;Share &lt;code&gt;.envrc&lt;/code&gt;, keep&amp;nbsp;personal &lt;code&gt;.env&lt;/code&gt; files&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Try it out — once you go automatic, you&amp;#8217;ll wonder how you survived the manual era. Your productivity will skyrocket, and you&amp;#8217;ll have more time for&amp;nbsp;memes.&lt;/p&gt;
&lt;h2 id="future-vibes-mise-en-place"&gt;Future Vibes:&amp;nbsp;mise-en-place&lt;/h2&gt;
&lt;p&gt;Direnv is solid and battle-tested, but peep this new kid on the block: &lt;strong&gt;&lt;a href="https://mise.jdx.dev/"&gt;mise-en-place&lt;/a&gt;&lt;/strong&gt; (say it like &amp;#8220;meez&amp;#8221;). It&amp;#8217;s the dev tool that wants to be your&amp;nbsp;everything.&lt;/p&gt;
&lt;p&gt;Mise&amp;nbsp;combines:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Tool version management&lt;/strong&gt; (think asdf/nvm/pyenv but&amp;nbsp;better)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Environment variable handling&lt;/strong&gt; (direnv&amp;#8217;s&amp;nbsp;job)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Task running&lt;/strong&gt; (make/just&amp;nbsp;territory)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The big win? &lt;strong&gt;One tool to rule them all&lt;/strong&gt;. No more juggling direnv + asdf + make like a circus act.&amp;nbsp;One &lt;code&gt;mise.toml&lt;/code&gt; config file handles it&amp;nbsp;all:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;# mise.toml&lt;/span&gt;
&lt;span class="k"&gt;[tools]&lt;/span&gt;
&lt;span class="n"&gt;python&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"3.13"&lt;/span&gt;
&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"20"&lt;/span&gt;

&lt;span class="k"&gt;[env]&lt;/span&gt;
&lt;span class="n"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"postgres://localhost/mydb"&lt;/span&gt;

&lt;span class="k"&gt;[tasks.dev]&lt;/span&gt;
&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"python manage.py runserver"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;It auto-activates Python venvs,&amp;nbsp;loads &lt;code&gt;.env&lt;/code&gt; files, and plays nice with&amp;nbsp;existing &lt;code&gt;.tool-versions&lt;/code&gt; from asdf. Built in Rust, so it&amp;#8217;s faster than your ex moving on. If you&amp;#8217;re drowning in tool sprawl, mise might be your lifesaver. I&amp;#8217;ll drop a full migration guide soon — stay&amp;nbsp;woke!&lt;/p&gt;
&lt;h2 id="links-and-shit"&gt;Links and&amp;nbsp;Shit&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://direnv.net/"&gt;direnv docs&lt;/a&gt; - The &lt;span class="caps"&gt;OG&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/astral-sh/uv"&gt;uv - Python&amp;#8217;s speed&amp;nbsp;demon&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://12factor.net/config"&gt;Twelve-Factor App - Config&amp;nbsp;wisdom&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mise.jdx.dev/"&gt;mise-en-place&lt;/a&gt; - The unified&amp;nbsp;beast&lt;/li&gt;
&lt;/ul&gt;</content><category term="Tools"/><category term="direnv"/><category term="environment"/><category term="shell"/><category term="uv"/><category term="python"/><category term="mise"/></entry><entry><title>Git usage guidelines for team collaboration</title><link href="https://alexsavio.github.io/git-collaboration-guidelines.html" rel="alternate"/><published>2020-06-11T12:00:00+02:00</published><updated>2020-06-11T12:00:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2020-06-11:/git-collaboration-guidelines.html</id><summary type="html">&lt;p&gt;Suggestions on how to use a code repository with git for&amp;nbsp;teams.&lt;/p&gt;</summary><content type="html">&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;This is a set of rules that I have been gathering in the past few years which work well for most of the projects I worked on with small teams of 3-8 people. These guidelines are heavily based on the &lt;a href="https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines"&gt;angular.js/&lt;span class="caps"&gt;DEVELOPERS&lt;/span&gt;.md document on  GitHub&lt;/a&gt; and this is not about &lt;a href="https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow"&gt;GitFlow&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="branching-model"&gt;Branching&amp;nbsp;model&lt;/h2&gt;
&lt;p&gt;Always create a new branch from an up-to-date &amp;#8220;main&amp;#8221; branch.
The branches should have a short life (no more than 2 days) and have a very determined objective.
Once the objective is reached, a Pull Request (&lt;span class="caps"&gt;PR&lt;/span&gt;) should be created to merge the branch to main.
Once the branch is merged, it should be deleted.
Always merge to&amp;nbsp;main.&lt;/p&gt;
&lt;h3 id="branch-names"&gt;Branch&amp;nbsp;names&lt;/h3&gt;
&lt;p&gt;The branch names are not that important in very small teams, but when the team is bigger or work remotely,
a pattern for the branch names is also good to follow. Here is a&amp;nbsp;suggestion:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;```&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;[&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ticket_id&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;]&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Some tools like &lt;a href="https://www.sourcetreeapp.com/"&gt;Sourcetree&lt;/a&gt; pick&amp;nbsp;the &lt;code&gt;/&lt;/code&gt; from the branch name and splits the name in their &lt;span class="caps"&gt;GUI&lt;/span&gt;,
so you can see the different types of branches as in different&amp;nbsp;folders.&lt;/p&gt;
&lt;h4 id="type"&gt;Type&lt;/h4&gt;
&lt;p&gt;The &lt;type&gt; describes the generic objective of the branch, it can be one of the&amp;nbsp;following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;feat&lt;/strong&gt;: a new&amp;nbsp;feature,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;fix&lt;/strong&gt;: a bug&amp;nbsp;fix,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;docs&lt;/strong&gt;: documentation only changes (in or out of the&amp;nbsp;code),&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;tests&lt;/strong&gt;: new tests or fixes in&amp;nbsp;tests,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;refactor&lt;/strong&gt;: code change that neither fixes a bug or adds a&amp;nbsp;feature,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;style&lt;/strong&gt;: code changes that&amp;nbsp;neither,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;chore&lt;/strong&gt;: Changes to the build process or auxiliary tools for the project&amp;nbsp;maintenance,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;perf&lt;/strong&gt;: A code change that improves&amp;nbsp;performance.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="ticket-id"&gt;Ticket &lt;span class="caps"&gt;ID&lt;/span&gt;&lt;/h4&gt;
&lt;p&gt;This is optional, but is good if the purpose of the branch is too complex or if you follow a Scrum development process.
The &lt;ticket_id&gt; should be the identifier of the ticket or user story that the branch is going to solve.
The format depends on the project management tool you are using, but usually it has a project acronym and a&amp;nbsp;number: &lt;code&gt;PRJ_123&lt;/code&gt;.&lt;/p&gt;
&lt;h4 id="subject"&gt;Subject&lt;/h4&gt;
&lt;p&gt;The &lt;subject&gt; part should be no more than 3 or 4 words about the specific objective of the branch.
If you don’t put a ticket &lt;span class="caps"&gt;ID&lt;/span&gt;, the specificity of the name is more&amp;nbsp;relevant.&lt;/p&gt;
&lt;h3 id="commit-messages"&gt;Commit&amp;nbsp;messages&lt;/h3&gt;
&lt;p&gt;Here we follow a very specific pattern in order to be able to parse the commit messages to automatically generate a
change log for each release in a &lt;span class="caps"&gt;CI&lt;/span&gt;/&lt;span class="caps"&gt;CD&lt;/span&gt; process and also semantic release version bumps
with tools like semantic-release (available for Node.js and&amp;nbsp;Python).&lt;/p&gt;
&lt;h4 id="format"&gt;Format&lt;/h4&gt;
&lt;p&gt;Each commit message consists of a header, a body and a footer. The header has a special format that includes a type, a scope and a&amp;nbsp;subject:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;```&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;):&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;BLANK&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;LINE&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;BLANK&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;LINE&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;footer&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The header is mandatory and the scope of the header is optional.
Any line of the commit message cannot be longer 100 characters!
This allows the message to be easier to read on GitHub as well as in various git&amp;nbsp;tools.&lt;/p&gt;
&lt;h5 id="type_1"&gt;Type&lt;/h5&gt;
&lt;p&gt;The &lt;type&gt; describes the generic objective of the commit, use the same types used for branches. I will repeat them&amp;nbsp;here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;feat&lt;/strong&gt;: a new&amp;nbsp;feature,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;fix&lt;/strong&gt;: a bug&amp;nbsp;fix,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;docs&lt;/strong&gt;: documentation only changes (in or out of the&amp;nbsp;code),&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;tests&lt;/strong&gt;: new tests or fixes in&amp;nbsp;tests,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;refactor&lt;/strong&gt;: code change that neither fixes a bug or adds a&amp;nbsp;feature,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;style&lt;/strong&gt;: code changes that&amp;nbsp;neither,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;chore&lt;/strong&gt;: Changes to the build process or auxiliary tools for the project&amp;nbsp;maintenance,&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;perf&lt;/strong&gt;: A code change that improves&amp;nbsp;performance.&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id="scope"&gt;Scope&lt;/h5&gt;
&lt;p&gt;The &lt;scope&gt; could be anything specifying place of the commit change. A scope should be a part of the project that the stakeholders understand.
The possible scopes can be agreed beforehand with the developers and/or stakeholders.
You can use * when the change affects more than a single scope, but you can also not put anything (remove the parentheses as&amp;nbsp;well).&lt;/p&gt;
&lt;h5 id="subject_1"&gt;Subject&lt;/h5&gt;
&lt;p&gt;The &lt;subject&gt; contains succinct description of the&amp;nbsp;change:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;use the imperative, present tense: &amp;#8220;change&amp;#8221; not &amp;#8220;changed&amp;#8221; nor&amp;nbsp;&amp;#8220;changes&amp;#8221;&lt;/li&gt;
&lt;li&gt;don&amp;#8217;t capitalize first&amp;nbsp;letter&lt;/li&gt;
&lt;li&gt;no dot (.) at the&amp;nbsp;end&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Don’t use generic subjects as: &amp;#8216;debug&amp;#8217; or &amp;#8216;few fixes&amp;#8217;. Be clear and&amp;nbsp;specific.&lt;/p&gt;
&lt;h5 id="body"&gt;Body&lt;/h5&gt;
&lt;p&gt;The &lt;body&gt; is optional, but if you use it, just as in the subject, use the imperative, present tense: &amp;#8220;change&amp;#8221; not &amp;#8220;changed&amp;#8221; nor &amp;#8220;changes&amp;#8221;.
The body should include the motivation for the change and contrast
this with the previous&amp;nbsp;behavior.&lt;/p&gt;
&lt;h5 id="footer"&gt;Footer&lt;/h5&gt;
&lt;p&gt;The &lt;footer&gt; is optional. The footer should contain any information about Breaking Changes and is also the place to reference GitHub issues that this commit closes.
Breaking Changes should start with the word &lt;span class="caps"&gt;BREAKING&lt;/span&gt; &lt;span class="caps"&gt;CHANGE&lt;/span&gt;: with a space or two newlines. The rest of the commit message is then used for this.
A detailed explanation can be found in the Angular.js&amp;nbsp;document.&lt;/p&gt;
&lt;h3 id="pull-requests"&gt;Pull&amp;nbsp;Requests&lt;/h3&gt;
&lt;p&gt;The Pull or Merge Requests (&lt;span class="caps"&gt;PR&lt;/span&gt;) are used to share with your co-developers the code changes
you did in your branch and ask them to review it. Here we always do a &lt;span class="caps"&gt;PR&lt;/span&gt; from your branch to
the &amp;#8216;main&amp;#8217;&amp;nbsp;branch.&lt;/p&gt;
&lt;p&gt;In a &lt;span class="caps"&gt;PR&lt;/span&gt;, your colleagues will have a view of the differences between the branches and the
commits. You must also add a title and a&amp;nbsp;description.&lt;/p&gt;
&lt;p&gt;The title should be sufficient to understand what is being&amp;nbsp;changed.&lt;/p&gt;
&lt;p&gt;In the description you&amp;nbsp;should:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;make a useful&amp;nbsp;description,&lt;/li&gt;
&lt;li&gt;describe what was changed in the pull&amp;nbsp;request,&lt;/li&gt;
&lt;li&gt;explain why this &lt;span class="caps"&gt;PR&lt;/span&gt;&amp;nbsp;exists,&lt;/li&gt;
&lt;li&gt;make it clear how it does what it sets out to do. E.g: Does it change a column in the&amp;nbsp;database?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;How is this being done? What happens to the old&amp;nbsp;data?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you may want to use screenshots to demonstrate what has changed if there is a
&lt;span class="caps"&gt;GUI&lt;/span&gt; involved in the&amp;nbsp;project.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Pull request size:&lt;/strong&gt; It should be small. The pull request must have a maximum of 250 lines of change.
&lt;strong&gt;Feature breaking:&lt;/strong&gt; Whenever it’s possible break pull requests into smaller ones.
&lt;strong&gt;Single Responsibility Principle:&lt;/strong&gt; The pull request should do only 1&amp;nbsp;thing.&lt;/p&gt;
&lt;h3 id="cicd"&gt;&lt;span class="caps"&gt;CI&lt;/span&gt;/&lt;span class="caps"&gt;CD&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;With this setup your &lt;span class="caps"&gt;CI&lt;/span&gt;/&lt;span class="caps"&gt;CD&lt;/span&gt; pipeline&amp;nbsp;would:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;run your checks and tests for every push to a &lt;span class="caps"&gt;PR&lt;/span&gt; and every merge to&amp;nbsp;&amp;#8216;main&amp;#8217;,&lt;/li&gt;
&lt;li&gt;run a deployment to your test environment every merge to &amp;#8216;main&amp;#8217;,&amp;nbsp;and&lt;/li&gt;
&lt;li&gt;enable a manual deployment to your production environment for every merge to&amp;nbsp;&amp;#8216;main&amp;#8217;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This deployment should trigger a release first, with automatic version bumping
and change log generation. Bitbucket-pipelines supports&amp;nbsp;this.&lt;/p&gt;
&lt;h3 id="remember-git-is-a-collaboration-tool-not-a-reporting-tool"&gt;&lt;span style="color:red"&gt;Remember: git is a collaboration tool, not a reporting&amp;nbsp;tool.&lt;/span&gt;&lt;/h3&gt;
&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://medium.com/@hugooodias/the-anatomy-of-a-perfect-pull-request-567382bb6067"&gt;The anatomy of a perfect pull request – Hugo Dias –&amp;nbsp;Medium&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.conventionalcommits.org/en/v1.0.0-beta.4/#specification"&gt;Conventional&amp;nbsp;Commits&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow"&gt;Gitflow Workflow | Atlassian Git&amp;nbsp;Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines"&gt;angular.js/&lt;span class="caps"&gt;DEVELOPERS&lt;/span&gt;.md at master · angular/angular.js ·&amp;nbsp;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/semantic-release/semantic-release"&gt;GitHub - semantic-release/semantic-release: Fully automated version management and package&amp;nbsp;publishing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.sourcetreeapp.com/"&gt;Sourcetree&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><category term="Tools"/><category term="git"/><category term="workflow"/><category term="collaboration"/></entry><entry><title>Remove big files from a git repository</title><link href="https://alexsavio.github.io/git-cleanup-bfg.html" rel="alternate"/><published>2017-12-30T12:28:00+01:00</published><updated>2017-12-30T12:28:00+01:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2017-12-30:/git-cleanup-bfg.html</id><summary type="html">&lt;p&gt;Remove large blobs from your git repository&amp;nbsp;history&lt;/p&gt;</summary><content type="html">&lt;h3 id="introduction"&gt;Introduction&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://rtyley.github.io/bfg-repo-cleaner/"&gt;&lt;span class="caps"&gt;BFG&lt;/span&gt; Repo-Cleaner&lt;/a&gt; is a tool to &amp;#8220;remove large or troublesome blobs&amp;#8221; from Git&amp;nbsp;repositories.&lt;/p&gt;
&lt;p&gt;Here goes a quick guide on how to remove files larger than 10&amp;nbsp;MiB.&lt;/p&gt;
&lt;h3 id="installation"&gt;Installation&lt;/h3&gt;
&lt;p&gt;Download the lastest release from https://rtyley.github.io/bfg-repo-cleaner/.
It includes&amp;nbsp;a &lt;code&gt;.jar&lt;/code&gt; file which we will use through the command&amp;nbsp;line.&lt;/p&gt;
&lt;p&gt;You can&amp;nbsp;use &lt;code&gt;bfg&lt;/code&gt; as an alias&amp;nbsp;for &lt;code&gt;java -jar ~/Software/bfg-1.12.16.jar&lt;/code&gt;.
Meaning that&amp;nbsp;&amp;#8220;&lt;code&gt;~/Software/bfg-1.12.16.jar&lt;/code&gt;&amp;#8221; is wherever you downloaded&amp;nbsp;the &lt;code&gt;.jar&lt;/code&gt; file.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nb"&gt;alias&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;bfg&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;java&lt;span class="w"&gt; &lt;/span&gt;-jar&lt;span class="w"&gt; &lt;/span&gt;~/Software/bfg-1.12.16.jar
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="first-step"&gt;First&amp;nbsp;step&lt;/h3&gt;
&lt;p&gt;First you must delete the blobs that you want to delete from the &lt;span class="caps"&gt;HEAD&lt;/span&gt; of your repository, commit, and&amp;nbsp;push.&lt;/p&gt;
&lt;h3 id="usage"&gt;Usage&lt;/h3&gt;
&lt;p&gt;Clone your repository in mirror&amp;nbsp;mode:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;git&lt;span class="w"&gt; &lt;/span&gt;clone&lt;span class="w"&gt; &lt;/span&gt;--mirror&lt;span class="w"&gt; &lt;/span&gt;git://example.com/some-big-repo.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Run &lt;span class="caps"&gt;BFG&lt;/span&gt; to delete files bigger than 10MiB (see more examples in the project&amp;nbsp;documentation):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;bfg&lt;span class="w"&gt; &lt;/span&gt;--strip-blobs-bigger-than&lt;span class="w"&gt; &lt;/span&gt;10M&lt;span class="w"&gt; &lt;/span&gt;some-big-repo.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Prune the reference log entries and&amp;nbsp;push:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;some-big-repo.git
git&lt;span class="w"&gt; &lt;/span&gt;reflog&lt;span class="w"&gt; &lt;/span&gt;expire&lt;span class="w"&gt; &lt;/span&gt;--expire&lt;span class="o"&gt;=&lt;/span&gt;now&lt;span class="w"&gt; &lt;/span&gt;--all&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git&lt;span class="w"&gt; &lt;/span&gt;gc&lt;span class="w"&gt; &lt;/span&gt;--prune&lt;span class="o"&gt;=&lt;/span&gt;now&lt;span class="w"&gt; &lt;/span&gt;--aggressive
git&lt;span class="w"&gt; &lt;/span&gt;push
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://rtyley.github.io/bfg-repo-cleaner/"&gt;https://rtyley.github.io/bfg-repo-cleaner/&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</content><category term="Tools"/><category term="git"/><category term="bfg"/><category term="cleanup"/><category term="history-rewrite"/></entry><entry><title>Access Google Spreadsheets using gspread and OAuth2Client</title><link href="https://alexsavio.github.io/gspread_oauth2client_intro.html" rel="alternate"/><published>2015-05-14T19:11:46+02:00</published><updated>2016-03-29T13:30:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2015-05-14:/gspread_oauth2client_intro.html</id><summary type="html">&lt;p&gt;How to access Google spreadsheets using the Python module gspread and the OAuth2Client authorization&amp;nbsp;system.&lt;/p&gt;</summary><content type="html">&lt;p&gt;Jump to &lt;a href="#materials"&gt;the Materials and Methods section&lt;/a&gt; if you don&amp;#8217;t want to read the&amp;nbsp;introduction.&lt;/p&gt;
&lt;p&gt;This post presents a way of accessing Google Spreadsheets(&lt;span class="caps"&gt;GS&lt;/span&gt;) and securely distributing Python source code that  uses &lt;span class="caps"&gt;GS&lt;/span&gt;.&lt;/p&gt;
&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://docs.google.com/spreadsheets/"&gt;Google spreadsheets&lt;/a&gt;(&lt;span class="caps"&gt;GS&lt;/span&gt;) are useful for fast deployment of simple
forms on the web as well as share and collaborate on simple data structures with other&amp;nbsp;people.&lt;/p&gt;
&lt;p&gt;Not everybody has enough experience with the sheet cell functionalities and the small devils of the spreadsheet world. You may find yourself trapped on the &lt;a href="https://support.google.com/docs"&gt;Google Docs help&lt;/a&gt; or looking for that non-existent function in the &lt;a href="https://support.google.com/docs/table/25273?hl=en"&gt;&lt;span class="caps"&gt;GS&lt;/span&gt; reference&lt;/a&gt; trying to program more complex data processes. In those cases I feel the urge to unleash the power of Python over the&amp;nbsp;data.&lt;/p&gt;
&lt;p&gt;There are ways of doing that through the Official Google Spreasheet &lt;span class="caps"&gt;API&lt;/span&gt;. The &lt;span class="caps"&gt;API&lt;/span&gt; is flexible but can take a considerable amount of work if your idea is &amp;#8220;just&amp;#8221; accessing the data of the spreadsheets and doing a few operations on&amp;nbsp;them.&lt;/p&gt;
&lt;p&gt;To leverage all the &lt;span class="caps"&gt;API&lt;/span&gt; work and help us all there is &lt;a href="https://github.com/burnash/gspread"&gt;gspread&lt;/a&gt;, which wraps up the &lt;span class="caps"&gt;API&lt;/span&gt; and makes clear and pragmatic functions&amp;nbsp;sprout.&lt;/p&gt;
&lt;h3 id="how-to-authenticate-through-gspread"&gt;How to authenticate through&amp;nbsp;gspread&lt;/h3&gt;
&lt;p&gt;Initially the authentication method to use gpsread was using username and password pair. This is a problem when you need to share your application with other people. You can&amp;#8217;t share your passwords, create user accounts for every user of your application or even, you would have to share your common document to every user you&amp;nbsp;have.&lt;/p&gt;
&lt;p&gt;In these situations ideally your application should prove its own identity to the &lt;span class="caps"&gt;API&lt;/span&gt;, but no user consent should be necessary. Similarly, in enterprise scenarios, your application could request delegated access to some resources. This is a possible scenario where OAuth2.0 comes to save&amp;nbsp;you.&lt;/p&gt;
&lt;h3 id="oauth20-authorization-framework"&gt;OAuth2.0 authorization&amp;nbsp;framework&lt;/h3&gt;
&lt;p&gt;The &lt;a href="http://en.wikipedia.org/wiki/OAuth"&gt;OAuth2.0 authorization framework&lt;/a&gt; is being adopted by many web services as a secure way for 3rd-parties to deploy software that use their APIs. It is well summarized &lt;a href="https://developers.google.com/identity/protocols/OAuth2#serviceaccount"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As the &lt;a href="http://tools.ietf.org/html/rfc6749"&gt;OAuth2.0 &lt;span class="caps"&gt;RFC&lt;/span&gt;&lt;/a&gt;&amp;nbsp;says:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The OAuth 2.0 authorization framework enables a third-party
application to obtain limited access to an &lt;span class="caps"&gt;HTTP&lt;/span&gt; service, either on
behalf of a resource owner by orchestrating an approval interaction
between the resource owner and the &lt;span class="caps"&gt;HTTP&lt;/span&gt; service, or by allowing the
third-party application to obtain access on its own behalf.  This
specification replaces and obsoletes the OAuth 1.0 protocol described
in &lt;span class="caps"&gt;RFC&lt;/span&gt;&amp;nbsp;5849.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developers.google.com/identity/protocols/OAuth2"&gt;Google has adopted OAuth 2.0&lt;/a&gt; for his APIs and web services. They also created a Python module for accessing resources protected by OAuth 2.0 called &lt;a href="https://github.com/google/oauth2client"&gt;oauth2client&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Check &lt;a href="https://developers.google.com/identity/protocols/OAuth2ServiceAccount"&gt;here&lt;/a&gt; to understand more how the authorization process works or how you can use&amp;nbsp;it.&lt;/p&gt;
&lt;h2 id="materials-and-methods"&gt;Materials and Methods&lt;a id="materials"&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id="installation"&gt;Installation&lt;/h3&gt;
&lt;p&gt;The simplest tool to install the needed modules&amp;nbsp;is &lt;code&gt;pip&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install gspread oauth2client
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Following the &lt;a href="#install-crypto"&gt;note&lt;/a&gt;, you would also want to&amp;nbsp;install &lt;code&gt;pycrypto&lt;/code&gt; or &lt;code&gt;pyopenssl&lt;/code&gt;,&amp;nbsp;e.g.:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install pycrypto
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="experiment"&gt;Experiment&lt;/h3&gt;
&lt;h3 id="create-signed-json-web-tokens-jwts"&gt;Create signed &lt;span class="caps"&gt;JSON&lt;/span&gt; Web Tokens&amp;nbsp;(JWTs)&lt;/h3&gt;
&lt;p&gt;The gspread documentation explains how to create Google OAuth2.0 &lt;span class="caps"&gt;JSON&lt;/span&gt; Web Tokens (JWTs) &lt;a href="http://gspread.readthedocs.org/en/latest/oauth2.html"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Follow his full instructions on the &lt;a href="https://console.developers.google.com/project"&gt;Google Developers Console&lt;/a&gt; web site to create a service account Client &lt;span class="caps"&gt;ID&lt;/span&gt; &lt;span class="caps"&gt;JSON&lt;/span&gt; file. I will call the&amp;nbsp;file &lt;code&gt;gspread-test.json&lt;/code&gt; from now&amp;nbsp;on.&lt;/p&gt;
&lt;p&gt;After&amp;nbsp;saving &lt;code&gt;gspread-test.json&lt;/code&gt; you need to &lt;strong&gt;share your document with the given email in&amp;nbsp;the &lt;code&gt;client_email&lt;/code&gt; field&lt;/strong&gt; of the file. Otherwise you’ll get&amp;nbsp;a &lt;code&gt;SpreadsheetNotFound&lt;/code&gt; exception when trying to open&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The resulting &lt;span class="caps"&gt;JSON&lt;/span&gt; file is a secure authorization key for any spreadsheet you may want to. For this reason you should hide this file should as it could be used to do nasty things against your spreadsheets. Please follow more comments on this in the &lt;a href="#discussion"&gt;discussion&lt;/a&gt;&amp;nbsp;section.&lt;/p&gt;
&lt;h3 id="sign-your-jwts-for-credentials"&gt;Sign your JWTs for&amp;nbsp;credentials&lt;/h3&gt;
&lt;p&gt;This is a snippet of how to obtain the data of a spreadsheet given its name in the&amp;nbsp;variable &lt;code&gt;wks&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;```&lt;/span&gt;&lt;span class="n"&gt;python&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;gspread&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;oauth2client.service_account&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ServiceAccountCredentials&lt;/span&gt;

&lt;span class="n"&gt;json_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'gspread-test.json'&lt;/span&gt;
&lt;span class="n"&gt;scope&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'https://spreadsheets.google.com/feeds'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;credentials&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ServiceAccountCredentials&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;from_json_keyfile_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;google_api_key_file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;gc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gspread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;authorize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;wks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gc&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Where is the money Lebowski?"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sheet1&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;gc&lt;/code&gt; object is&amp;nbsp;a &lt;code&gt;gspread.client.Client&lt;/code&gt;, check its main functionality &lt;a href="http://gspread.readthedocs.org/en/latest/index.html#main-interface"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You can find &lt;a href="http://gspread.readthedocs.org/en/latest/index.html#models"&gt;here&lt;/a&gt; the main functionality&amp;nbsp;of &lt;code&gt;wks&lt;/code&gt; is a &lt;span class="caps"&gt;GS&lt;/span&gt;&amp;nbsp;class.&lt;/p&gt;
&lt;p&gt;&lt;a id="install-crypto"&gt;&lt;/a&gt;
&lt;strong&gt;Note:&lt;/strong&gt; You must create the signed credentials&amp;nbsp;using &lt;code&gt;ServiceAccountCredentials&lt;/code&gt; from &lt;code&gt;oauth2client.service_account&lt;/code&gt;.
This class requires&amp;nbsp;either &lt;code&gt;PyOpenSSL&lt;/code&gt;,&amp;nbsp;or &lt;code&gt;PyCrypto 2.6&lt;/code&gt; or later. If you are&amp;nbsp;getting &lt;code&gt;CryptoUnavailableError&lt;/code&gt; when trying to create your signed credentials, install &lt;a href="https://github.com/pyca/pyopenssl"&gt;PyOpenSSL&lt;/a&gt; or &lt;a href="https://github.com/dlitz/pycrypto"&gt;PyCrypto&lt;/a&gt;,&amp;nbsp;e.g.:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install pycrypto
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="results"&gt;Results&lt;/h3&gt;
&lt;p&gt;Have a look at the possibilities you have with gspread &lt;a href="https://github.com/burnash/gspread#more-examples"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Some examples&amp;nbsp;here:&lt;/p&gt;
&lt;h4 id="opening-a-spreadsheet"&gt;Opening a&amp;nbsp;Spreadsheet&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```python
&lt;span class="gh"&gt;#&lt;/span&gt; You can open a spreadsheet by its title as it appears in Google Docs
sh = gc.open("My poor gym results") # &amp;lt;-- Look ma, no keys!

&lt;span class="gh"&gt;#&lt;/span&gt; If you want to be specific, use a key (which you can extract from
&lt;span class="gh"&gt;#&lt;/span&gt; the spreadsheet's url)
sht1 = gc.open_by_key('0BmgG6nO_6dprdS1MN3d3MkdPa142WFRrdnRRUWl1UFE')

&lt;span class="gh"&gt;#&lt;/span&gt; Or, if you feel lazy to extract that key, paste the entire url
sht2 = gc.open_by_url('https://docs.google.com/spreadsheet/ccc?key=0Bm...FE&amp;amp;hl')
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h4 id="selecting-a-worksheet"&gt;Selecting a&amp;nbsp;worksheet&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```python
&lt;span class="gh"&gt;#&lt;/span&gt; Select worksheet by index. Worksheet indexes start from zero
worksheet = sh.get_worksheet(0)

&lt;span class="gh"&gt;#&lt;/span&gt; By title
worksheet = sh.worksheet("January")

&lt;span class="gh"&gt;#&lt;/span&gt; Most common case: Sheet1
worksheet = sh.sheet1

&lt;span class="gh"&gt;#&lt;/span&gt; Get a list of all worksheets
worksheet_list = sh.worksheets()
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h4 id="creating-a-worksheet"&gt;Creating a&amp;nbsp;worksheet&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```python
worksheet = wks.add_worksheet(title="A worksheet", rows="100", cols="20")
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h4 id="getting-a-cell-value"&gt;Getting a cell&amp;nbsp;value&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```python
# With label
val = worksheet.acell('B1').value

# With coords
val = worksheet.cell(1, 2).value
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h4 id="getting-all-values-from-a-worksheet-as-a-list-of-lists"&gt;Getting all values from a worksheet as a list of&amp;nbsp;lists&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```python
list_of_lists = worksheet.get_all_values()
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="discussion"&gt;Discussion&lt;a id="discussion"&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Regarding security issues, it is not clear to me how we should &amp;#8216;hide&amp;#8217; the &lt;span class="caps"&gt;JSON&lt;/span&gt; key information in case we needed to distribute the Python applications created. In a compiled language it would be possible to put the content in a file, obfuscate it, encrypt it and then compile it. Of course we could do this on Python using, for instance, Cython, but I would like something simpler and I think there isn&amp;#8217;t one.
&lt;em&gt;If you have any suggestion on how to do this in a pure Python package, please send me an&amp;nbsp;email.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id="links"&gt;Links&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://docs.google.com/spreadsheets/"&gt;https://docs.google.com/spreadsheets/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://support.google.com/docs"&gt;https://support.google.com/docs&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://support.google.com/docs/table/25273?hl=en"&gt;https://support.google.com/docs/table/25273?hl=en&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/burnash/gspread"&gt;https://github.com/burnash/gspread&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/OAuth"&gt;http://en.wikipedia.org/wiki/OAuth&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developers.google.com/identity/protocols/OAuth2#serviceaccount"&gt;https://developers.google.com/identity/protocols/OAuth2#serviceaccount&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://tools.ietf.org/html/rfc6749"&gt;http://tools.ietf.org/html/rfc6749&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developers.google.com/identity/protocols/OAuth2"&gt;https://developers.google.com/identity/protocols/OAuth2&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/google/oauth2client"&gt;https://github.com/google/oauth2client&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://developers.google.com/identity/protocols/OAuth2ServiceAccount"&gt;https://developers.google.com/identity/protocols/OAuth2ServiceAccount&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://gspread.readthedocs.org/en/latest/oauth2.html"&gt;http://gspread.readthedocs.org/en/latest/oauth2.html&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://console.developers.google.com/project"&gt;https://console.developers.google.com/project&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://gspread.readthedocs.org/en/latest/index.html#main-interface"&gt;http://gspread.readthedocs.org/en/latest/index.html#main-interface&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://gspread.readthedocs.org/en/latest/index.html#models"&gt;http://gspread.readthedocs.org/en/latest/index.html#models&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/pyca/pyopenssl"&gt;https://github.com/pyca/pyopenssl&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/dlitz/pycrypto"&gt;https://github.com/dlitz/pycrypto&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/burnash/gspread#more-examples"&gt;https://github.com/burnash/gspread#more-examples&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;</content><category term="Python"/><category term="python"/><category term="google-sheets"/><category term="gspread"/><category term="oauth"/><category term="api"/></entry><entry><title>Install Bokeh from sources</title><link href="https://alexsavio.github.io/quick-bokeh.html" rel="alternate"/><published>2014-11-11T22:11:46+01:00</published><updated>2014-11-11T22:11:46+01:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2014-11-11:/quick-bokeh.html</id><summary type="html">&lt;p&gt;A short guide to install Bokeh from sources in a virtualenv on Ubuntu&amp;nbsp;14.04&lt;/p&gt;</summary><content type="html">&lt;h1 id="introduction"&gt;Introduction&lt;/h1&gt;
&lt;p&gt;Bokeh is a Python interactive visualization library that targets modern web browsers for presentation. You can find its home at&amp;nbsp;http://bokeh.pydata.org/&lt;/p&gt;
&lt;p&gt;There is a great gallery here:&amp;nbsp;http://bokeh.pydata.org/docs/gallery.html#gallery&lt;/p&gt;
&lt;h1 id="requirements"&gt;Requirements&lt;/h1&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo apt-get install nodejs npm redis-server
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; activate your virtualenv now, if you&amp;nbsp;wish.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install numpy
pip install flask redis requests pandas wsaccel ujson cython
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="gevent"&gt;gevent&lt;/h2&gt;
&lt;h3 id="python-27"&gt;Python&amp;nbsp;2.7&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install gevent
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="python-34"&gt;Python&amp;nbsp;3.4&lt;/h3&gt;
&lt;p&gt;The current version of gevent at https://github.com/gevent/gevent is not compatible with Python 3 yet.
Luckily there is a fork of gevent patched to work with Python&amp;nbsp;3:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;git clone https://github.com/fantix/gevent.git
cd gevent

python setup.py install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="gevent-websocket"&gt;gevent-websocket&lt;/h2&gt;
&lt;h3 id="python-27_1"&gt;Python&amp;nbsp;2.7&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install gevent-websocket
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="python-34_1"&gt;Python&amp;nbsp;3.4&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;hg clone https://bitbucket.org/Jeffrey/gevent-websocket
cd gevent-websocket
python setup.py install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h1 id="clone-bokeh-repository"&gt;Clone Bokeh&amp;nbsp;repository&lt;/h1&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;git clone https://github.com/bokeh/bokeh.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="bokehjs"&gt;BokehJS&lt;/h2&gt;
&lt;h3 id="requirements_1"&gt;Requirements&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;cd bokeh/bokehjs
npm install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="install-grunt-the-javascript-task-runner"&gt;Install Grunt, the javascript task&amp;nbsp;runner&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo npm install -g grunt-cli
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="deploy"&gt;Deploy&lt;/h3&gt;
&lt;p&gt;Generate the compiled and optimized BokehJS libraries, and deploy them to the build&amp;nbsp;subdirectory.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;grunt deploy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="build"&gt;Build&lt;/h3&gt;
&lt;p&gt;This will build the BokehJS sources without concatenating and optimizing into standalone&amp;nbsp;libraries.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;grunt build
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;At this point you can use BokehJS together with require.js as an &lt;span class="caps"&gt;AMD&lt;/span&gt;&amp;nbsp;module.&lt;/p&gt;
&lt;h1 id="install-bokeh"&gt;Install&amp;nbsp;Bokeh&lt;/h1&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;cd &amp;lt;wherever_is&amp;gt;/bokeh
python setup.py install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This instruction will first ask if you want (1) a newly built BokehJS or (2) the build you just did in the &lt;strong&gt;bokehjs&lt;/strong&gt; folder. Choose&amp;nbsp;2.&lt;/p&gt;
&lt;h1 id="documentation"&gt;Documentation&lt;/h1&gt;
&lt;h2 id="requirements_2"&gt;Requirements&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install docutils sphinx sphinxcontrib-napoleon sphinx_bootstrap_theme sphinxcontrib-httpdomain
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="download-sample-data"&gt;Download sample&amp;nbsp;data&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="s1"&gt;'import bokeh; bokeh.sampledata.download()'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="build-html"&gt;Build&amp;nbsp;html&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;cd &amp;lt;wherever_is&amp;gt;/bokeh/sphinx
make html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="http://bokeh.pydata.org/docs/installation.html"&gt;http://bokeh.pydata.org/docs/installation.html&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</content><category term="Python"/><category term="python"/><category term="bokeh"/><category term="visualisation"/></entry><entry><title>How to use Byobu</title><link href="https://alexsavio.github.io/how-to-byobu.html" rel="alternate"/><published>2014-07-06T10:00:00+02:00</published><updated>2014-07-06T10:00:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2014-07-06:/how-to-byobu.html</id><summary type="html">&lt;p&gt;A short manual for Byobu and a list of its&amp;nbsp;advantages.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;a href="http://byobu.co"&gt;Byobu&lt;/a&gt;, in the same way as &lt;a href="http://tmux.sourceforge.net/"&gt;tmux&lt;/a&gt;, allows to
manage many terminals through just one. In summary, it is a terminal-based terminal multiplexer and session&amp;nbsp;manager.&lt;/p&gt;
&lt;p&gt;It can be very helpful when working with a server through &lt;span class="caps"&gt;SSH&lt;/span&gt;. Instead of opening a terminal
and connecting to your server every time you nedd another terminal, you can
setup your server to run Byobu or tmux at the beginning of your session and have as many terminals as you need. Byobu also keeps terminal sessions alive after detaching from&amp;nbsp;them.&lt;/p&gt;
&lt;p&gt;Byobu is an enhancement that connects to and uses Screen or tmux (you choose), but offers useful statistics and easy-to-use hotkeys for the basic&amp;nbsp;commands.&lt;/p&gt;
&lt;h2 id="installing-byobu"&gt;Installing&amp;nbsp;Byobu&lt;/h2&gt;
&lt;p&gt;In&amp;nbsp;Ubuntu:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;apt-get&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;byobu.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Else take a look at &lt;a href="http://byobu.co/downloads.html"&gt;http://byobu.co/downloads.html&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="start-byobu"&gt;Start&amp;nbsp;Byobu&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;byobu
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="configure-ubuntu-to-run-byobu-from-the-beginning"&gt;Configure Ubuntu to run Byobu from the&amp;nbsp;beginning&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;byobu-config
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Feel free to change&amp;nbsp;anything.&lt;/p&gt;
&lt;p&gt;The important setting to change is: &amp;#8220;&lt;em&gt;Byobu currently launches at login (toggle on)&lt;/em&gt;&amp;#8221;. Select that and press&amp;nbsp;return.&lt;/p&gt;
&lt;p&gt;Now you can go back to the menu and exit byobu-config (tab to the exit choice and hit&amp;nbsp;return).&lt;/p&gt;
&lt;h2 id="resume-previous-sessions"&gt;Resume previous&amp;nbsp;sessions&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;byobu&lt;span class="w"&gt; &lt;/span&gt;–r&lt;span class="w"&gt; &lt;/span&gt;session_title
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="hotkeys"&gt;Hotkeys&lt;/h2&gt;
&lt;p&gt;Byobu has easy keybindings that use the function&amp;nbsp;keys:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;F2&lt;/strong&gt;: Create a new&amp;nbsp;window&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;F3&lt;/strong&gt;: Move to previous&amp;nbsp;window&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;F4&lt;/strong&gt;: Move to next&amp;nbsp;window&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;F5&lt;/strong&gt;: Reload&amp;nbsp;profile&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;F6&lt;/strong&gt;: Detach from this&amp;nbsp;session&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;F7&lt;/strong&gt;: Enter copy/scrollback&amp;nbsp;mode&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;F8&lt;/strong&gt;: Re-title a&amp;nbsp;window&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;F9&lt;/strong&gt;: Configuration Menu, can also be summoned by &lt;strong&gt;Ctrl+a&lt;/strong&gt;, &lt;strong&gt;Ctrl+@&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;F12&lt;/strong&gt;: Lock current&amp;nbsp;session&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="how-detaching-works-or-how-to-maintain-a-session"&gt;How detaching works or How to maintain a&amp;nbsp;session&lt;/h2&gt;
&lt;p&gt;Perform a short demo. Issue the&amp;nbsp;command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;hello
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now exit the session by pressing &lt;strong&gt;F6&lt;/strong&gt; to detach from Byobu and then run: &lt;em&gt;exit&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Now &lt;span class="caps"&gt;SSH&lt;/span&gt; back into your machine.
You can notice that the &lt;em&gt;echo hello&lt;/em&gt; command is still on the&amp;nbsp;screen.&lt;/p&gt;
&lt;p&gt;Detaching does not end your session, it gives you access to another session.
That means you can log in, run a long running task, and then detach and come back later when you;ve finished the&amp;nbsp;task.&lt;/p&gt;
&lt;h2 id="note-for-vim-users"&gt;Note for vim&amp;nbsp;users&lt;/h2&gt;
&lt;p&gt;You might find now a strange behaviour when using &lt;strong&gt;Ctrl-Left&lt;/strong&gt; and &lt;strong&gt;Ctrl-Right&lt;/strong&gt; keys to skip words using vim and also other&amp;nbsp;programs.&lt;/p&gt;
&lt;p&gt;The best solution I found&amp;nbsp;was:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;':set term=xterm'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;~/.vim/vimrc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;blockquote&gt;&lt;/blockquote&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'unbind-key -n C-Left'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;~/.byobu/keybindings.tmux
&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'unbind-key -n C-Right'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;~/.byobu/keybindings.tmux
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;blockquote&gt;&lt;/blockquote&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'set-window-option -g xterm-keys on'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;~/.byobu/.tmux.conf
&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"set -g terminal-overrides 'xterm*:smcup@:rmcup@'"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;~/.byobu/.tmux.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;p&gt;[1] &lt;a href="http://www.saltycrane.com/blog/2012/10/how-start-long-running-process-screen-and-detach-it/"&gt;http://www.saltycrane.com/blog/2012/10/how-start-long-running-process-screen-and-detach-it/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[2] &lt;a href="http://tmux.sourceforge.net/"&gt;http://tmux.sourceforge.net/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[3] &lt;a href="http://byobu.co/documentation.html"&gt;http://byobu.co/documentation.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[4] &lt;a href="http://www.howtogeek.com/58487/how-to-easily-multitask-in-a-linux-terminal-with-byobu/"&gt;http://www.howtogeek.com/58487/how-to-easily-multitask-in-a-linux-terminal-with-byobu/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[5] &lt;a href="http://blog.smartlogicsolutions.com/2010/01/22/ubuntu-byobu-landscape/"&gt;http://blog.smartlogicsolutions.com/2010/01/22/ubuntu-byobu-landscape/&lt;/a&gt;&lt;/p&gt;</content><category term="Tools"/><category term="byobu"/><category term="terminal"/><category term="tmux"/><category term="ssh"/><category term="productivity"/></entry><entry><title>How to set up different versions of GCC</title><link href="https://alexsavio.github.io/setup-gcc-versions.html" rel="alternate"/><published>2014-06-03T11:00:00+02:00</published><updated>2014-06-03T11:00:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2014-06-03:/setup-gcc-versions.html</id><summary type="html">&lt;p&gt;How to set up different versions of &lt;span class="caps"&gt;GCC&lt;/span&gt;&lt;/p&gt;</summary><content type="html">&lt;p&gt;When I need to change versions of software I use on Ubuntu, e.g., gcc and g++ and&amp;nbsp;Java.&lt;/p&gt;
&lt;h3 id="update-alternatives"&gt;Update-alternatives&lt;/h3&gt;
&lt;p&gt;A neat way to do it is using &lt;em&gt;update-alternatives&lt;/em&gt;. This how you have to do it with&amp;nbsp;gcc:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7
sudo update-alternatives --config gcc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;p&gt;[1] &lt;a href="http://charette.no-ip.com:81/programming/2011-12-24_GCCv47/"&gt;http://charette.no-ip.com:81/programming/2011-12-24_GCCv47/&lt;/a&gt;&lt;/p&gt;</content><category term="Tools"/><category term="gcc"/><category term="ubuntu"/><category term="compiler"/><category term="linux"/></entry><entry><title>Installing common Python data analysis tools in virtualenv</title><link href="https://alexsavio.github.io/data-analysis-tools-install.html" rel="alternate"/><published>2014-04-26T18:38:37+02:00</published><updated>2014-04-26T18:38:37+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2014-04-26:/data-analysis-tools-install.html</id><summary type="html">&lt;p&gt;Installing Python data analysis&amp;nbsp;tools&lt;/p&gt;</summary><content type="html">&lt;p&gt;Tested on Ubuntu 13.10 and&amp;nbsp;14.04.&lt;/p&gt;
&lt;h3 id="requirements"&gt;Requirements&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;apt&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;python&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;pip&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;python&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;dev&lt;/span&gt;

&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;pip&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;virtualenv&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;virtualenvwrapper&lt;/span&gt;

&lt;span class="n"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"export WORKON_HOME=~/envs"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;~/.&lt;/span&gt;&lt;span class="n"&gt;bashrc&lt;/span&gt;
&lt;span class="n"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"source /usr/local/bin/virtualenvwrapper.sh"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;~/.&lt;/span&gt;&lt;span class="n"&gt;bashrc&lt;/span&gt;
&lt;span class="n"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"export PIP_REQUIRE_VIRTUALENV=true"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;~/.&lt;/span&gt;&lt;span class="n"&gt;bashrc&lt;/span&gt;
&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;~/.&lt;/span&gt;&lt;span class="n"&gt;bashrc&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="create-a-virtual-environment"&gt;Create a virtual&amp;nbsp;environment&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;mkvirtualenv &amp;lt;env_name&amp;gt; -p &amp;lt;path_to_python&amp;gt;*

*&amp;lt;path_to_python&amp;gt; can be either /usr/bin/python2 or /usr/bin/python3,
or whatever you need.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="install-modules"&gt;Install&amp;nbsp;modules&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://ipython.org/"&gt;IPython&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;pip&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ipython&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://www.numpy.org/"&gt;Numpy&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install numpy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Test&amp;nbsp;numpy&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;nose&lt;/span&gt;

&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="s1"&gt;'import numpy; numpy.test()'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://cython.org/"&gt;Cython&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install cython
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://www.scipy.org/"&gt;Scipy&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo apt-get build-dep python-scipy

sudo apt-get install libblas-dev liblapack-dev

pip install scipy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://docs.python.org/3.3/library/readline.html"&gt;Readline&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo apt-get install libncurses5-dev

pip install readline
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Other&amp;nbsp;dependencies&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install python-dateutil sphinx pygments tornado
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="graphical-libraries-for-gui-building-and-ipython-qt-console"&gt;Graphical libraries for &lt;span class="caps"&gt;GUI&lt;/span&gt; building and IPython &lt;span class="caps"&gt;QT&lt;/span&gt;&amp;nbsp;console&lt;/h3&gt;
&lt;h4 id="you-can-either-install-them-inside-the-virtual-environment"&gt;You can either install them inside the virtual&amp;nbsp;environment:&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt; pip install pyside
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You must install PyQt4&amp;nbsp;globally:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt; sudo apt-get install python3-pyqt4 python3-sip python-qt4-dev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;or&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt; sudo apt-get install python-pyqt4 python-sip python-qt4-dev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h4 id="i-recommend-installing-them-globally-then-linking-from-the-virtual-environment"&gt;I recommend installing them globally then linking from the virtual&amp;nbsp;environment:&lt;/h4&gt;
&lt;p&gt;First install&amp;nbsp;them:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo apt-get install python3-pyqt4 python3-pyside python3-sip
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;or&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo apt-get install python-qt4 python-pyside python-sip python-qt4-dev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Then link them (with the virtualenv&amp;nbsp;activated):&lt;/p&gt;
&lt;p&gt;In [3] we can see a script to link any library to the virtual environment (save
it in, e.g. symlink_pyqt4_and_sip.sh or ${WORKON_HOME}/postmkvirtualenv and
execute&amp;nbsp;it):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt; 1&lt;/span&gt;
&lt;span class="normal"&gt; 2&lt;/span&gt;
&lt;span class="normal"&gt; 3&lt;/span&gt;
&lt;span class="normal"&gt; 4&lt;/span&gt;
&lt;span class="normal"&gt; 5&lt;/span&gt;
&lt;span class="normal"&gt; 6&lt;/span&gt;
&lt;span class="normal"&gt; 7&lt;/span&gt;
&lt;span class="normal"&gt; 8&lt;/span&gt;
&lt;span class="normal"&gt; 9&lt;/span&gt;
&lt;span class="normal"&gt;10&lt;/span&gt;
&lt;span class="normal"&gt;11&lt;/span&gt;
&lt;span class="normal"&gt;12&lt;/span&gt;
&lt;span class="normal"&gt;13&lt;/span&gt;
&lt;span class="normal"&gt;14&lt;/span&gt;
&lt;span class="normal"&gt;15&lt;/span&gt;
&lt;span class="normal"&gt;16&lt;/span&gt;
&lt;span class="normal"&gt;17&lt;/span&gt;
&lt;span class="normal"&gt;18&lt;/span&gt;
&lt;span class="normal"&gt;19&lt;/span&gt;
&lt;span class="normal"&gt;20&lt;/span&gt;
&lt;span class="normal"&gt;21&lt;/span&gt;
&lt;span class="normal"&gt;22&lt;/span&gt;
&lt;span class="normal"&gt;23&lt;/span&gt;
&lt;span class="normal"&gt;24&lt;/span&gt;
&lt;span class="normal"&gt;25&lt;/span&gt;
&lt;span class="normal"&gt;26&lt;/span&gt;
&lt;span class="normal"&gt;27&lt;/span&gt;
&lt;span class="normal"&gt;28&lt;/span&gt;
&lt;span class="normal"&gt;29&lt;/span&gt;
&lt;span class="normal"&gt;30&lt;/span&gt;
&lt;span class="normal"&gt;31&lt;/span&gt;
&lt;span class="normal"&gt;32&lt;/span&gt;
&lt;span class="normal"&gt;33&lt;/span&gt;
&lt;span class="normal"&gt;34&lt;/span&gt;
&lt;span class="normal"&gt;35&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="ch"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c1"&gt;# This hook is executed after a new virtualenv is activated.&lt;/span&gt;
&lt;span class="c1"&gt;# ~/.virtualenvs/postmkvirtualenv&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;find_real_lib&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;syspy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;libname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;syspath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$syspy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-c&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"import sys; print(' '.join(sys.path).strip())"&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;libdir&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$syspath&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;do&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-e&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$libdir&lt;/span&gt;/&lt;span class="nv"&gt;$libname&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$3&lt;/span&gt;&lt;span class="s2"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$libdir&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;$libname&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;done&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;libs&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;PyQt4&lt;span class="w"&gt; &lt;/span&gt;sip.so&lt;span class="w"&gt; &lt;/span&gt;PySide&lt;span class="w"&gt; &lt;/span&gt;sip.cpython-34m-x86_64-linux-gnu.so&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#other_libs = ( vtk cairo )&lt;/span&gt;

&lt;span class="nv"&gt;python_version&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;python&lt;span class="k"&gt;$(&lt;/span&gt;python&lt;span class="w"&gt; &lt;/span&gt;-c&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"import sys; print (str(sys.version_info[0])+'.'+str(sys.version_info[1]))"&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;var&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;which&lt;span class="w"&gt; &lt;/span&gt;-a&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$python_version&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;syspy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;var&lt;/span&gt;&lt;span class="p"&gt;[-1]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;get_python_lib_cmd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"from distutils.sysconfig import get_python_lib; print (get_python_lib())"&lt;/span&gt;
&lt;span class="nv"&gt;lib_virtualenv_path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;python&lt;span class="w"&gt; &lt;/span&gt;-c&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$get_python_lib_cmd&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;lib&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;libs&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;do&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;libsyspath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;''&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;find_real_lib&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$syspy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$lib&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;libsyspath
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'0'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;ln&lt;span class="w"&gt; &lt;/span&gt;-s&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$libsyspath&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$lib_virtualenv_path&lt;/span&gt;/&lt;span class="nv"&gt;$lib&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;

&lt;h3 id="other-interesting-modules"&gt;Other interesting&amp;nbsp;modules&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://matplotlib.org/"&gt;matplotlib&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo apt-get build-dep python-matplotlib

pip install pyparsing

pip install matplotlib
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://scikit-image.org/"&gt;scikit-image&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install scikit-image
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://scikit-learn.org"&gt;scikit-learn&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install scikit-learn
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://github.com/scikit-fuzzy/scikit-fuzzy"&gt;scikit-fuzzy&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://pandas.pydata.org/"&gt;Pandas&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo apt-get install libhdf5-dev

pip install numexpr
pip install tables
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If you have problems importing tables, it might help downloading and compiling the &lt;a href="http://www.hdfgroup.org/HDF5/release/obtainsrc.html"&gt;&lt;span class="caps"&gt;HDF5&lt;/span&gt; library&lt;/a&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install pandas
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://www.h5py.org/"&gt;h5py&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo apt-get install libhdf5-dev

pip install h5py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://patsy.readthedocs.org/en/latest/"&gt;patsy&lt;/a&gt; and &lt;a href="http://statsmodels.sourceforge.net/"&gt;statsmodels&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install patsy
pip install statsmodels
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://pymc-devs.github.io/pymc/"&gt;pymc&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install pymc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="speed-up-execution"&gt;Speed up&amp;nbsp;execution&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://pypi.python.org/pypi/Bottleneck"&gt;bottleneck&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install bottleneck
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://github.com/twiecki/CythonGSL"&gt;cythongsl&lt;/a&gt;
 &lt;a href="http://nbviewer.ipython.org/github/twiecki/CythonGSL/blob/master/examples/cython_gsl_ipythonnb.ipynb"&gt;cythongsl-demo&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install cythongsl
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="neuroscience-tools"&gt;Neuroscience&amp;nbsp;tools:&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://nipy.org/nibabel/"&gt;Nibabel&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install nibabel
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://nipy.org/"&gt;Nipy&lt;/a&gt;&amp;nbsp;Dependencies:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;pip install sphinx sympy networkx traits

pip install nipy

pip install nipype dipy nitime
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://www.cs.dartmouth.edu/~nfoti/blog/blog/2012/07/17/setting-up-
virtualenv-for-data-analysis-on-osx/"&gt;http://www.cs.dartmouth.edu/~nfoti/blog/blog/2012/07/17/setting-up-&amp;nbsp;virtualenv-for-data-analysis-on-osx/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://calvinx.com/2012/11/03/ipython-qtconsole/"&gt;http://calvinx.com/2012/11/03/ipython-qtconsole/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://gist.github.com/alexsavio/7580457"&gt;https://gist.github.com/alexsavio/7580457&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;</content><category term="Python"/><category term="python"/><category term="virtualenv"/><category term="numpy"/><category term="scipy"/><category term="data-analysis"/></entry><entry><title>Compile Numpy and Scipy against Intel MKL</title><link href="https://alexsavio.github.io/numpy_scipy_mkl.html" rel="alternate"/><published>2014-04-08T22:00:00+02:00</published><updated>2014-04-08T22:00:00+02:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2014-04-08:/numpy_scipy_mkl.html</id><summary type="html">&lt;p&gt;Numpy and Scipy on Intel &lt;span class="caps"&gt;MKL&lt;/span&gt;&lt;/p&gt;</summary><content type="html">&lt;h6 id="tested-on-ubuntu-1310-and-1404"&gt;Tested on Ubuntu 13.10 and&amp;nbsp;14.04&lt;/h6&gt;
&lt;h3 id="1-install-c-composer-and-fortran-composer-with-mkl"&gt;1. Install C++ Composer and &lt;span class="caps"&gt;FORTRAN&lt;/span&gt; Composer, with &lt;span class="caps"&gt;MKL&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;Fill forms and download online installation shell scripts from &lt;a href="http://software.intel.com/en-us/non-commercial-software-development"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id="openblas-note"&gt;OpenBLAS&amp;nbsp;Note&lt;/h4&gt;
&lt;p&gt;If you want to use OpenBLAS as well, install it and follow the OpenBLAS notes along this tutorial.
  I haven&amp;#8217;t tested this&amp;nbsp;yet.&lt;/p&gt;
&lt;p&gt;But first, install&amp;nbsp;it:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
git clone git://github.com/xianyi/OpenBLAS
cd OpenBLAS &amp;amp;&amp;amp; make FC=gfortran
sudo make PREFIX=/opt/OpenBLAS install
sudo ldconfig
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="2-execute-shell-scripts-with-sudo"&gt;2. Execute shell scripts with&amp;nbsp;sudo&lt;/h3&gt;
&lt;p&gt;I will assume you&amp;#8217;ll install the libraries in&amp;nbsp;/opt/intel.&lt;/p&gt;
&lt;h3 id="3-once-installed-add-this-to-bashrc"&gt;3. Once installed, add this&amp;nbsp;to &lt;code&gt;~/.bashrc&lt;/code&gt;&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;```&lt;/span&gt;&lt;span class="n"&gt;bash&lt;/span&gt;
&lt;span class="c1"&gt;#Intel C++ Studio&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;intel&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="n"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;export&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;INTEL_HOME&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;intel&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;export&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;PATH&lt;/span&gt;&lt;span class="p"&gt;}:&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;INTEL_HOME&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;export&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;LD_LIBRARY_PATH&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;intel&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;mkl&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;intel64&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;intel&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;intel64&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;LD_LIBRARY_PATH&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;fi&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="4-add-this-to-etcldsoconfdintelconf"&gt;4. Add this&amp;nbsp;to &lt;code&gt;/etc/ld.so.conf.d/intel.conf&lt;/code&gt;&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;/opt/intel/lib/intel64
/opt/intel/lib/intel64/irml
/opt/intel/lib/intel64/crt
/opt/intel/mkl/lib/intel64
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="5-download-numpy-and-scipy-from-here"&gt;5. Download Numpy and Scipy from &lt;a href="http://www.scipy.org/scipylib/download.html"&gt;here&lt;/a&gt;&lt;/h3&gt;
&lt;h3 id="6-change-numpy-source-code"&gt;6. Change Numpy source&amp;nbsp;code&lt;/h3&gt;
&lt;p&gt;Change directory to&amp;nbsp;numpy-x.x.x&lt;/p&gt;
&lt;p&gt;Create a site.cfg from the existing&amp;nbsp;site.cfg.examle&lt;/p&gt;
&lt;p&gt;Edit site.cfg as&amp;nbsp;follows:&lt;/p&gt;
&lt;p&gt;Add the following lines to site.cfg in your top level NumPy directory to use Intel® &lt;span class="caps"&gt;MKL&lt;/span&gt;, if you are building on Intel 64 platform, assuming the default path for the Intel &lt;span class="caps"&gt;MKL&lt;/span&gt; installation from the Intel Parallel Studio &lt;span class="caps"&gt;XE&lt;/span&gt; 2013 or Intel Composer &lt;span class="caps"&gt;XE&lt;/span&gt; 2013&amp;nbsp;versions:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;```&lt;/span&gt;&lt;span class="nc"&gt;text&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mkl&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;library_dirs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;intel&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;mkl&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;intel64&lt;/span&gt;
&lt;span class="n"&gt;include_dirs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;intel&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;mkl&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="k"&gt;include&lt;/span&gt;
&lt;span class="n"&gt;mkl_libs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mkl_rt&lt;/span&gt;
&lt;span class="n"&gt;lapack_libs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If you are building NumPy for 32 bit, please add as the&amp;nbsp;following:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;```&lt;/span&gt;&lt;span class="nc"&gt;text&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mkl&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;library_dirs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;intel&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;mkl&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ia32&lt;/span&gt;
&lt;span class="n"&gt;include_dirs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;intel&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;mkl&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="k"&gt;include&lt;/span&gt;
&lt;span class="n"&gt;mkl_libs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mkl_rt&lt;/span&gt;
&lt;span class="n"&gt;lapack_libs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Change cc_exe in numpy/distutils/intelccompiler.py to be something&amp;nbsp;like:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```python
self.cc_exe = \'icc -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost\'
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Here we use, -O3, optimizations for speed and enables more aggressive loop transformations such as Fusion, Block-Unroll-and-Jam, and collapsing &lt;span class="caps"&gt;IF&lt;/span&gt; statements, -openmp for OpenMP threading and -xhost option tells the compiler to generate instructions for the highest instruction set available on the compilation host processor. If you are using the &lt;span class="caps"&gt;ILP64&lt;/span&gt; interface, please add -DMKL_ILP64 compiler&amp;nbsp;flag.&lt;/p&gt;
&lt;p&gt;Run &lt;code&gt;icc --help&lt;/code&gt; for more information on processor-specific options, and refer Intel Compiler documentation for more details on the compiler&amp;nbsp;flags.&lt;/p&gt;
&lt;p&gt;Change the Fortran compiler flags in numpy-x.x.x/numpy/distutil/fcompiler/intel.py to use the following compiler options for the Intel Fortran&amp;nbsp;Compiler:&lt;/p&gt;
&lt;p&gt;For ia32 and&amp;nbsp;Intel64&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
ifort -xhost -openmp -fp-model strict -fPIC
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Change&amp;nbsp;the &lt;code&gt;get_flags_opt&lt;/code&gt; function line&amp;nbsp;to:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```&lt;span class="nv"&gt;python&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;[&lt;span class="s1"&gt;'-xhost -openmp -fp-model strict'&lt;/span&gt;]
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If you are using &lt;span class="caps"&gt;ILP64&lt;/span&gt; interface of Intel &lt;span class="caps"&gt;MKL&lt;/span&gt;, please add -i8 flag above.  If you are using older versions of Numpy/SciPy, please refer the new intel.py for your reference from the latest version of NumPy, which you can replace to use the above mentioned compiler&amp;nbsp;options.&lt;/p&gt;
&lt;h4 id="note"&gt;Note&lt;/h4&gt;
&lt;p&gt;To use OpenBLAS, uncomment the following lines and correct the&amp;nbsp;paths:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;```&lt;/span&gt;&lt;span class="nc"&gt;text&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;openblas&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;libraries&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;openblas&lt;/span&gt;
&lt;span class="n"&gt;library_dirs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;OpenBLAS&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;
&lt;span class="n"&gt;include_dirs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;OpenBLAS&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="k"&gt;include&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="7-check-your-config"&gt;7. Check your&amp;nbsp;config&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
cd &amp;lt;numpy-x.x.x&amp;gt;
python setup.py config
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You should see the &lt;span class="caps"&gt;MKL&lt;/span&gt; library paths, and OpenBLAS if you enabled&amp;nbsp;it.&lt;/p&gt;
&lt;h3 id="8-compile-numpy-and-scipy-with-the-following-command-once-for-numpy-and-then-once-for-scipy"&gt;8. Compile Numpy and Scipy with the following command (once for Numpy and then once for&amp;nbsp;Scipy):&lt;/h3&gt;
&lt;p&gt;Remember to activate the virtual environment if you are going to use this in&amp;nbsp;one.&lt;/p&gt;
&lt;h4 id="81-for-64-bit"&gt;8.1 For&amp;nbsp;64-bit&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
cd &amp;lt;numpy-x.x.x&amp;gt;
python setup.py config --compiler=intelem --fcompiler=intelem build_clib \
--compiler=intelem --fcompiler=intelem build_ext --compiler=intelem --fcompiler=intelem install
&lt;span class="s"&gt;```&lt;/span&gt;

```bash
cd &amp;lt;scipy-x.x.x&amp;gt;
python setup.py config --compiler=intelem --fcompiler=intelem build_clib \
--compiler=intelem --fcompiler=intelem build_ext --compiler=intelem --fcompiler=intelem install
&lt;span class="s"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h4 id="82-for-32-bit"&gt;8.2 For&amp;nbsp;32-bit&lt;/h4&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
cd &amp;lt;numpy-x.x.x&amp;gt;
python setup.py config --compiler=intel --fcompiler=intel build_clib \
--compiler=intel --fcompiler=intel build_ext --compiler=intel --fcompiler=intel install
&lt;span class="s"&gt;```&lt;/span&gt;

```bash
cd &amp;lt;scipy-x.x.x&amp;gt;
python setup.py config --compiler=intel --fcompiler=intel build_clib \
--compiler=intel --fcompiler=intel build_ext --compiler=intel --fcompiler=intel install
&lt;span class="s"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="9-troubleshooting"&gt;9.&amp;nbsp;Troubleshooting&lt;/h3&gt;
&lt;h4 id="91-compiling-scipy-using-deprecated-numpy-api-disable-it-by"&gt;9.1 Compiling Scipy: &amp;#8220;Using deprecated NumPy &lt;span class="caps"&gt;API&lt;/span&gt;, disable it&amp;nbsp;by&amp;#8230;&amp;#8221;&lt;/h4&gt;
&lt;p&gt;Thi may be because of the version of &lt;span class="caps"&gt;GCC&lt;/span&gt;, try using 4.7 (worked in November&amp;nbsp;2013):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
sudo apt-get install gcc-4.7
sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.7 /usr/bin/gcc
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Compile both Numpy and Scipy&amp;nbsp;again.&lt;/p&gt;
&lt;h3 id="10-testing"&gt;10.&amp;nbsp;Testing&lt;/h3&gt;
&lt;p&gt;You can test OpenBLAS with the following code (got from &lt;a href="https://gist.github.com/osdf/"&gt;https://gist.github.com/osdf/&lt;/a&gt;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;```&lt;/span&gt;&lt;span class="n"&gt;python&lt;/span&gt;
&lt;span class="c1"&gt;#!/usr/bin/env python&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;numpy&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sys&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;timeit&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;numpy.core._dotblas&lt;/span&gt;
    &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s1"&gt;'FAST BLAS'&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="ne"&gt;ImportError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s1"&gt;'slow blas'&lt;/span&gt;

&lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;"version:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__version__&lt;/span&gt;
&lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;"maxint:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maxint&lt;/span&gt;
&lt;span class="nb"&gt;print&lt;/span&gt;

&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="n"&gt;setup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"import numpy; x = numpy.random.random((1000,1000))"&lt;/span&gt;
&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;

&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;timeit&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Timer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"numpy.dot(x, x.T)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;setup&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;"dot:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timeit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"sec"&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://software.intel.com/en-us/articles/numpyscipy-with-intel-mkl"&gt;https://software.intel.com/en-us/articles/numpyscipy-with-intel-mkl&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://gehrcke.de/2014/02/building-numpy-and-scipy-with-intel-compilers-and-intel-mkl-on-a-64-bit-machine/"&gt;http://gehrcke.de/2014/02/building-numpy-and-scipy-with-intel-compilers-and-intel-mkl-on-a-64-bit-machine/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://stackoverflow.com/questions/11443302/compiling-numpy-with-openblas-integration"&gt;http://stackoverflow.com/questions/11443302/compiling-numpy-with-openblas-integration&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://gist.githubusercontent.com/osdf/3842524/raw/df01f7fa9d849bec353d6ab03eae0c1ee68f1538/test_numpy.py"&gt;https://gist.githubusercontent.com/osdf/3842524/raw/df01f7fa9d849bec353d6ab03eae0c1ee68f1538/test_numpy.py&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;</content><category term="Python"/><category term="python"/><category term="numpy"/><category term="scipy"/><category term="mkl"/><category term="openblas"/><category term="performance"/></entry><entry><title>Using BibLatex with Lyx and JabRef</title><link href="https://alexsavio.github.io/biblatex_lyx_jabref_encoding.html" rel="alternate"/><published>2014-02-27T18:11:46+01:00</published><updated>2014-02-27T18:11:46+01:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2014-02-27:/biblatex_lyx_jabref_encoding.html</id><summary type="html">&lt;p&gt;Configuring BibLatex in Lyx to benefit of &lt;span class="caps"&gt;UTF&lt;/span&gt;-8&amp;nbsp;encoding&lt;/p&gt;</summary><content type="html">&lt;h3 id="introduction"&gt;Introduction&lt;/h3&gt;
&lt;p&gt;For publishing articles with Lyx I&amp;#8217;ve used Zotero, JabRef and Lyx during my PhD.
I&amp;#8217;ve always had problems with the encoding of the BibTex files and ended up
editing them in JabRef, removing/replacing strange&amp;nbsp;characters.&lt;/p&gt;
&lt;p&gt;Today my beloved girlfriend (are you happy now?) indicated me
&lt;a href="http://www.ctan.org/pkg/biblatex"&gt;BibLatex&lt;/a&gt;.
She showed me that we can configure Lyx to use it through
&lt;a href="http://biblatex-biber.sourceforge.net/"&gt;biber&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is a list of steps that you should perform to be able to use BibLatex on&amp;nbsp;Lyx.&lt;/p&gt;
&lt;h3 id="step-1-reconfigure-encodings-in-zotero-and-jabref"&gt;Step 1: Reconfigure encodings in Zotero and&amp;nbsp;JabRef&lt;/h3&gt;
&lt;p&gt;Setup Zotero to export to &lt;span class="caps"&gt;UTF&lt;/span&gt;-8.&lt;/p&gt;
&lt;p&gt;Setup JabRef to use the default encoding as &lt;span class="caps"&gt;UTF&lt;/span&gt;-8.&lt;/p&gt;
&lt;h3 id="step-2-install-biblatex-and-biber"&gt;Step 2: Install biblatex and&amp;nbsp;biber&lt;/h3&gt;
&lt;p&gt;In Ubuntu I installed the packages: &lt;em&gt;biblatex texlive-latex-extra&amp;nbsp;texlive-bibtex-extra&lt;/em&gt;&lt;/p&gt;
&lt;h3 id="step-3-create-the-biblatexmodule-file"&gt;Step 3: Create the biblatex.module&amp;nbsp;file&lt;/h3&gt;
&lt;p&gt;Create a file named biblatex.module with the following&amp;nbsp;content:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;#\DeclareLyXModule{Biblatex-citation-styles}&lt;/span&gt;
&lt;span class="c1"&gt;#DescriptionBegin&lt;/span&gt;
&lt;span class="c1"&gt;#A prerequisite for using the biblatex package. This module&lt;/span&gt;
&lt;span class="c1"&gt;#enables the author/year citation styles without actually loading natbib.&lt;/span&gt;
&lt;span class="c1"&gt;#Biblatex itself needs to be loaded manually. Cf.&lt;/span&gt;
&lt;span class="c1"&gt;#http://wiki.lyx.org/BibTeX/Biblatex&lt;/span&gt;
&lt;span class="c1"&gt;#DescriptionEnd&lt;/span&gt;

&lt;span class="n"&gt;Format&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;

&lt;span class="c1"&gt;# this is biblatex actually&lt;/span&gt;
&lt;span class="n"&gt;Provides&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;natbib&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Put the file biblatex.module in the layouts folder in your user directory
(Help→About LyX tells you where you can find this directory; in the latest versions of &lt;span class="caps"&gt;OSX&lt;/span&gt; the correct layouts folder is in the applications&amp;nbsp;folder).&lt;/p&gt;
&lt;p&gt;In Ubuntu:&amp;nbsp;~/.lyx&lt;/p&gt;
&lt;p&gt;Run Tools→Reconfigure, restart&amp;nbsp;LyX.&lt;/p&gt;
&lt;h3 id="step-4-creating-the-lyx-file"&gt;Step 4: Creating the .lyx&amp;nbsp;file&lt;/h3&gt;
&lt;h4 id="add-the-biblatex-module"&gt;Add the biblatex&amp;nbsp;module&lt;/h4&gt;
&lt;p&gt;Add to &amp;#8220;Selected&amp;#8221; the module &amp;#8220;Biblatex-citation-styles&amp;#8221; from&amp;nbsp;Document→Settings→Modules.&lt;/p&gt;
&lt;h4 id="load-biblatex-in-the-preamble"&gt;Load biblatex in the&amp;nbsp;preamble&lt;/h4&gt;
&lt;p&gt;In the document preamble (Document→Settings→Preamble) you have to load biblatex manually,&amp;nbsp;with:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;usepackage&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;natbib&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;numeric&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;backend&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;biber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;maxnames&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;doi&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;bibencoding&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="p"&gt;]{&lt;/span&gt;&lt;span class="nx"&gt;biblatex&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h4 id="load-the-bibliography-in-the-preamble"&gt;Load the bibliography in the&amp;nbsp;preamble&lt;/h4&gt;
&lt;p&gt;Load your bibliography database in the&amp;nbsp;preamble:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;\addbibresource{/home/alexandre/mybibs.bib}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You must load the databases must using \addbibresource&amp;nbsp;commands.&lt;/p&gt;
&lt;p&gt;Please refer to the &lt;a href="http://mirrors.ctan.org/macros/latex/contrib/biblatex/doc/biblatex.pdf"&gt;biblatex documentation&lt;/a&gt; for further&amp;nbsp;options.&lt;/p&gt;
&lt;h4 id="set-biber-as-the-bibtex-processor"&gt;Set biber as the BibTex&amp;nbsp;processor&lt;/h4&gt;
&lt;p&gt;In  Document→Settings→Bibliography, set the Processor as&amp;nbsp;biber.&lt;/p&gt;
&lt;h4 id="load-the-bibliography-in-a-note"&gt;Load the bibliography in a&amp;nbsp;note&lt;/h4&gt;
&lt;p&gt;In the document, insert the BibTeX inset (Insert→List/&lt;span class="caps"&gt;TOC&lt;/span&gt;→BibTeX Bibliography&amp;#8230; ) in a LyX note or comment,
such that LyX finds the citations, but no \bibliography command is output to&amp;nbsp;LaTeX.&lt;/p&gt;
&lt;p&gt;It does not matter which style you chose here, so you can stick with &amp;#8220;plain&amp;#8221;.
To use the citation dialog, you&amp;#8217;ll have to choose the correct databases (i.e. those you loaded above in item&amp;nbsp;(3)).&lt;/p&gt;
&lt;p&gt;You must do this if you are going to use the citation dialog. I use JabRef to push the citations&amp;nbsp;instead.&lt;/p&gt;
&lt;h4 id="put-the-printbibliography-command"&gt;Put the printbibliography&amp;nbsp;command&lt;/h4&gt;
&lt;p&gt;In the document, enter \printbibliography in &lt;span class="caps"&gt;ERT&lt;/span&gt; (TeX mode) at the place where you want the bibliography to&amp;nbsp;appear.&lt;/p&gt;
&lt;h4 id="view-the-file-in-pdf"&gt;View the file in &lt;span class="caps"&gt;PDF&lt;/span&gt;&lt;/h4&gt;
&lt;p&gt;And this should do&amp;nbsp;it.&lt;/p&gt;
&lt;h3 id="references"&gt;References&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://wiki.lyx.org/BibTeX/Tips"&gt;http://wiki.lyx.org/BibTeX/Tips&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://wiki.lyx.org/BibTeX/Biblatex"&gt;http://wiki.lyx.org/BibTeX/Biblatex&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://wiki.lyx.org/BibTeX/BiblatexStyles"&gt;http://wiki.lyx.org/BibTeX/BiblatexStyles&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The biblatex.module file: &lt;a href="http://wiki.lyx.org/uploads/BibTeX/biblatex.module"&gt;http://wiki.lyx.org/uploads/BibTeX/biblatex.module&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The bibtexall script: &lt;a href="http://wiki.lyx.org/uploads/BibTeX/bibtexall"&gt;http://wiki.lyx.org/uploads/BibTeX/bibtexall&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;</content><category term="Tools"/><category term="latex"/><category term="lyx"/><category term="bibtex"/><category term="biblatex"/><category term="bibliography"/></entry><entry><title>How to create virtualenvs with Virtualenvwrapper</title><link href="https://alexsavio.github.io/virtualenvwrapper.html" rel="alternate"/><published>2014-02-08T21:16:14+01:00</published><updated>2014-02-08T21:16:14+01:00</updated><author><name>Alexandre M. Savio</name></author><id>tag:alexsavio.github.io,2014-02-08:/virtualenvwrapper.html</id><summary type="html">&lt;p&gt;Create virtualenvs with&amp;nbsp;virtualenvwrapper&lt;/p&gt;</summary><content type="html">&lt;h2 id="virtualenv-and-virtualenvwrapper"&gt;Virtualenv and&amp;nbsp;virtualenvwrapper&lt;/h2&gt;
&lt;p&gt;Install virtualenv and&amp;nbsp;virtualenvwrapper&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
sudo apt-get install python3-pip
sudo pip3 install virtualenv virtualenvwrapper
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Virtualenvwrapper .bashrc&amp;nbsp;setup:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;```&lt;/span&gt;&lt;span class="n"&gt;bash&lt;/span&gt;
&lt;span class="n"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"export WORKON_HOME=~/envs"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;~/.&lt;/span&gt;&lt;span class="n"&gt;bashrc&lt;/span&gt;
&lt;span class="n"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"source /usr/local/bin/virtualenvwrapper.sh"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;~/.&lt;/span&gt;&lt;span class="n"&gt;bashrc&lt;/span&gt;
&lt;span class="n"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"export PIP_REQUIRE_VIRTUALENV=true"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;~/.&lt;/span&gt;&lt;span class="n"&gt;bashrc&lt;/span&gt;
&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;~/.&lt;/span&gt;&lt;span class="n"&gt;bashrc&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="basic-usage-commands"&gt;Basic usage&amp;nbsp;commands&lt;/h2&gt;
&lt;p&gt;Create a&amp;nbsp;virtualenv:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
mkvirtualenv &amp;lt;env name&amp;gt;
```bash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Activate the&amp;nbsp;virtualenv:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
workon &amp;lt;env name&amp;gt;
```bash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Install a package in the activated&amp;nbsp;virtualenv&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;```&lt;/span&gt;&lt;span class="nx"&gt;bash&lt;/span&gt;
&lt;span class="nx"&gt;pip&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kn"&gt;package&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Go to its directory after activating&amp;nbsp;it&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
cdvirtualenv
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Set a working directory as a project of the&amp;nbsp;virtualenv&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
cd &amp;lt;project dir&amp;gt;
setvirtualenvproject $VIRTUAL_ENV $(pwd)
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Get a list of the Python modules and versions installed in an activated&amp;nbsp;virtualenv&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
pip freeze
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To deactivate a&amp;nbsp;virtualenv&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
deactivate
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id="run-ipython-within-the-virtualenv"&gt;Run ipython within the&amp;nbsp;virtualenv&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;```&lt;/span&gt;&lt;span class="n"&gt;bash&lt;/span&gt;
&lt;span class="n"&gt;alias&lt;/span&gt; &lt;span class="n"&gt;ipy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;\&lt;span class="s2"&gt;"python -c 'import IPython;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;IPython.terminal.ipapp.launch_new_instance()&amp;#8217;&amp;#34;
    ipy&amp;nbsp;&amp;#8220;`&lt;/p&gt;
&lt;h3 id="run-ipython-with-other-options"&gt;Run ipython with other&amp;nbsp;options&lt;/h3&gt;
&lt;p&gt;Add this to&amp;nbsp;.bashrc:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;```&lt;/span&gt;
&lt;span class="n"&gt;alias&lt;/span&gt; &lt;span class="n"&gt;ipy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"python -c 'import IPython;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;IPython.terminal.ipapp.launch_new_instance()&amp;#8217;&amp;#8221;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="n"&gt;ipyqt&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="s1"&gt;'import IPython;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;IPython.start_ipython([&amp;#8216;&amp;#8221;&amp;#8217;&amp;#8220;&amp;#8216;qtconsole&amp;#8217;&amp;#8221;&amp;#8217;&amp;#8221;&amp;#8217;]);&amp;#8217;&amp;nbsp;}&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="n"&gt;ipynote&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="s1"&gt;'import IPython; IPython.start_ipython(['&lt;/span&gt;&lt;span class="s2"&gt;"'"&lt;/span&gt;&lt;span class="s1"&gt;'notebook'&lt;/span&gt;&lt;span class="s2"&gt;"'"&lt;/span&gt;&lt;span class="s1"&gt;']);'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;```&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="another-way-of-creating-a-virtualenv"&gt;Another way of creating a&amp;nbsp;virtualenv&lt;/h2&gt;
&lt;p&gt;Download the virtualenv&amp;nbsp;script:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
wget https://raw.github.com/pypa/virtualenv/1.9.X/virtualenv.py
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Give it execution&amp;nbsp;permission:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
chmod +x virtualenv.py
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Create the&amp;nbsp;virtualenv:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
./virtualenv.py &amp;lt;env_name&amp;gt; -p &amp;lt;path_to_python&amp;gt;
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Activate&amp;nbsp;it:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;```bash
source &amp;lt;env_name&amp;gt;/bin/activate
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://www.virtualenv.org/en/latest/"&gt;http://www.virtualenv.org/en/latest/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://virtualenvwrapper.readthedocs.org/en/latest/"&gt;http://virtualenvwrapper.readthedocs.org/en/latest/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://virtualenvwrapper.readthedocs.org/en/latest/command_ref.html"&gt;http://virtualenvwrapper.readthedocs.org/en/latest/command_ref.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.cs.dartmouth.edu/~nfoti/blog/blog/2012/07/17/setting-up-virtualenv-
for-data-analysis-on-osx/"&gt;http://www.cs.dartmouth.edu/~nfoti/blog/blog/2012/07/17/setting-up-virtualenv-&amp;nbsp;for-data-analysis-on-osx/&lt;/a&gt;&lt;/p&gt;</content><category term="Python"/><category term="python"/><category term="virtualenv"/><category term="virtualenvwrapper"/></entry></feed>