声明式编程与(控制)算法

In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an imperative programming language from a declarative programming language.

 

A declarative language declares a set of rules about what outputs should result from which inputs (eg. if you have A, then the result is B). An engine will apply these rules to inputs, and give an output.

Declarative programming : is a programming paradigm that expresses the logic of a computation(What do) without describing its control flow(How do). Some well-known examples of declarative domain specific languages (DSLs) include CSS, regular expressions, and a subset of SQL (SELECT queries, for example) Many markup languages such as HTML, MXML, XAML, XSLT... are often declarative. The declarative programming try to blur the distinction between a program as a set of instructions and a program as an assertion about the desired answer.

 

Functional programming : is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data.

 

I liked an explanation from a Cambridge course + their examples:

  • Declarative - specify what to do, not how to do it
    • E.g.: HTML describes what should appear on a web page, not how it should be drawn on the screen
  • Imperative - specify both what and how
    • int x; - what (declarative)
    • x=x+1; - how

 

In computer science, declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow.

 

that expresses the logic of a computation without describing its control flow

 

 

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

 

 

首先从第一个差异声明范式开始,声明式编程的重点是应该做什么事,而不是如何去做(后者是命令式编程)。命令式语言往往集中在一个程序的方法,明确如何实现具体操作及改变程序的状态,而声明式编程表达操作的逻辑(不要着眼于实现)。

 

声明式编程透过函数、推论规则或项重写(term-rewriting)规则,来描述变量之间的关系。它的语言运行器编译器解释器)采用了一个固定的算法,以从这些关系产生结果。

转载于:https://www.cnblogs.com/feng9exe/p/10191424.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值