Question

I understand what declarative languages have to offer, but I have not yet connected the dots as to why I would use them. For example, I do not understand why describing a problem is more beneficial than writing a solution to an already understood problem in an imperative language (side-effects non-withstanding).

This is not a discussion about what makes a good application in declarative language. I only want to understand the circumstances and any common, specific project requirements that would make a programmer say "We really should use a declarative language for this".

Was it helpful?

Solution

As a rule of thumb, I guess declarative programming makes sense when there exists multiple strategies to achieve one goal. Declaratively programming the what rather than the how let the parser/compiler/runtime figure out which strategies is best--it optimizes the execution for you.

Two exemples of declarative languages and optimizations:

  • regular expression -- do you really want to bother about the underlying DFA, NDFA that are required for a fast execution?
  • SQL queries -- the DBMS has statistics and caches and can (hopefully) figure out an optimal execution plan

The link provided by @verisimilitude is worth reading.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top