Geeks With Blogs

News kaleidoscope 1817, lit. "observer of beautiful forms," coined by its inventor, Sir David Brewster (1781-1868), from Gk. kalos "beautiful" + eidos "shape" (see -oid) + -scope, on model of telescope, etc. Figurative meaning "constantly changing pattern" is first attested 1819 in Lord Byron, whose publisher had sent him one.

Kaleidoscope Everything under the sun, ending in .Net

Imperative Programming ::

Imperative programming is a programming paradigm that describes computation in terms of statements that change a program state. In much the same way as the imperative mood in natural languages expresses commands to take action, imperative programs define sequences of commands for the computer to perform.

The focus is on what steps the computer should take rather than what the computer will do (ex. C, C++, Java).

Declarative Programming ::

Declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow. It attempts to minimize or eliminate side effects by describing what the program should accomplish, rather than describing how to go about accomplishing it.

The focus is on what the computer should do rather than how it should do it (ex. SQL).

A  C# example of declarative v/s. imperative programming is LINQ.

With imperative programming, you tell the compiler what you want to happen, step by step.

For example, let's start with this collection, and choose the odd numbers:

List<int> collection = new List<int> { 1, 2, 3, 4, 5 };
With imperative programming, we'd step through this, and decide what we want:

List<int> results = new List<int>();
foreach(var num in collection)
    if (num % 2 != 0)
Here’s what we are doing:

*Create a result collection
*Step through each number in the collection
*Check the number, if it's odd, add it to the results

With declarative programming, on the other hand, we write the code that describes what you want, but not necessarily how to get it

var results = collection.Where( num => num % 2 != 0);

Here, we're saying "Give us everything where it's odd", not "Step through the collection. Check this item, if it's odd, add it to a result collection."

Functional Programming ::

Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions.Functional programming has its roots in the lambda calculus.

It is a subset of declarative languages that has heavy focus on recursion.

Functional programming can be a mind-bender, which is one reason why Lisp, Scheme, and Haskell have never really surpassed C, C++, Java and COBOL in commercial popularity. But there are benefits to the functional way. For one, if you can get the logic correct, functional programming requires orders of magnitude less code than imperative programming. That means fewer points of failure, less code to test, and a more productive (and, many would say, happier) programming life. As systems get bigger, this has become more and more important.

To know more :


Posted on Thursday, May 13, 2010 9:10 PM | Back to top

Comments on this post: Imperative Programming v/s Declarative Programming v/s Functional Programming

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © kaleidoscope | Powered by: | Join free