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
2
votes
4 answers

Coming from an OOP background, what would be some C programs/libraries to help me get the "C way"?

I have been doing OOP (C++/Java/PHP/Ruby) for a long time and really have a hard time imagining how large programs and libraries such as Linux or Apache can be written entirely in an imperative style. What would be small open source C projects I…
Olivier Lalonde
  • 19,423
  • 28
  • 76
  • 91
2
votes
3 answers

large amount of if else refactor

There is a if/else statement in my code and Im thinking of refactoring it.I have already searched many Similar Questions.like this. The best answer said that the chain-of-responsibility pattern is a good choice.But below is a part of my code. If I…
Rock Wang
  • 35
  • 7
2
votes
1 answer

Interning strings in declarative programming

The following scenario shows an abstraction that seems to me to be impossible to implement declaratively. Suppose that I want to create a Symbol object which allows you to create objects with strings that can be compared, like Symbol.for() in…
2
votes
0 answers

Imperative vs. Functional data structure tradeoffs

Is there some trade-off between these two examples of the same thing? My bias is to always use a functional style, but if I'm running billions of these foldLefts, is creating a new FunctionalA for every step in every list less efficient than just…
kmh
  • 1,516
  • 17
  • 33
2
votes
1 answer

Differences between imperative and declarative programming languages?

I know what they are: In an imperative programming language you tell the compiler what you want to happen step by step, whereas in a declarative language you write code which describes the result but not necessarily how to achieve the desired…
madcrazydrumma
  • 1,847
  • 3
  • 20
  • 38
2
votes
4 answers

Check if a value still remains the same in a While loop Python

I want know if there is a elegant method for looking if a value that continually changes in a while loop can be checked and stop the while loop if the value stops change and remains the same. For example: Value = 0 while True: value changes…
RedVelvet
  • 1,683
  • 3
  • 15
  • 24
2
votes
2 answers

Comparison of imperative and functional approach in Java

I have a methods that prints the name of a person from a given list if it has the indicated age. This method is implemented using the imperative and then functional approach. public static void printPerson(int age) { for(Person p: list) { …
Andrei
  • 7,509
  • 7
  • 32
  • 63
2
votes
1 answer

Automata theory and Functional programming

I recently started learning about functional programming and getting hands on with Haskell. With the fundamental difference between functional paradigm and others is, we don't maintain states and there are no computations as in imperative paradigm.…
shar
  • 1,988
  • 2
  • 18
  • 25
2
votes
1 answer

How to convert an imperative double for-loop to functional style without return in Scala?

I have the following Scala code, imperative style, and I was wondering if there is an equivalent in functional style avoiding the use of return: def function(c: Char, vector: Vector[Vector[Char]]): (x:Int , y:Int) = { for (x <- vector.indices) …
bquenin
  • 1,470
  • 2
  • 12
  • 12
2
votes
1 answer

Overhead in functional style programming

In Rust by Example #36, the sum of odd integers up to a limit is calculated in both imperative style and functional style. I separated these two out and increased the upper limit to 10000000000000000 and timed the results: Imperative…
2
votes
2 answers

Is functional language wasting memory?

In general, I want to ask, if a problem can be solved by both imperative language way as well as functional language way, would functional language wasting memory, at least not saving memory, compare to imperative language, since, function…
2
votes
0 answers

Functional programming style vs performance in Ruby

I love functional programming and I love Ruby as well. If I can code an algorithm in a functional style rather than in a imperative style, I do it. I tend to do not update or reuse variables as much as possible, avoid using "bang!" methods and use…
2
votes
1 answer

What GUI libraries are not object-oriented?

I have been using C a lot lately, and want to explore programming more than just console applications. However, most GUI libraries are object-oriented, and it is very difficult to program with them in programming languages which are not…
1
vote
1 answer

How to make mouse events handling easier?

Sometimes I have to implement a feature like customized drag & drop. The code may goes like this: bool mouse_down = false; Vec2 mouse_pos; void on_mouse_down() { mouse_down = true; mouse_pos = cursor_pos(); } void on_mouse_move() { …
pipipi
  • 501
  • 1
  • 3
  • 11
1
vote
1 answer

Is cobol declarative language or its is imperative

while COBOL does support some declarative programming constructs, it is primarily an imperative programming language that is designed to provide low-level control over the machine, and its main focus is on describing how a program should operate,…