I remember I had a situation in the past where I was trying to write an SQL query to perform a complex migration on the database. Despite the trials, the migration logic was too complex to achieve by simply using native SQL.
I tried to explain to the team that SQL is not the right language to be used in this situation, but I couldn’t use the right words to explain why! I remember I said something like, “We can achieve it but with a language like Java.”. But why Java and not SQL? What makes these languages different?
Declarative Programming
Declarative programming is the type of programming where you ask the language to perform a task for you without caring about the internal details of how the task will be executed.
Declarative programming languages focus on specifying the desired outcome, rather than providing explicit instructions on how to achieve it. They emphasize the “what” rather than the “how”. Although this might provide a higher level of abstraction, it leads to less flexibility.
They are mostly domain-specific languages (DSLs). Some well-known examples are SQL and HTML.
Imperative Programming
Imperative programming is the type of programming where you use the language to specify explicitly the steps required to achieve a desired outcome.
Imperative programming languages are steps-oriented. They emphasize the “how” rather than the “what”. Unlike declarative programming languages, imperative ones provide higher flexibility and low-level control.
They are mostly general-purpose languages (GPLs). Some well-known examples are Java, Python, PHP, and nearly most of the famous programming languages.
Now, you get the difference between declarative and imperative languages. This helps you understand the mindset behind the two types and the strengths and limitations of the languages under each. Hence, better decisions!