---
title: "Imperative and declarative programming"  
description: "In this blog I am trying to explain the imperative and declarative (functional) programming.Declarative (functional) programming:Declarative (function"  
author: "Vijay Shukla"  
published: 2013-04-25  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/487/imperative-and-declarative-programming  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Imperative and declarative programming

In this blog I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to explain the imperative and declarative ([functional](https://www.mindstick.com/articles/13005/the-functional-aspects-of-laser-technology)) programming.

Declarative (functional) programming:

Declarative (functional) programming expresses the logic of a computation without describing its [control flow](https://www.mindstick.com/interview/33772/what-is-the-control-flow-function-and-its-execution-in-control-flow-statements). Many languages applying this style attempt to minimize or eliminate [side effects](https://yourviews.mindstick.com/story/4434/5-side-effects-of-eating-too-many-chia-seeds) by describing what the program should accomplish, rather than describing how to go about accomplishing.

For instance, if you have a list in C# and you want to pull out every Nth element, you have to point at the first element, set a counter at one, move to the next element, increment the counter, check to see if you're at the Nth element and so on. The functional equivalent would be to write a function that recognizes when the size of a list is a multiple of N, and then pass that function to the list, possibly with another snippet of code to hand back the head of the list [if your](https://www.mindstick.com/forum/156103/what-will-be-your-approach-if-your-seo-method-doesn-t-work) N-recognizer evaluates to true and discarding it if it evaluates to false. The two functions recurs through the list, and finally hand back a list consisting of every Nth element.

[Imperative Programming](https://answers.mindstick.com/qa/111797/what-are-the-main-differences-between-functional-and-imperative-programming-paradigms)

A [developer](https://www.mindstick.com/articles/157260/variation-between-web-designer-and-web-developer) writes code that describes in exacting detail the steps that the computer must take to accomplish the goal. This is sometimes [referred to as](https://answers.mindstick.com/qa/39930/at-the-turn-of-the-century-widespread-panic-occurred-that-at-midnight-all-computers-would-reset-to-zero-and-life-as-we-knew-it-would-cease-to-exist-what-was-this-doomsday-theory-commonly-referred-to-as) algorithmic programming. In contrast, a functional approach involves composing the problem as a set of functions to be executed. You define carefully the input to each function, and what each function returns. The following table describes some of the general [differences](https://www.mindstick.com/articles/12918/cat-5e-vs-cat-6a-understanding-the-major-differences) between these two approaches.

---

Original Source: https://www.mindstick.com/blog/487/imperative-and-declarative-programming

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
