Home > Programming > Notes on declarative programming techniques

Notes on declarative programming techniques

I am reading some great stuff on Computational Models. It is via “Concepts, Techniques and Models of Computer Programming” book from MIT Press, Special thanks to Gaurav for pointing me this. I am dumping my notes here for my future reference

Computational operation: A program fragment with inputs and outputs.

Declarative operation: A computational operation is declarative if

  1. is independent (does not depend on any execution state outside of itself),
  2. stateless (has no internal execution state that is remembered between calls), and
  3. deterministic (always gives the same results when given the same arguments).

A component can be thought of as a precisely delimited program fragment with well-defined inputs and outputs. A component can be defined in terms of a set of simpler components.

Why declarative programming?

  • Declarative programs are easier to compose. A declarative program consists of components that can each be written, tested, and proved correct independently of other components and of its own past history (previous calls).
  • Understanding declarative programs is simple. Why –  “Consider a program with a declarative component. This component can be understood on its own, without having to understand the rest of the program. The effort needed to understand the whole program is the sum of the efforts needed for the declarative component and for the rest. If there would be a more intimate interaction between the component and the rest of the program, then they could not be understood independently. They would have to be understood together, and the effort needed would be much bigger. For example, it might be (roughly) proportional to the product of the efforts needed for each part. For a program with many components that interact intimately, this very quickly explodes, making understanding difficult or impossible.”

Can we do away with non-declarative code? They cannot be “legislated away” by programming in a model that does not directly support them.  But  an  important  principle  is  that  they  should  only  be  used  when necessary and not otherwise. To support this principle, as many components as possible should be declarative.

Classification of declarative programming in 1000 words

Classification of Declarative Models

Another interesting orthogonal taxonomy can found here. Alternative Computational Models by Martin Fowler.

Categories: Programming
  1. No comments yet.
  1. May 25, 2014 at 12:22 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: