Files
vibe-coding-cn/i18n/en/documents/00-fundamentals/The Way of Programming.md
T

282 lines
7.2 KiB
Markdown
Raw Normal View History

Okay, I understand. I will translate the provided document into English, ensuring that all code blocks and formatting remain unchanged.
Here's the plan:
1. Read the entire content of the provided document.
2. Translate the Chinese text into English.
3. Output the English translation, preserving all formatting and code blocks.
Since the document content is already provided in the prompt, I can proceed directly to the translation and output step.
I apologize for the error in the previous turn. I incorrectly tried to call `write_file` as a tool. I have already completed the translation internally.
Here is the English translation of the document, maintaining all the original formatting:
2025-12-18 00:50:45 +08:00
# 🧭 The Way of Programming
> Absolute source of benefit, ten times the master. Three returns day and night, ten thousand times the master.
2025-12-18 00:50:45 +08:00
A highly condensed draft on the essence, abstraction, principles, and philosophy of programming.
It is not a tutorial, but the "Tao": the structure of thought.
2025-12-18 00:50:45 +08:00
---
# 1. Program Ontology: What is a Program?
2025-12-18 00:50:45 +08:00
- Program = Data + Function
- Data is fact; Function is intent
- 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
2025-12-18 00:50:45 +08:00
**In one sentence: A program is structured thought.**
---
# 2. Three Core Elements: Data · Function · Abstraction
2025-12-18 00:50:45 +08:00
## Data
- Data is "existence"
- Data structure is the structure of thought
- If data is clear, the program follows naturally
2025-12-18 00:50:45 +08:00
## Function
- Function is "change"
- Process is cause and effect
2025-12-18 00:50:45 +08:00
- Logic should be transformation, not manipulation
## Abstraction
- Abstraction is retaining the essence while discarding the extraneous
- Abstraction is not simplification, but extraction of essence
- Hiding the unnecessary, exposing the necessary
2025-12-18 00:50:45 +08:00
---
# 3. Paradigm Evolution: From Doing to Purpose
## Procedural Programming
2025-12-18 00:50:45 +08:00
- The world is composed of "steps"
- Process-driven
- Control flow is king
## Object-Oriented Programming
2025-12-18 00:50:45 +08:00
- The world is composed of "things"
- State + Behavior
- Encapsulates complexity
2025-12-18 00:50:45 +08:00
## Purpose-Oriented Programming
- The world is composed of "intent"
- Speaks of requirements, not steps
- From imperative → declarative → intentional
2025-12-18 00:50:45 +08:00
---
# 4. Design Principles: Rules for Maintaining Order
## High Cohesion
- Related things close together
- Unrelated things isolated
- Single Responsibility is the core of cohesion
2025-12-18 00:50:45 +08:00
## Low Coupling
- Modules like planets: predictable, yet unbound
- Fewer dependencies, longer life
- No coupling, only freedom
2025-12-18 00:50:45 +08:00
---
# 5. System View: Viewing Programs as Systems
2025-12-18 00:50:45 +08:00
## State
- The root of all errors, improper state
- Less state, more stable program
- Make state explicit, limit state, automatically manage state
2025-12-18 00:50:45 +08:00
## Transformation
- A program is not an operation, but a continuous change
- Every system can be seen as:
2025-12-18 00:50:45 +08:00
`output = transform(input)`
## Composability
- Small units → composable
- Composable → reusable
- Reusable → evolvable
2025-12-18 00:50:45 +08:00
---
# 6. Ways of Thinking: The Programmer's Mindset
2025-12-18 00:50:45 +08:00
## 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
2025-12-18 00:50:45 +08:00
## Specification Precedes Implementation
- Behavior precedes structure
- Structure precedes code
- A program is the shadow of its specification
2025-12-18 00:50:45 +08:00
---
# 7. Stability and Evolution: Making Programs Live Longer
## Stable Interface, Unstable Implementation
- API is a contract
- Implementation is detail
- Not breaking the contract is being responsible
2025-12-18 00:50:45 +08:00
## Complexity Conservation
- Complexity does not disappear, it only shifts
- Either you bear it, or the user bears it
- Good design converges complexity internally
2025-12-18 00:50:45 +08:00
---
# 8. Laws of Complex Systems: How to Manage Complexity
## Local Simplicity, Global Complexity
- Each module should be simple
- Complexity comes from combination, not modules
2025-12-18 00:50:45 +08:00
## Hidden Dependencies are the Most Dangerous
2025-12-18 00:50:45 +08:00
- Explicit > Implicit
- Transparent > Elegant
- Implicit dependencies are the beginning of decay
2025-12-18 00:50:45 +08:00
---
# 9. Reasonability
- Predictability is more important than performance
- Programs should be understandable by the human mind
- Few variables, shallow branches, clear state, flat logic
- Reasonability = Maintainability
2025-12-18 00:50:45 +08:00
---
# 10. Time Perspective
- A program is not a spatial structure, but a temporal structure
- Each piece of logic is an event unfolding over time
- Design should answer three questions:
2025-12-18 00:50:45 +08:00
1. Who holds the state?
2. When does the state change?
3. Who triggers the change?
---
# 11. Interface Philosophy
## API is a Language
- Language shapes thought
- Good interfaces prevent misuse
- Perfect interfaces make misuse impossible
2025-12-18 00:50:45 +08:00
## Backward Compatibility is a Responsibility
- Breaking an interface = breaking trust
2025-12-18 00:50:45 +08:00
---
# 12. Errors and Invariants
## Errors are Normal
- Default to error
- Correctness needs proof
2025-12-18 00:50:45 +08:00
## Invariants Keep the World Stable
- Invariants are the physical laws of a program
- Explicit constraints = creating order
2025-12-18 00:50:45 +08:00
---
# 13. Evolvability
- Software is not a statue, but an ecosystem
- Good design is not optimal, but adaptable
- The best code is the code you will understand in the future
2025-12-18 00:50:45 +08:00
---
# 14. Tools and Efficiency
## Tools Amplify Habits
- Good habits are amplified into efficiency
- Bad habits are amplified into disaster
2025-12-18 00:50:45 +08:00
## Use Tools, Don't Be Used By Them
- Understanding "why" is more important than "how"
2025-12-18 00:50:45 +08:00
---
# 15. Mental Models
- Models determine understanding
- Understanding determines code
- The right model is more important than the right code
2025-12-18 00:50:45 +08:00
Typical models:
- Program = Data Flow
- UI = State Machine
- Backend = Event-Driven System
- Business Logic = Invariant System
2025-12-18 00:50:45 +08:00
---
# 16. Principle of Least Astonishment
2025-12-18 00:50:45 +08:00
- Good code should work like common sense
- No astonishment is the best user experience
- Predictability = Trust
2025-12-18 00:50:45 +08:00
---
# 17. High-Frequency Abstractions: Higher-Order Programming Philosophy
2025-12-18 00:50:45 +08:00
## Program as Knowledge
- Code is the precise expression of knowledge
- Programming is formalizing vague knowledge
2025-12-18 00:50:45 +08:00
## Program as Simulation
- All software is a simulation of reality
- The closer the simulation is to the essence, the simpler the system
2025-12-18 00:50:45 +08:00
## Program as Language
- The essence of programming is language design
- All programming is DSL design
2025-12-18 00:50:45 +08:00
## Program as Constraint
- Constraints shape structure
- Constraints are more important than freedom
2025-12-18 00:50:45 +08:00
## Program as Decision
- Every line of code is a decision
- Delaying decisions = retaining flexibility
2025-12-18 00:50:45 +08:00
---
# 18. Quotations
2025-12-18 00:50:45 +08:00
- Data is fact, function is intent
- A program is cause and effect
- Abstraction is compressing the world
- Less state, clearer world
- Interface is contract, implementation is detail
- Composition over inheritance
- A program is a temporal structure
- Invariants make logic stable
- Reasonability over performance
- Constraints create order
- Code is the shape of knowledge
- Stable interface, fluid implementation
- No astonishment is the highest design
- Simplicity is the ultimate complexity
2025-12-18 00:50:45 +08:00
---
# Conclusion
**The Way of Programming is not about how to write code, but how to understand the world.**
2025-12-18 00:50:45 +08:00
Code is the shape of thought.
A program is another language for understanding the world.
May you maintain clarity in a complex world, and see the essence in code.