Programming Paradigm
一句话解释
programming paradigm 是样式 or philosophy 的编写 code, 如 imperative, declarative, or 对象-oriented.
用大白话说
A programming paradigm is a way of thinking about and structuring your code. Different paradigms approach problem-solving differently — they are like different schools of thought in programming.
Major paradigms include:
- Imperative: step-by-step instructions (C, Pascal)
- Object-oriented: organize code around objects and classes (Java, C#)
- Functional: pure functions, no side effects (Haskell, Elixir)
- Declarative: describe what you want, not how (SQL, HTML)
- Procedural: a subset of imperative, organized into procedures/functions (C, Fortran)
大多数modern languages support multiple paradigms. JavaScript can be imperative, object-oriented, or functional. Python supports OOP and functional styles. Choosing a paradigm depends on the problem, the team, and the language. Understanding multiple paradigms makes you a more versatile programmer.
示例
// Imperative style — step by step
let total = 0;
for (let i = 0; i < arr.length; i++) {
total += arr[i];
}
// Functional style — declare what you want
const total2 = arr.reduce((sum, n) => sum + n, 0);
// Object-oriented style — organize around objects
class Calculator {
sum(arr) { return arr.reduce((a, b) => a + b, 0); }
}相同任务 (summing 数组) in three paradigms: imperative (循环), functional (reduce), and OOP (类方法).
相关术语
相关资源
相关课程
- Programming Paradigms
学习关于 programming paradigms.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。