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
3
votes
3 answers

Is object-orientated programming compatible with functional programming?

I grew up being taught java, and I've started to learn a lot of PHP over the last few years using popular open-source CMSs. I really love the natural-feeling of OOP, but I've more recently discovered the concept of functional programming, which…
3
votes
3 answers

Prolog 'is/2' predicate implementation

How is the 'is/2' Prolog predicate implemented? I know that X is 3*4 is equivalent with is(X, 3*4) But is the predicate implemented using imperative programming? In other words, is the implementation equivalent with the following C…
bsky
  • 19,326
  • 49
  • 155
  • 270
3
votes
2 answers

return type after while in a try

Almost for the first time I'm trying to write imperative code in ocaml to try to answer a question on this website, but I'm facing a little problem. let f() = try while true do () done with _ -> 2 He doesn't like this, because he thinks…
bruce_ricard
  • 743
  • 1
  • 7
  • 15
3
votes
7 answers

Executing code BETWEEN loop iterations

Say you want to loop through 3 elements like this: for(int i=0; i<3; i++) { doSomething(); } Of course, this is the same as saying: doSomething(); doSomething(); doSomething();. Now, let's say you want to do something BETWEEN each iteration, as…
hgarland
  • 33
  • 2
3
votes
2 answers

An operator riddle

While converting a project from Python to C#, I found some interesting differences in the syntax families. Yet I got stuck, still unable to understand and comprehend the dissimilar behavior of comparison operator in C#. During the course of curing…
2
votes
3 answers

Name a list in Scheme

I'm trying to make an array-like data structure in Scheme, and since I need to refer to it (and alter it!) often, I want to give it a name. But from what I've read on various tutorial sites, it looks like the only way to name the list for later…
AmberWolfe
  • 55
  • 3
  • 8
2
votes
4 answers

Is there a standardized way to transform functional code to imperative code?

I'm writing a small tool for generating php checks from javascript code, and I would like to know if anyone knows of a standard way of transforming functional code into imperative code? I found this paper: Defunctionalization at Work it explains…
2
votes
2 answers

Functional evaluation of conditionals in C#?

In functional programming a statement like if (a || b) can be evaluated in parallel by default, since we don't make any assumptions about the evaluation order due to referential transparency. Is there any easy way to introduce this type of…
user4779
  • 645
  • 5
  • 14
2
votes
1 answer

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

Recently, I was searching for a way to enhance navigating between screens in my Flutter apps. and I found new programming concepts for me (declarative and imperative programming). I need to know more about the declarative and imperative paradigms…
2
votes
2 answers

Functional programming: Declarative vs imperative

Functional programming insists on telling what to do, rather than how to do. For example,Scala's collections library has methods like filter, map etc. These methods enable developers to get rid of traditional for loops, and hence so called…
2
votes
4 answers

Better way to express "if false return false" construct

In many cases you have code like this (C-style pseudo code used): bool checkCondition(); bool doSomething(){ if (checkCondition() == false) return false; // do something return true; } I keep reusing this patter and every time…
Nick
  • 9,962
  • 4
  • 42
  • 80
2
votes
1 answer

Why re-constructing view hierarchy is affordable in declarative UI frameworks like Flutter?

I am reading Flutter's official documentation on state management and in this page it says: For example, in Flutter it’s okay to rebuild parts of your UI from scratch instead of modifying it. Flutter is fast enough to do that, even on every frame…
2
votes
1 answer

Is it common to have code that looks "imperative" supporting reactive code?

It seems like I'm starting to write "imperative looking" methods to support the functionality/readability of the reactive chains. This may not be the most technical of questions, but is this common? @Component public class MyRequestHandler { …
SoCal
  • 801
  • 1
  • 10
  • 23
2
votes
1 answer

How do I tell tell a child element in React to seek its video element?

I have a simple React app with a video player and chart displaying data about the video. Both are in their own components at the top level: class App extends Component { ... render() { return (
2
votes
1 answer

Converting iteration loop body into functional code Java 8

I want to convert the below imperative code into functional code using Java 8. The way it works is I capture the current time before and after the API call, then I subtract the before from the after. The result is a rough time it took for the API…