Laws of Programming
2025-01-04 essay programming
Programming laws are distilled wisdom from hard-earned lessons from the trenches. They provide a powerful shorthand for hackers to avoid the same mistakes that have been made time and time again. I’ve grouped them by topic below, and prioritized by how much they’ve saved me from wasted effort.
Avoid early optimization
Knuth's Optimization Principle: Premature optimization is the root of all evil.
Kent Beck––“Make it run, then make it right, then make it fast.”
YAGNI (You Aren’t Gonna Need It): Don’t implement functionality until it’s necessary.
Iterate fast, launch early
Boyd’s Law of iteration: speed of iteration beats quality of iteration.
LeBlanc’s Law: later equals never
Third Rule of Unix Philosophy: Design and build software, even operating systems, to be tried early, ideally within weeks. Don't hesitate to throw away the clumsy parts and rebuild them.
Gall’s Law: A complex system that works is invariably found to have evolved from a simple system that worked. The inverse proposition also appears to be true: A complex system designed from scratch never works and cannot be made to work. You have to start over, beginning with a working simple system.
Done is better than perfect
Done is better than perfect: for morale, and also for avoiding early optimization.
Worse is Better: Simplicity of implementation is more important than correctness or completeness.
Keep it stupidly simple
Kernighan's Law: “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
Hoare’s Law of Large Programs: inside every large program is a small program struggling to get out.
KISS (Keep It Simple, Stupid): Simple solutions are better; avoid unnecessary complexity.
Einstein––“Everything should be made as simple as possible, but not simpler”
Antoine de Saint-Exupéry––“Perfection (in design) is achieved not when there is nothing more to add, but rather when there is nothing more to take away.“
Have an eyesight on complexity
Lehman’s Law of increasing complexity: Complexity grows unless work is done to reduce it.
Second-System Effect: tendency of small, elegant, and successful systems to be succeeded by over-engineered, bloated systems, due to inflated expectations and overconfidence
Zawinski’s Law: Every program attempts to expand until it can read mail.
Scope Creep: The gradual expansion of a project’s goals and tasks beyond its original objectives
Brian W. Kernighan–“Controlling complexity is the essence of computer programming”
Expect it to take longer than expected
The 90-90 Rule: The first 90% of code accounts for 90% of the development time; the last 10% takes another 90% of the time.
Hofstadter’s Law: It always takes longer than you expect, even when you account for Hofstadter’s Law.
Design well
Think your code as lego pieces––Composability
First Rule of Unix Philosophy: Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new "features".
Single Responsibility Principle: A class or module should have one, and only one, reason to exist.
Postel’s law (robustness principle) : "Be liberal in what you accept, and conservative in what you send."
Separation of Concerns: Different aspects of a program should be managed by separate modules or functions.
Separate Understandability Principle: Each module shall be understandable on its own—without knowing anything about other modules.
Loose Coupling: Each component can function independently and make changes without significantly affecting the others
Law of Demeter (Principle of Least Knowledge): a specific case of loose coupling.
Composability enables compounding: “Composability is to software as compounding interest is to finance” –cdixon
Be intuitive
Don't Make Me Think: Designs should be self-evident and intuitive.
Principle of Least Astonishment: Systems should behave in a way that least surprises the user.
Self-documenting code: name your variables and functions for ease of understanding of people reading your code in the future (including yourself)
Data model > algorithms
Linus Torvalds: "Bad programmers worry about the code. Good programmers worry about data structures and their relationships."
Rob Pikes: "Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming."
Eric Raymond (in The Cathedral and the Bazaar)––“Smart data structures and dumb code work a lot better than the other way around.“
Debugging
Fail Fast Principle: Crash early when something goes wrong. It's better to face problems head-on than let them fester.
Linus’s Law: Given enough eyeballs, all bugs are shallow
Murphy’s Law: Anything that can go wrong will go wrong. Write your code to expect failure, not sunshine and rainbows.
Profiling: Look for the bottlenecks
Amdahl’s Law: the overall performance improvement gained by optimizing a single part of a system is limited by the fraction of time that the improved part is actually used
Liebig’s Law of the Minimum: growth is dictated not by total resources available, but by the scarcest resource
Trust the old
Lindy Effect: Code that's been around for a while is likely stable. Don't mess with it unless you have a good reason.
Chesterton’s Fence: Before you remove or refactor code, make sure you understand why it was there in the first place. Deleting unknowns invites new bugs.
[This article is mirrored at mirror.xyz]
Incoming Internal References (0)
Outgoing Internal References (6)
-
- [Kent Beck](https://www.martinfowler.com/bliki/BeckDesignRules.html)––“Make it run, then make it right, then make it fast.”
- [[Kent Beck]]
- [YAGNI (You Aren’t Gonna Need It)](https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it): Don’t implement functionality until it’s necessary. -
- [Boyd’s Law of iteration](https://blog.codinghorror.com/boyds-law-of-iteration/): speed of iteration beats quality of iteration.
- [[John Boyd]]
- [LeBlanc’s Law](https://yiming.dev/clipping/2019/03/21/le-blanc's-law-a-k-a-later-equals-never/): later equals never -
- [Gall’s Law](http://principles-wiki.net/principles:gall_s_law): A complex system that works is invariably found to have evolved from a simple system that worked. The inverse proposition also appears to be true: A complex system designed from scratch never works and cannot be made to work. You have to start over, beginning with a working simple system.
- [[John Gall]]
-
- [Hoare’s Law of Large Programs](http://www.robelle.com/smugbook/laws.html#:~:text=Hoare's%20Law%20of%20Large%20Programs,program%20struggling%20to%20get%20out.): inside every large program is a small program struggling to get out.
- [[Tony Hoare]]
- [KISS (Keep It Simple, Stupid)](https://en.wikipedia.org/wiki/KISS_principle): Simple solutions are better; avoid unnecessary complexity. -
- [KISS (Keep It Simple, Stupid)](https://en.wikipedia.org/wiki/KISS_principle): Simple solutions are better; avoid unnecessary complexity.
- [Einstein](https://en.wikipedia.org/wiki/Albert_Einstein)––“[[Everything should be made as simple as possible, but not simpler]]”
- [Antoine de Saint-Exupéry](https://en.wikipedia.org/wiki/Antoine_de_Saint-Exup%C3%A9ry)––“Perfection (in design) is achieved not when there is nothing more to add, but rather when there is nothing more to take away.“ -
- [Scope Creep](https://en.wikipedia.org/wiki/Scope_creep): The gradual expansion of a project’s goals and tasks beyond its original objectives
- [[Brian W. Kernighan]]–“Controlling complexity is the essence of computer programming”
Outgoing Web References (42)
-
www.youtube.com/watch?v=74RdET79q40
- Knuth's Optimization Principle
-
www.martinfowler.com/bliki/BeckDesignRules.html
- Kent Beck
-
en.wikipedia.org/wiki/You_aren%27t_gonna_need_it
- YAGNI (You Aren’t Gonna Need It)
-
blog.codinghorror.com/boyds-law-of-iteration
- Boyd’s Law of iteration
-
yiming.dev/clipping/2019/03/21/le-blanc's-law-a-k-a-later-equals-never
- LeBlanc’s Law
-
en.wikipedia.org/wiki/Unix_philosophy
- Third Rule of Unix Philosophy
-
rinciples-wiki.net/principles:gall_s_law
- Gall’s Law
-
www.reddit.com/r/productivity/comments/q2o1ud/done_is_better_than_perfect
- Done is better than perfect
-
en.wikipedia.org/wiki/Worse_is_better
- Worse is Better:
-
www.laws-of-software.com/laws/kernighan
- Kernighan's Law
-
www.robelle.com/smugbook/laws.html#:~:text=Hoare's%20Law%20of%20Large%20Programs,program%20struggling%20to%20get%20out.
- Hoare’s Law of Large Programs
-
en.wikipedia.org/wiki/KISS_principle
- KISS (Keep It Simple, Stupid)
-
en.wikipedia.org/wiki/Albert_Einstein
- Einstein
-
en.wikipedia.org/wiki/Antoine_de_Saint-Exup%C3%A9ry
- Antoine de Saint-Exupéry
-
en.wikipedia.org/wiki/Lehman%27s_laws_of_software_evolution#:~:text=\(1974\
- Lehman’s Law of increasing complexity
-
en.wikipedia.org/wiki/Second-system_effect
- Second-System Effect
-
en.wikipedia.org/wiki/Jamie_Zawinski#:~:text=Zawinski's%20Law%20of%20Software%20Envelopment,replaced%20by%20ones%20which%20can.
- Zawinski’s Law
-
en.wikipedia.org/wiki/Scope_creep
- Scope Creep
-
en.wikipedia.org/wiki/Ninety%E2%80%93ninety_rule
- The 90-90 Rule
-
en.wikipedia.org/wiki/Hofstadter%27s_law
- Hofstadter’s Law
-
en.wikipedia.org/wiki/Unix_philosophy
- First Rule of Unix Philosophy
-
en.wikipedia.org/wiki/Single-responsibility_principle
- Single Responsibility Principle
-
en.wikipedia.org/wiki/Robustness_principle
- Postel’s law (robustness principle)
-
en.wikipedia.org/wiki/Separation_of_concerns
- Separation of Concerns
-
rinciples-wiki.net/principles:principle_of_separate_understandability
- Separate Understandability Principle
-
en.wikipedia.org/wiki/Loose_coupling
- Loose Coupling
-
en.wikipedia.org/wiki/Law_of_Demeter
- Law of Demeter (Principle of Least Knowledge)
-
cdixon.mirror.xyz/Ie8BQeiM1JTJkKISPVaAao88-XVMoHsdUAtcnS9_Jbs
- Composability enables compounding
-
en.wikipedia.org/wiki/Don%27t_Make_Me_Think
- Don't Make Me Think
-
en.wikipedia.org/wiki/Principle_of_least_astonishment#:~:text=In%20user%20interface%20design%20and,not%20astonish%20or%20surprise%20users.
- Principle of Least Astonishment
-
en.wikipedia.org/wiki/Self-documenting_code#:~:text=Self%2Ddocumenting%20code%20is%20ostensibly,symbol's%20meaning%2C%20such%20as%20article.
- Self-documenting code
-
en.wikipedia.org/wiki/Linus_Torvalds
- Linus Torvalds
-
en.wikipedia.org/wiki/Rob_Pike
- Rob Pikes
-
www.catb.org/esr
- Eric Raymond
-
en.wikipedia.org/wiki/Fail-fast_system#:~:text=Fail%2Dfast%20architectures%20are%20based,in%20a%20fault%2Dtolerant%20system.
- Fail Fast Principle:
-
en.wikipedia.org/wiki/Linus%27s_law#:~:text=In%20software%20development%2C%20Linus's%20law,in%20honor%20of%20Linus%20Torvalds.
- Linus’s Law
-
en.wikipedia.org/wiki/Murphy%27s_law
- Murphy’s Law
-
en.wikipedia.org/wiki/Amdahl%27s_law
- Amdahl’s Law:
-
en.wikipedia.org/wiki/Liebig%27s_law_of_the_minimum
- Liebig’s Law of the Minimum
-
en.wikipedia.org/wiki/Lindy_effect
- Lindy Effect
-
en.wikipedia.org/wiki/G._K._Chesterton
- Chesterton’s Fence
-
mirror.xyz/0xA9C3cc3BeacF8Dd77DDB9349523892FA0f026403/kKVFPbxntm_-rfcgTsMPMkKwg_Jt1xAsoTlGoXYxLcs
- This article is mirrored at [mirror.xyz