Original link: https://sexywp.com/imperative-and-declarative-programming.htm
Imperative programming, Imperative Programming, is a kind of programming generic. Through programming instructions, it tells the computer that the command to be executed in each step, the computer executes line by line according to the instructions of the code, and then the final result can be obtained. The advantage of imperative programming is that it is very intuitive, the code gives the command and the computer executes it. Therefore, this kind of programming generics is also very easy to learn. The C language, Java language, etc. that we learned in the beginning all support imperative programming and are also the main programming generics of such languages. Object-oriented programming is also a kind of programming generics, and at the same time, object-oriented programming generics are also a special case of imperative programming generics. Therefore, imperative programming is a more abstract concept. Declarative programming, Declarative Programming, as the name suggests, this kind of programming generics is more inclined to tell the computer, “what is”, and let the computer decide how to operate. Declarative programming is very difficult to understand because there are many things that cannot be self-evident. The program only needs to tell the computer how to switch from one state to another in two different states, and the computer can automatically complete the replenishment. For example, the Flutter I am learning, this framework is building an application interface, such as to do a function, the interface is a button, after clicking, you can hide the number on the interface and switch to an asterisk. If we use imperative programming, we might write this (pseudocode): If we use declarative programming, we might write this: In imperative programming generics, we give the label an order to hide the content . In declarative programming, we tell the interface whether to display an asterisk or a number based on the hide flag. In the click event, we just re-specify the value of hide. Then, the interface was originally 12345, how did it become ***? It’s not mentioned in the code, and you can’t expect that when the code executes to a certain line, the number on the interface will turn into an asterisk. These are determined and scheduled by the framework itself. In fact, it is not difficult to imagine that there will definitely be an instruction at the bottom of the framework or system to tell the graphics engine at a certain time to erase the numbers and redraw the asterisks, but these have nothing to do with the programmers who write the upper-level business. . Therefore, imperative programming generics are fundamental. After all, the CPU is driven by machine code or assembly instructions, and it is impossible not to return to imperative programming generics. Declarative programming generics are a higher-level methodological abstraction than imperative programming generics. It’s like a company only describes what the company’s vision is. As for how to achieve it, everyone from the president to the grassroots employees must work hard and work hard towards the goal, which can only be achieved after a long time. Using declarative programming generics, the programmer’s productivity can be released more, and the programming efficiency is also higher, but obviously, the underlying framework or engine will undertake more work, in order to intelligently implement the interface or the interface declared by the programmer. The state completes the change in the middle. -End- Tags: flutter, Programming Paradigm
This article is reprinted from: https://sexywp.com/imperative-and-declarative-programming.htm
This site is for inclusion only, and the copyright belongs to the original author.