0

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".

Sage Gerard
  • 1,311
  • 8
  • 29
  • 3
    Have you gone through - ? Though it may not completely answer your question, to some extent at least you'll get a basic idea... stackoverflow.com/questions/129628/what-is-declarative-programming – verisimilitude Jun 27 '12 at 05:32
  • I saw the question before, so at first I thought you were offering a link for a definition, but then I scrolled down a bit and saw the answer that I assume you guys wanted me to see. Thanks! – Sage Gerard Jun 27 '12 at 12:11

1 Answers1

2

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.

ewernli
  • 38,045
  • 5
  • 92
  • 123
  • In the regex examples, even DFAs/NFAs would be somewhat delcarative. Writing out a state machine with loop+switch is the real imperative equivalent, and way worse to do by hand. –  Jun 27 '12 at 11:03