几种编程范式

175 阅读1分钟

1. Declarative Programming 声明式编程

  1. The programmer instructs the computer what to be computed 程序指示电脑计算什么
  2. Do not know how it works ,but you know what it does 不知道怎么工作的,但是知道做了什么
  3. Decouple DOM manipulation from app logic and improve the testability of code将逻辑和DOM操作解耦,改善代码的可测试性
  4. Improves readability of a code 提高代码可读性

2. Imperative Programming 命令式编程

  1. The script is basically telling the computer how to do something 脚本基本上是告诉计算机如何做某事
  2. Imperative phrases which change the global state of a program 改成程序状态的命令短语
  3. Not scalable 不可扩展

3. Object Oriented Programming 面向对象编程

  1. Program is defined by object which combine state and behavior 程序被包含状态和行为的对象定义
  2. Good for structured and modular code 适用于结构化和模块化代码
  3. Well suited for big projects 高度适配大型项目

4. Functional Programming 函数式编程

  1. Treats computations as the excution of functions and aviods changing state and mutable data 将计算作为函数的输出结果并避免状态修改和可变数据
  2. Eliminating side effects ,ie.e, changes in state that do not depend on the function inputs ,can make it much easier to understand and predict the behavior of a programmer 消除副作用,即不依赖函数输入状态的变化,使更容易的理解和预测函数的行为
  3. Emphaize using of immutable data 加强不可变数据的使用