I am studying two main paradigms of programming, declarative and imperative paradigm. I am having a hard time following the ambiguous statements made on my textbook and wikipedia, such as:
declarative:
– focuses on “what” the computer is to do.
– is free of “side effects”
– without control flow
imperative:
– focuses on “how” the computer should do it.
– how to do it in terms of sequence of actions
how would you differentiate the two programming paradigms? If you could expand on the statements made above, it will be very helpful.
SQL is the classic declarative language: you say “look at this table, and give me all rows that meet these criteria” (and in real-life you use joins, select lists, whatever, but it’s the same basic statement). As you noted above, this statement tells the computer what you want, not how to do it.
Internally, the database system is implemented in a language like C, and your SQL query will be translated into the following imperative steps:
One of the key things to note here is the explicit control flow: while, for, and if. These won’t appear in declarative languages.