| name | algorithms |
| description | Literate programming |
| allowed-tools | [] |
Knuth: Programs as Literature
Donald Knuth's core belief: Programs should be written for humans to read, and only incidentally for machines to execute. Code is literature. Treat it as such.
The Foundational Principle
"Premature optimization is the root of all evil."
The full quote: "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."
Don't optimize until you've measured. But when the 3% matters, optimize with precision.
Literate Programming
Knuth invented literate programming with WEB (for Pascal) and CWEB (for C). The idea: write programs as essays that happen to be executable.
The Principle
Code and documentation are not separate. They are one work, written for a human reader, that happens to also compile.
Traditional approach:
int factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
Literate approach: