编程范式是一种使用某种编程语言解决问题的方法,或者我们也可以说它是一种使用我们可用的工具和技术按照某种方法解决问题的方法。有很多已知的编程语言,但所有这些语言在实现时都需要遵循一些策略,这种方法/策略是范式。除了各种编程语言之外,还有很多范式可以满足每个需求。
命令式编程作为 顾名思义是一种描述程序如何执行的编程范式。开发者更关心如何一步步得到答案。它包括命令命令的序列。在这种情况下,执行顺序非常重要,并且使用可变和不可变数据。 Fortran、 Java、C、C++ 编程语言是命令式编程的例子。
声明式编程作为 顾名思义是一种编程范式,它描述了要执行的程序。开发人员更关心收到的答案。它声明了我们想要什么样的结果,而将编程语言放在一边,专注于简单地弄清楚如何产生它们。简单来说,它主要关注最终结果。它表达了计算的逻辑。 Miranda、Erlang、Haskell、Prolog 是声明式编程的一些流行示例。
在了解这两种语言的基础知识后,现在让您讨论这两种不同类型的编程之间的主要区别
Imperative Programming |
Declarative Programming |
---|---|
In this, programs specify how it is to be done. | In this, programs specify what is to be done. |
It simply describes the control flow of computation. | It simply expresses the logic of computation. |
Its main goal is to describe how to get it or accomplish it. | Its main goal is to describe the desired result without direct dictation on how to get it. |
Its advantages include ease to learn and read, the notional model is simple to understand, etc. | Its advantages include effective code, which can be applied by using ways, easy extension, high level of abstraction, etc. |
Its type includes procedural programming, object-oriented programming, parallel processing approach. | Its type includes logic programming and functional programming. |
In this, the user is allowed to make decisions and commands to the compiler. | In this, a compiler is allowed to make decisions. |
It has many side effects and includes mutable variables as compared to declarative programming. | It has no side effects and does not include any mutable variables as compared to imperative programming. |
It gives full control to developers that are very important in low-level programming. | It may automate repetitive flow along with simplifying code structure. |