Questions tagged [imperative-programming]

Imperative programming is a paradigm of expressing the logic of a computer program or computation by explicitly describing its control flow in terms of statements that change a program state.

From Wikipedia:

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

FAQ:

See also

143 questions
794
votes
21 answers

What is the difference between declarative and imperative paradigm in programming?

I have been searching the web looking for a definition for declarative and imperative programming that would shed some light for me. However, the language used at some of the resources that I have found is daunting - for instance at Wikipedia. Does…
Brad
  • 20,302
  • 36
  • 84
  • 102
89
votes
4 answers

Why is Haskell (sometimes) referred to as "Best Imperative Language"?

(I hope this question is on-topic -- I tried searching for an answer but didn't find a definitive answer. If this happens to be off-topic or already answered, please moderate/remove it.) I remember having heard/read the half-joking comment about…
hvr
  • 7,775
  • 3
  • 33
  • 47
62
votes
6 answers

Functional Programming Vs Declarative Programming Vs Imperative Programming

I have been too used to Imperative Programming which is the usual way of telling the computer to perform step by step the procedure to get the final result. On the other hand, declarative programming just passes the input and expects the output…
50
votes
2 answers

What are the performance impacts of 'functional' Rust?

I am following the Rust track on Exercism.io. I have a fair amount of C/C++ experience. I like the 'functional' elements of Rust but I'm concerned about the relative performance. I solved the 'run length encoding' problem: pub fn encode(source:…
48
votes
13 answers

Haskell vs. procedural programming in the real world

These days I'm getting seriously into functional programming. While I'm really excited about Haskell and the possibilities it seems to offer, I can also see now that it is going to take me a while to learn. In an SO question on How to learn Haskell…
user50685
36
votes
13 answers

Mixing object-oriented and functional programming

What languages are available that promote both object-oriented and functional programming? I know that any language that supports first-class functions can be considered functional, but I'm looking for a syntax that's specifically targeted for both…
Kai
  • 9,444
  • 6
  • 46
  • 61
34
votes
4 answers

Idiomatic clojure for progress reporting?

How should I monitor the progress of a mapped function in clojure? When processing records in an imperative language I often print a message every so often to indicate how far things have gone, e.g. reporting every 1000 records. Essentially this is…
31
votes
4 answers

Examples where compiler-optimized functional code performs better than imperative code

One of the promises of side-effect free, referentially transparent functional programming is that such code can be extensively optimized. To quote Wikipedia: Immutability of data can, in many cases, lead to execution efficiency, by allowing the…
18
votes
3 answers

Python programming functional vs. imperative code

So I'm currently in a class learning about the 3 major programming paradigms. I know that python uses both the functional and imperative paradigms. I was looking for a short sample code in python of each of these paradigms to better understand this…
Bobcat88
  • 738
  • 2
  • 7
  • 22
17
votes
4 answers

Reason for using reactive programming in simple cases

Please, can somebody explain me what are the advantages of using reactive style: Observable greeting = Observable.just("Hello"); Observable yelling = greeting.map(s -> s.toUppercase()); instead of simple imperative style: String…
Sever
  • 2,338
  • 5
  • 35
  • 55
16
votes
3 answers

Why are simple for loop expressions restricted to integer ranges?

According to the F# spec (see §6.5.7), simple for loops are bounded by integer (int aka int32 aka System.Int32) limits start and stop, e.g. for i = start to stop do // do sth. I wonder why the iteration bounds for this type of for loop are…
Frank
  • 2,738
  • 19
  • 30
15
votes
4 answers

When imperative style fits better?

From the Programming in Scala (second edition), bottom of the p.98: A balanced attitude for Scala programmers Prefer vals, immutable objects, and methods without side effects. Reach for them first. Use vars, mutable objects, and methods with…
PrimosK
  • 13,848
  • 10
  • 60
  • 78
15
votes
5 answers

Is C an imperative or declarative programming language

It is quite confusing to know difference between Imperative and Declarative programming can any one explain difference between both in real world terms? Kindly clarify whether C is an Imperative or Declarative Language?
AshrithGande
  • 351
  • 1
  • 10
  • 25
15
votes
7 answers

Is functional Clojure or imperative Groovy more readable?

OK, no cheating now. No, really, take a minute or two and try this out. What does "positions" do? Edit: simplified according to cgrand's suggestion. (defn redux [[current next] flag] [(if flag current next) (inc next)]) (defn positions [coll] …
foxdonut
  • 7,779
  • 7
  • 34
  • 33
13
votes
7 answers

Translating Imperative Java to Functional Java (A Game)

I'm learning a lot more about Java 8 and its functional capabilities, and I wanted to do some more practice with it. Say, for example, I have the following imperative code which is for wrapping a circle around the bounds of the screen: if…
1
2 3
9 10