In computer science, declarative programming is a programming paradigm — a style of building the structure and elements of computer programs—that expresses the logic of a computation without describing its control flow. This is in contrast with imperative programming, which implements algorithms in explicit steps.
声明式编程:告诉“机器”你想要的是什么(what),让机器想出如何去做(how)。
In computer science, imperative programming is a programming paradigm that uses statements that change a program's state. In much the same way that the imperative mood in natural languages expresses commands, an imperative program consists of commands for the computer to perform. Imperative programming focuses on describing how a program operates. The term is often used in contrast to declarative programming, which focuses on what the program should accomplish without specifying how the program should achieve the result.
命令式编程:命令“机器”如何去做事情(how),这样不管你想要的是什么(what),它都会按照你的命令实现。
-
声明式编程让我们去描述我们想要的是什么,让底层的软件、计算机去解决如何实现。
-
在很多情况中,就像我们看到的一样,声明式编程能给我们的编程带来真正的提升,通过站在更高层面写代码,我们可以更多的专注于 what,而这正是我们开发软件真正的目标。
问题是,程序员习惯了去描述 how,这让我们感觉很好很安心能够控制程序的运行状态,不放走任何我们不能看见不能理解的处理过程。