2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 命令式编程面向算法vs声明式编程面向描述

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

时间:2019-08-15 21:43:16

相关推荐

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

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

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

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

算法 = 控制 + 逻辑;

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

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

声明式编程面向描述:

面向逻辑、抽象、描述;

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

计算规则;

结合规则;

处理规则;

特征规则;

描述为主,算法为辅。

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

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

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

/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 havevalueas only effect; semantics support equational reasoning

Declarative languages don't have looping control structures, e.g. for and while, becausedue 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), becausedue 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 Programmingmeans any style of programming where your program is structured out of instructionsdescribing how the operations performed by a computer will happen.

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

Functional Programmingis programming by evaluating functions and functions of functions... As (strictly defined) functional programming means programming by defining side-effect free mathematical functions so itis 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.

/questions/1784664/what-is-the-difference-between-declarative-and-imperative-programming

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。