§Hammurabi

§ 01–46 · The Code of Engineering

Hammurabi

Laws Every Engineer Should Know

Laws that govern systems, teams, and decisions — each paired with its counter-force, a field guideline, and a primary source. Named for the first written code of laws.

Prologue

“…to bring about the rule of righteousness in the land, so that the strong should not harm the weak.”

— The Code of Hammurabi, c. 1754 BCE

Hammurabi did not invent justice; he wrote it down, numbered it, and set it in stone where everyone could read the same law. This codex does that for engineering — the recurring forces that govern systems, teams, and decisions, carved as articles so they can be cited, argued, and amended, rather than rediscovered at 3 AM.

Codex

The Laws

§ 01Decision

Type 1 vs Type 2 Decisions

The brain instinctively treats all failures as threats, demanding excessive caution for reversible decisions (two-way doors).

CounterThe 'One-Way Door' Filter.

If a decision is easily reversible, ship within 24 hours. Only spend weeks on irreversible 'one-way doors'.

§ Jeff Bezos, Amazon Shareholder Letter (1997)

§ 02Safety

Normalization of Deviance

When a minor rule is broken and no disaster occurs, the brain re-classifies deviance as 'normal'.

CounterBroken Windows Theory.

Do not say 'it worked before' to skip investigation. Fix hacks or document them as high-priority debt.

§ Diane Vaughan, The Challenger Launch Decision (1996)

§ 03Systems

Chesterton's Fence

The ego jumps to 'simplify' by deleting legacy code/rules it doesn't immediately understand.

CounterBalance with YAGNI (You Ain't Gonna Need It).

You are forbidden from removing a fence until you can explain exactly why it was put there.

§ G. K. Chesterton, The Thing (1929)

§ 04Cognition

Normalcy Bias

In a crisis, the brain defaults to the most frequent explanation. 'It's just a transient error' as systems fail.

CounterPre-mortem / Red Teaming.

Ask: 'If this were the start of a total collapse, what would the next 10 minutes look like?'

§ Amanda Ripley, The Unthinkable (2008)

§ 05Organization

Law of Triviality

People provide more feedback on simple things (naming) than complex ones because everyone understands them.

CounterCore Value Focus.

If a review spends 80% on style, approve immediately and move to automated linter configs.

§ C. Northcote Parkinson, Parkinson's Law (1957)

§ 06Systems

Gall's Law

The delusion that complex systems can be designed top-down from scratch. They are too chaotic.

CounterThe MVP (Minimum Viable Product).

A complex system that works evolved from a simple system that worked. Start with a working 'Hello World'.

§ John Gall, Systemantics (1975)

§ 07Organization

Conway's Law

Software architecture is a map of the org chart. If teams don't talk, their services won't integrate.

CounterInverse Conway Maneuver.

To get a modular architecture, create independent teams first. Do not fight the org chart with code.

§ Melvin E. Conway, Datamation (1968)

§ 08Systems

Hyrum's Law

With enough users, every observable behavior (even bugs) will be depended on by someone.

CounterChaos Engineering.

Assume every change is breaking once you have users. Use strict versioning and feature flags.

§ Hyrum Wright, hyrumslaw.com; Software Engineering at Google (2020)

§ 09Organization

Brooks' Law

Adding people to a late project explodes communication channels quadratically (n(n-1)/2). New people drain veterans.

CounterScope Cutting.

If a project is late, do not add people. Remove features or push the date.

§ Fred Brooks, The Mythical Man-Month (1975)

§ 10Cognition

The XY Problem

Users get stuck on a solution (Y) and ask for help with it, forgetting the original problem (X).

CounterFive Whys.

When someone asks 'How do I do Y?', always reply 'What are you trying to achieve with Y?'

§ Perl & sysadmin folklore; xyproblem.info

§ 11Distributed Systems

Postel's Law

Assuming everyone follows the spec perfectly leads to brittle failures in distributed systems.

CounterFail-Fast (Internal only).

Be conservative in what you send and liberal in what you accept.

§ Jon Postel, RFC 760 / RFC 793 (1980–81)

§ 12Organization

Hanlon's Razor

Assuming malice or sabotage for bugs/delays when it's usually just lack of sleep or context.

CounterPsychological Safety.

Never attribute to malice what is adequately explained by lack of context. Debug the system.

§ Robert J. Hanlon, Murphy's Law Book Two (1980)

§ 13Estimation

Hofstadter's Law

It always takes longer than you expect, even when you take into account Hofstadter's Law.

CounterEvidence-Based Scheduling.

Double your most conservative estimate, then add 20%. Expect to be wrong.

§ Douglas Hofstadter, Gödel, Escher, Bach (1979)

§ 14Incentives

Goodhart's Law

When a measure becomes a target, it ceases to be a good measure. Rewards for 'commits' create junk commits.

CounterBalanced Scorecards.

Never use a single metric to judge performance. Observe outputs, not proxies.

§ Charles Goodhart (1975); Marilyn Strathern (1997)

§ 15Systems

Lindy Effect

For non-perishables like software, the longer it has survived, the longer it is likely to survive.

CounterHype Cycle Analysis.

If you need stability for 10 years, choose a technology that has already been around for 10 years.

§ Benoit Mandelbrot; Nassim Taleb, Antifragile (2012)

§ 16Decision

Sunk Cost Fallacy

Continuing to invest in failing projects because 'we've already spent so much.' The brain hates loss.

CounterZero-Based Budgeting.

Ask: 'If we started today with zero investment, would we choose this path?' If no, kill it.

§ Hal R. Arkes & Catherine Blumer (1985)

§ 17Cognition

Cargo Cult Engineering

Copying practices of successful companies (Spotify Model) without understanding the 'why'.

CounterFirst Principles Thinking.

Adopt a tool because you have the exact problem it solves, not because Google uses it.

§ Richard P. Feynman, Cargo Cult Science (1974)

§ 18Performance

Amdahl's Law

Optimizing a part has no impact if the bottleneck is elsewhere. Resource waste.

CounterTheory of Constraints.

Find the 1% of code that takes 90% of time. Only optimize that. Ignore the rest.

§ Gene Amdahl, AFIPS (1967)

§ 19Systems

Leaky Abstractions

All non-trivial abstractions leak. You can't use SQL without understanding indexes eventually.

CounterT-Shaped Skills.

Use abstractions to move fast, but ensure someone understands the layer beneath it.

§ Joel Spolsky, Joel on Software (2002)

§ 20Decision

Pareto Principle

80% of bugs come from 20% of code. 80% of value comes from 20% of features.

CounterRuthless Prioritization.

Identify the 'Critical 20%' and give it 100% of your quality focus.

§ Vilfredo Pareto (1896); Joseph M. Juran (1951)

§ 21Cognition

Survivorship Bias

We study only the successes that survived and draw conclusions, ignoring the silent graveyard of failures that used the same strategy.

CounterFailure Studies / Post-mortem Culture.

Before adopting a strategy because 'Company X succeeded with it,' research how many failed using the same approach. The dead don't write blog posts.

§ Abraham Wald, SRG memo (1943)

§ 22Maintainability

Kernighan's Law

"Debugging is twice as hard as writing the code. If you write the cleverest code you can, you are by definition not smart enough to debug it."

CounterKISS (Keep It Simple, Stupid).

Code cleverness is a liability, not an asset. Write code your future self, sleep-deprived at 3 AM, can still understand in 6 months.

§ Kernighan & Plauger, The Elements of Programming Style (1978)

§ 23Incentives

The Cobra Effect

A solution designed to fix a problem creates a worse one. A bounty on cobras led people to breed cobras for the reward.

CounterSecond-Order Effects Analysis.

For every incentive, ask: 'If someone wanted to game this, how would they?' If you find a way, the design is wrong.

§ Horst Siebert, Der Kobra-Effekt (2001)

§ 24Organization

Dunbar's Number

Humans can maintain ~150 stable relationships. Teams larger than ~8 experience exponential communication breakdown.

CounterTwo-Pizza Rule / Team Topologies.

When a team exceeds 7±2 people, split it. If 'information-sharing meetings' multiply, you've exceeded the cognitive limit.

§ Robin I. M. Dunbar, J. Human Evolution (1992)

§ 25Systems

Worse is Better

A simpler, 'inferior' design that is easy to implement and adopt will beat a theoretically 'correct' but complex one. Unix beat Lisp. HTTP beat CORBA.

CounterThe Right Thing / Perfectionism.

A solution 80% correct that ships today will outperform a 100% correct one that ships next year. Optimize for adoption, not elegance.

§ Richard P. Gabriel, Lisp: Good News, Bad News (1991)

§ 26Organization

Cunningham's Law

"The best way to get the right answer on the internet is not to ask a question; it's to post the wrong answer." People correct mistakes faster than they answer questions.

CounterSocratic Method.

When docs are missing, post your best guess of how something works. The expert will appear to correct you faster than if you'd asked directly.

§ Ward Cunningham; named on Wikipedia (~2010)

§ 27Organization

Bystander Effect

The more people present, the less likely any single person acts. 'Someone else will handle it.' A page to a group channel often means nobody responds.

CounterExplicit Role Assignment / Incident Commander.

Never say "Can someone look at this?" Say "@name, you are investigating this." Assign a single, named owner for every incident.

§ John M. Darley & Bibb Latané, JPSP (1968)

§ 28Safety

Murphy's Law

Anything that can go wrong, will go wrong — given enough time, traffic, or unexpected input. Designing only for the happy path leaves a system one blip away from collapse.

CounterDefensive Design / Chaos Engineering.

Treat every external dependency, retry, and timeout as something that will fail in production. Build the failure path before the success path.

§ Capt. Edward A. Murphy Jr., USAF MX981 (1949)

§ 29Maintainability

Boy Scout Rule

Codebases decay because cleanup is always 'someone else's job.' Each engineer absorbs the entropy hit but defers the fix to a future refactor that never lands.

CounterIncremental Hygiene.

Always leave the code cleaner than you found it. A one-line rename or a deleted dead branch is small enough for the same PR and bends the entropy curve over months.

§ Robert C. Martin, Clean Code (2008)

§ 30Systems

Tesler's Law

Every system has irreducible complexity that cannot be removed — only relocated. Hide it from the user and it lands on the developer; hide it from the developer and it lands on the customer at 3 AM.

CounterHonest Layering.

When a 'simple API' feels too clean, ask: who absorbed the complexity I just removed? If you can't name them, you didn't simplify — you displaced.

§ Larry Tesler, Xerox PARC / Apple (~1984)

§ 31Cognition

Dunning-Kruger Effect

Lacking expertise also means lacking the meta-skill to recognize incompetence. Novices over-claim; true experts under-claim, assuming others share their understanding.

CounterCalibrated Confidence.

When someone declares a hard problem "easy," check their domain history before trusting the estimate. Weight the quiet veteran over the confident newcomer.

§ Justin Kruger & David Dunning, JPSP (1999)

§ 32Cognition

Curse of Knowledge

Once you know a thing, you cannot easily imagine not knowing it. Docs, error messages, and APIs become obvious to the author and opaque to the next reader.

CounterUser Testing / Onboarding Buddies.

Before shipping docs or an API, have someone unfamiliar attempt the task while you watch silently. Their confusion maps the assumptions you forgot to spell out.

§ Camerer, Loewenstein & Weber, JPE (1989)

§ 33Safety

Swiss Cheese Model

Every protective layer has holes. Accidents happen when holes across independent layers happen to align. No single layer is ever sufficient.

CounterDefense in Depth.

In an incident review, do not stop at the one thing that failed. Enumerate every layer that should have caught it and ask why each hole was open at the same moment.

§ James Reason, Human Error (1990)

§ 34Performance

Premature Optimization

"Premature optimization is the root of all evil." Optimizing before measurement wastes hours and entangles hot and cold paths, obstructing the real fix.

CounterProfile First.

Write the obvious code first. Only optimize hot paths that a profiler proves are bottlenecks. Keep the other 97% simple for the next maintainer.

§ Donald E. Knuth, Computing Surveys (1974)

§ 35Maintainability

Linus's Law

"Given enough eyeballs, all bugs are shallow." Defects invisible to one mind become trivial under many independent perspectives — if the code is actually visible.

CounterRotated Reviewers / Bug Bounties.

If a bug class keeps slipping through, do not assign the same reviewers more carefully — expose the code to differently-shaped eyes. Rotate, open up, bounty.

§ Eric S. Raymond, The Cathedral and the Bazaar (1999)

§ 36Distributed Systems

CAP Theorem

A networked store cannot simultaneously guarantee Consistency, Availability, and Partition tolerance. Partitions are not optional, so you are really choosing C or A when one strikes.

CounterPACELC / Tunable Consistency.

Decide before an outage whether each operation prefers consistency or availability. The partition will happen; the only question is what your system does when it does.

§ Eric Brewer, PODC keynote (2000); proved by Gilbert & Lynch (2002)

§ 37Performance

Little's Law

In any stable system, items-in-system (L) equals arrival rate (λ) times time-in-system (W): L = λW. It holds regardless of arrival distribution or service order.

CounterBackpressure / Admission Control.

To cut latency without adding capacity, cut work-in-progress. Cap concurrent requests — a shorter queue is faster than a faster server.

§ John D. C. Little, Operations Research (1961)

§ 38Distributed Systems

Two Generals Problem

Two parties on an unreliable channel can never be certain they agree — every message needs an ack, which needs an ack, forever. No fixed exchange guarantees common knowledge.

CounterIdempotency / Eventual Consistency.

Never assume "I sent it, so they got it." Make every cross-network action safely retryable and idempotent, and reconcile state instead of trusting one round-trip.

§ Akkoyunlu, Ekanadham & Huber (1975); framed by Jim Gray (1978)

§ 39Organization

Peter Principle

People are promoted on performance in their current role, not the next one. So everyone rises until they reach a role they are bad at — and there they stay.

CounterDual Career Ladders.

Do not promote your best engineer into management as a reward. Offer a technical ladder, and evaluate candidates for the role above, not the one they already mastered.

§ Laurence J. Peter & Raymond Hull, The Peter Principle (1969)

§ 40Organization

Parkinson's Law

"Work expands so as to fill the time available for its completion." Give a task a week and it takes a week; the same task with a two-day deadline ships in two days.

CounterTimeboxing.

Set deliberately short timeboxes for open-ended work and review at the deadline. A tight box forces the scoping decisions an open one defers forever.

§ C. Northcote Parkinson, The Economist (1955)

§ 41Performance

Wirth's Law

"Software is getting slower more rapidly than hardware is becoming faster." Each hardware gain is absorbed by added layers and features, so perceived speed stays flat.

CounterPerformance Budgets.

Treat the speed a faster machine buys you as a budget to protect, not a license to spend. Set a performance budget and fail the build when a release regresses against it.

§ Niklaus Wirth, A Plea for Lean Software (1995)

§ 42Estimation

Ninety-Ninety Rule

"The first 90% of the code takes 90% of the time. The remaining 10% takes the other 90%." The visible work hides a second, equal body of integration and edge cases.

CounterDemo on Real Data.

When something looks almost done, assume an entire second project remains: hardening, edge cases, integration. Schedule it, do not treat it as a rounding error.

§ Tom Cargill (Bell Labs); Jon Bentley, Programming Pearls (1985)

§ 43Maintainability

Eagleson's Law

Any code you have not looked at for six months might as well have been written by someone else. Your mental model evaporates far faster than the code does.

CounterADRs / Self-Explaining Code.

Write code and commit messages for the stranger you will become in six months. If a decision is not obvious from the code, record the why — not in your head.

§ Programming folklore attributed to Peter Eagleson

§ 44Interaction

Hick's Law

Decision time grows logarithmically with the number of choices: T = b·log₂(n+1). More options do not just clutter — they measurably slow every user down.

CounterProgressive Disclosure / Defaults.

Cut the choices on any screen or API surface to the few that matter; push the rest behind sensible defaults. Fewer doors, faster decisions.

§ W. E. Hick (1952) & Ray Hyman (1953)

§ 45Interaction

Fitts's Law

Time to reach a target depends on its distance and size: far, small targets are slow and error-prone; near, large ones are fast. Pointing has a measurable cost.

CounterEdges & Corners / Frequency Sizing.

Make frequent actions big and easy to hit; make rare or destructive ones small and far. Screen edges and corners are infinite targets — put primary actions there.

§ Paul M. Fitts, J. Experimental Psychology (1954)

§ 46Cognition

Miller's Law

"The Magical Number Seven, Plus or Minus Two." Working memory holds about seven chunks. Cross that and recall collapses — the brain drops items rather than slowing.

CounterChunking / Information Hiding.

Group related items into a handful of named chunks wherever a person must hold state in their head: arguments, form fields, menu groups, on-call steps.

§ George A. Miller, Psychological Review (1956)

Epilogue

Good engineering is not the avoidance of all risk, but the deliberate choice of which risks are worth taking.

— The Code

Let the engineer who tears down a fence without learning why it stands, who turns a measure into a target, or who calls a hard problem easy — inherit the pager at 3 AM.