Difference between Declarative and Procedural Programming?
During one of my interviews, they asked me the difference between Declarative Programming and Procedural Programming types.
What is the difference between them with examples?
PS : Could you tell me besides these two and object oriented programming, what type programming languages there are? Because they may ask the difference between other programming languages too. And there are similar questions like this one but too scattered.
Declarative
Describe a result and get it via a black box. The opposite of imperative. Examples:
Procedural or Imperative
Describe the algorithm and process steps, at various degrees of abstraction.
Object Oriented
Functional
You left this one out. Functional programming emphasizes the application of functions without side effects and without mutable state. The declarative systems above exhibit certain aspects of functional programming.
Declarative programming is where you say what you want without having to say how to do it. With procedural programming, you have to specify exact steps to get the result.
For example, SQL is more declarative than procedural, because the queries don't specify steps to produce the result.
In simple words, i have a real world example in which i need a cup of tea.
Procedural:
Declarative:
In procedural language, you define the whole process and provide the steps how to do it. You just provide orders and define how the process will be served.
In declarative language, you just set the command or order, and let it be on the system how to complete that order. You just need your result without digging into how it should be done.
Regards,
链接地址: http://www.djcxy.com/p/22874.html下一篇: 声明式和程序式编程之间的区别?