声明式编程-目标是显性而算法是隐性的

面向(控制)执行 vs 面向描述

 

命令式编程面向算法vs声明式编程面向描述。

命令式编程面向:数据结构与算法;

算法 = 控制 + 逻辑;

命令式编程是行动导向(Action-Oriented)的,因而算法是显性而目标是隐性的;

 

声明式编程将描述与求解分离;

声明式编程面向描述:

面向逻辑、抽象、描述;

逻辑(数学)规则的表达;

计算规则;

结合规则;

处理规则;

特征规则;

 

描述为主,算法为辅。

 

声明式编程专注问题的分析和表达而不是算法实现,不用指明执行顺序,一般没有或极少副作用。同时也非常适合于并发式计算。

 

编程语言的流行程度与其擅长的领域密切相关。函数式语言和逻辑式语言擅长基于数理逻辑的应用,命令式语言擅长基于业务逻辑的、尤其是交互式或事件驱动型的应用。

 

命令式编程通过一系列改变程序状态的指令来完成计算,声明式编程只描述程序应该完成的任务。命令式编程模拟电脑运算,是行动导向的,关键在于定义解法,即“怎么做”,因而算法是显性而目标是隐性的;声明式编程模拟人脑思维,是目标驱动的,关键在于描述问题,即“做什么”,因而目标是显性而算法是隐性的

 

http://www.nowamagic.net/academy/detail/1220528

 

imperative - expressions describe sequence of actions to perform (associative)

declarative - expressions are declarations that contribute to behavior of program (associative, commutative, idempotent, monotonic)

functional - expressions have value as only effect; semantics support equational reasoning

 

 

  • Declarative languages don't have looping control structures, e.g. for and while, because due to immutability, the loop condition would never change.
  • Declarative languages don't express control-flow other than nested function order (a.k.a logical dependencies), because due to immutability, other choices of evaluation order do not change the result (see below).

 

on the other hand, an imperative approach gives you more low level control - it's the "micromanager approach" to programming. 

 

20

Imperative Programming means any style of programming where your program is structured out of instructions describing how the operations performed by a computer will happen.

Declarative Programming means any style of programming where your program is a description either of the problem or the solution - but doesn't explicitly state how the work will be done.

Functional Programming is programming by evaluating functions and functions of functions... As (strictly defined) functional programming means programming by defining side-effect free mathematical functions so it is a form of declarative programming but it isn't the only kind of declarative programming.

Logic Programming (for example in Prolog) is another form of declarative programming. It involves computing by deciding whether a logical statement is true (or whether it can be satisfied). The program is typically a series of facts and rules - i.e. a description rather than a series of instructions.

 

https://stackoverflow.com/questions/1784664/what-is-the-difference-between-declarative-and-imperative-programming

 

posted @ 2018-12-28 15:14  zzfx  阅读(321)  评论(0编辑  收藏  举报