Declarative Programming

The conventional programming practice (know as Imperative programming)  where a developer define a number of actions to change the state of a data element is getting obsolete due to it’s gap between what a problem is manifested in the real word with software solution. The imperative programming was around for many years. There were a lot of improvements in the paradigm to make the imperative techniques better. 

The point is that irrespective of the disruptive developments in technology and programming languages in the last 50 years, the programming style has been quite imperative. The procedural languages, where  a program is made of a list of actions sequentially to achieve a desired functionality seems to be inefficient.  The procedural style was evolved with a structural style where complex lengthy procedures can be split into blocks and subroutines which makes the programs easily understandable and maintainable. The biggest development in Imperative programming was Object oriented programming style which was evolved in MIT in 1960.

The improvements of Imperative programming drastically improved the maintainability and manageability of the code. It also improved the leaning lead time. However it didn’t actually make a paradigm shift in the thought process until Declarative programming evolved in the last 5 years.

What’s declarative programming 

The declarative programming in simple words is all about what to be achieved rather than  how to reach a goal. The  concerns of declarative programming is around variables, control flow and declarative programming  doesn’t worry about the state. This is because steps and intermediate states to transform the initial state of a variable into the final state is not a concern here. The declaratives paradigms are around operational semantics which is implicit. There are 2 classes of  declarative programming languages. They are functional and second is relational respectively.

Functional language

The functional language relate input to the output. Microsoft has introduced a functional language called F# , although this is supported in VB and C#. The F# is an open source under Apache 2.0 licence and it’s being ported on multiple platforms using through a software foundation. The functional programming is about building an output based on input without worrying about the state. The functional programming is built on lambda calculus. The tutorial by Rojas  provide a thorough and short introduction of Lambda calculus

The functional language is normally implemented as application of functions to the arguments. The functional programs  lacks states, assignments. This means the input variables holds it’s value. It should also be noted that the functional program will not have any impact on anything else, rather it should just compute output(s) based on input(s).  

Relational Language

While the functional language shows you how to arrive at an output from input, the relational language talks about how inputs can be related to output. A relation can be viewed as a reversible function that can return an arbitrary number of values. For example, the “square root” relation maps the number [0] to itself, but maps [4] to [2 -2].  The relational programming style relate the input to the output. In conventional programming , for example the sqrt(16) returns 4. This is not right in it’s strictest sense. The sqrt(16) => {4,-4} . The relational way is that square root of 16 should be related to a set of 2 numbers which is +2 and –2.  This is called a binary relation. In a relational language there is only one solution which might relate a single input to 1 or more outputs (when 1 input relate to 2 outputs similar sqrt function, then it is called binary relation. Similar there can be ternary as well as higher order relationships can occur) . The Z specification language  uses algebraic notation to specify the relations. The relational langue implements solution through multiple ways such as parallel execution and through a method called back tracking. The language  LIBRA uses back tracking.

Declarative programming in Action


The declarative practice is heavily used in higher level language,especially for customization. The as a service provided by Salesforce)  platform of Salesforce  is one of the most notable example of declarative programming. Although support an object oriented language, the majority of customization can be done through click and configure (declaratively). This means someone with thorough knowledge on the Salesforce object model can customize much of the platform without writing a single line of code. The visual aspect of declarative practice make Salesforce one of the most productive platform to work with. This makes the multi tenant cloud based CRM platform scalable and extensible. 


The Microsoft provide a full blown functional programming language called  F# ( ), which enables representation of complex ideas in a simple and  declarative way. The book- Real-World Functional Programming book  thoroughly covers how  real world problems can be resolved declaratively. The XAML(eXtensible Application Markup Language) which is the foundation of WPF (Windows Presentation Framework) , WCF (Windows Communication Foundation) and WF (Windows Workflow Foundation) is one of the best declarative implementations under Microsoft hood . Microsoft allows programmers to declare cross cutting concerns (such as security, logging etc.,) declaratively. Microsoft research has a number of parallel streams( declarative problem solvingdeclarative data centre, data structure and development ) which explore the possibility declarative programming in Microsoft platforms. The declarative practice has become essential in Microsoft platform development.  The LINQ (functional style) lamda expression are brought functional programming into the mainstream of .NET. One one another  functional programming example is  TPL (Task Parallel Library) in .NET


The developers in the java world didn’t think that Java is fast enough into the world of declarative programming. This created open source JVM based implementation of languages such as  JRuby, Groovy, Scala, Clojure. The project Lambda and it’s popularity indicate that how much the developers wanted such functionality in java which allows programmers to build multithreaded & multi-core capable  java programs at ease.  One another area where Java started using declarative style extensively is in its EJB implementation 


Additionally almost all popular languages such as Python, java script (Microsoft provide a declarative library) now implement declarative paradigm


The declarative style increase the coding productivity (ability to automate the code) and reduce the code cluttering (reduces number of lines of code). This can make maintenance and enhancements easier (users can customize or possibly add  features). The biggest contribution of declarative programming is in the world of parallel programming.  The multi-core CPUs are norms even in mobile and embedded processors and there is a need to deliver error proof programs runs  on these platforms as quickly as possible. The declarative style of programming is  definitely a solution to such problems.  The PaaS (Platform as service) is largely becoming declarative and stay in the same for for foreseeable  future.

Posted in Programming