RSS Amplifier

Laws of Software Engineering · Jul 20, 2026

Murphy's Law / Sod's Law

0
Sign in to vote or save

Dr. Milan Milanović · Laws of Software Engineering

2 min read

Anything that can go wrong will go wrong.

Takeaways

  • If an error can happen, it will happen. Plan and code defensively with this in mind.
  • Add error handling, backups, and checks.
  • Edge cases will occur in production. Write tests for these kinds of scenarios.

Overview

In software, Murphy’s Law is often used to explain bugs and production incidents: whatever can go wrong in code (a null pointer, a race condition, a network outage) eventually will manifest, especially in large user bases or at the worst possible time.

In practice, this law encourages developers to write more defensive code. This means checking for nulls, handling exceptions, validating inputs, and failing gracefully when errors occur. It also reminds DevOps teams to anticipate failures by implementing monitoring, enabling rollbacks, and maintaining contingency plans.

Murphy's Law / Sod's Law illustration

Murphy’s Law

Examples

If a web form field can accept text, someone will enter a 10,000-character string of weird symbols to see what happens, unless you’ve explicitly handled it. If memory can run out, it will be when multiple processes align just so.

A famous real-world instance was during a live demo (who remembers the Windows 98 presentation by Bill Gates?), if something can glitch, it likely will.

In coding, consider a function that assumes an input file exists. Murphy’s Law says that one day that file won’t be there or will be corrupted, so your code should handle the file-not-found or bad-data scenario rather than crash.

Another typical case is that the server will crash on your only day off, because that’s when it’s most likely to cause trouble. Engineers thus build highly available systems and pager rotations to mitigate Murphy’s Law.

Origins

Attributed to Edward A. Murphy Jr., an engineer working on rocket sled experiments in 1949. It became popular in aerospace and then everywhere. In software, it’s been around as long as bugs have, constantly reminding us that if there’s one untested scenario, one user will find it.

Further Reading

Want to go deeper?

All 63+ laws are covered with more depth, examples, and practical guidance in the Laws of Software Engineering book.

Get the Book

Last updated: July 20, 2026

Read the original on lawsofsoftwareengineering.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.