🧭 The Way of Programming
A highly condensed draft on the essence, abstraction, principles, and philosophy of programming.
It is not a tutorial, but "The Way": the structure of thought.
1. Ontology of Programs: What is a Program?
- Program = Data + Functions
- Data is facts; functions are intentions
- Input → Process → Output
- State determines the form of the world, transformation depicts the process
- A program is a description of reality, and also a tool to change reality.
In one sentence: A program is structured thought.
2. Three Core Elements: Data · Functions · Abstraction
Data
- Data is "existence"
- Data structure is the structure of thought
- If data is clear, the program is natural
Functions
- Functions are "change"
- Process is causality
- Logic should be transformation, not manipulation
Abstraction
- Abstraction is to filter out the false and preserve the true.
- Abstraction is not simplification, but extraction of essence.
- Hide what is unnecessary, expose what is necessary.
3. Paradigm Evolution: From Doing to Purpose
Procedural Programming
- The world is composed of "steps"
- Process-driven
- Control flow is king
Object-Oriented Programming
- The world is composed of "things"
- State + Behavior
- Encapsulate complexity
Purpose-Oriented Programming
- The world is composed of "intentions"
- Talk about requirements, not steps.
- From imperative → declarative → intentional.
4. Design Principles: Rules for Maintaining Order
High Cohesion
- Related things are close
- Unrelated things are isolated
- Single responsibility is the core of cohesion
Low Coupling
- Modules are like planets: predictable, but not bound.
- The fewer dependencies, the longer the life.
- Freedom comes from not being coupled.
5. System View: Treating Programs as Systems
State
- The root of all errors is improper state.
- The less state, the more stable the program.
- Externalize state, limit state, automatically manage state.
Transformation
- Programs are not operations, but continuous changes.
- Every system can be viewed as:
output = transform(input)
Composability
- Small units → Composable
- Composable → Reusable
- Reusable → Evolvable
6. Way of Thinking: The Programmer's Mind
Declarative vs. Imperative
- Imperative: tell the system how to do it.
- Declarative: tell the system what you want.
- High-level code should be declarative.
- Low-level code can be imperative.
Specification Precedes Implementation
- Behavior precedes structure.
- Structure precedes code.
- A program is the shadow of its specification.
7. Stability and Evolution: Making Programs Live Longer
Stable Interfaces, Unstable Implementations
- API is a contract.
- Implementation is detail.
- Not breaking the contract is being responsible.
Conservation of Complexity
- Complexity does not disappear, it only shifts.
- Either you bear it, or the user bears it.
- Good design converges complexity internally.
8. Laws of Complex Systems: How to Manage Complexity
Local Simplicity, Global Complexity
- Every module should be simple.
- Complexity comes from composition, not modules.
Hidden Dependencies Are Most Dangerous
- Explicit > Implicit
- Transparent > Elegant
- Implicit dependencies are the beginning of decay.
9. Reasonability
- Predictability is more important than performance.
- Programs should be reason-able by the human mind.
- Few variables, shallow branches, clear states, flat logic.
- Reasonability = Maintainability.
10. Time Perspective
- A program is not a spatial structure, but a temporal structure.
- Every piece of logic is an event unfolding over time.
- Design must answer three questions:
- Who holds the state?
- When does the state change?
- Who triggers the change?
11. Interface Philosophy
API is Language
- Language shapes thought.
- Good interfaces prevent misuse.
- Perfect interfaces make misuse impossible.
Backward Compatibility is Responsibility
- Breaking an interface = Breaking trust.
12. Errors and Invariants
Errors are Normal
- Defaults are errors.
- Correctness requires proof.
Invariants Keep the World Stable
- Invariants are the physical laws of programs.
- Explicit constraints = Creating order.
13. Evolvability
- Software is not a statue, but an ecosystem.
- Good design is not optimal, but changeable.
- The best code is the code your future self can understand.
14. Tools and Efficiency
Tools Amplify Habits
- Good habits are amplified into efficiency.
- Bad habits are amplified into disaster.
Use tools, don't be used by them
- Understanding "why" is more important than "how".
15. Mental Models
- Models determine understanding.
- Understanding determines code.
- Correct models are more important than correct code.
Typical models:
- Program = Data flow
- UI = State machine
- Backend = Event-driven system
- Business logic = Invariant system
16. Principle of Least Surprise
- Good code should behave like common sense.
- No surprise is the best user experience.
- Predictability = Trust.
17. High-Frequency Abstraction: Higher-Order Programming Philosophy
Program as Knowledge
- Code is the precise expression of knowledge.
- Programming is formalizing vague knowledge.
Program as Simulation
- All software is a simulation of reality.
- The closer the simulation is to essence, the simpler the system.
Program as Language
- The essence of programming is language design.
- All programming is DSL design.
Program as Constraint
- Constraints shape structure.
- Constraints are more important than freedom.
Program as Decision
- Every line of code is a decision.
- Delaying decisions = Preserving flexibility.
18. Quotes
- Data is facts, functions are intentions.
- Program is causality.
- Abstraction compresses the world.
- The less state, the clearer the world.
- Interface is contract, implementation is detail.
- Composition over inheritance.
- Program is a temporal structure.
- Invariants stabilize logic.
- Reasonability over performance.
- Constraints create order.
- Code is the shape of knowledge.
- Stable interface, fluid implementation.
- No surprise is the highest design.
- Simplicity is the ultimate sophistication.
Conclusion
The Way of Programming does not teach you how to write code, but how to understand the world.
Code is the shape of thought.
A program is another language for understanding the world.
May you remain clear in a complex world, and see the essence in code.