Imperative programming vs. Declarative programming
What is imperative programming vs. declarative programming
Imperative programming means that each steps of command/code is specified to get the final computation result.
Declarative programming means that only the results that are wanted are specified, no step by step code is provided to get the final computation results.
For example,
SQL is a declarative programming language
select * from user
where name = 'bily'
c++ is an iimperative programming language
vector<string> users;
for(int i=0; i < users.size(); i++) {
if(users[i] == "bily") {
cout << user[i] << endl;
}
}
Advantage and disadvantage of imperative programming.
-
Imperative programming depends on defined instructions to achieve final computation results, so code can be easy to understand and straightforward.
-
Order of performed operations is completely controlled by developer
-
Bugs can be easily traced because the program is assembled from blocks of code that is based on step by step commands.
-
Memory allocation and manipulation is directly linked in imperative programming. Efficient use of machine memory.
Reference
Enjoy Reading This Article?
Here are some more articles you might like to read next: