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.

Filter by
Sorted by
Tagged with
1 vote
1 answer
88 views

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 ...
Shahnaz Memon's user avatar
0 votes
2 answers
247 views

How to edit reactive form from an observable data in angular imperatively without subscribing to the Observable?

Below is the process I've been using to subscribe and then update a reactive form based on observable data. Maybe there's a way to fix the problem without subscribing to the observable and changing ...
syahiruddin's user avatar
2 votes
2 answers
133 views

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 ...
user4779's user avatar
  • 696
2 votes
1 answer
751 views

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 ...
Abdelrahman Nasser's user avatar
0 votes
1 answer
127 views

Functional vs imperative (statements): writing this in the most compact way

Looking for the shortest, most elegant wat to write this. I really like option 2. However, i get this error: Argument of type 'boolean[]' is not assignable to parameter of type 'SetStateAction<...
San Jay Falcon's user avatar
1 vote
1 answer
453 views

Incrementing a counter with functional programming vs imperative programming

I likely am asking a very stupid question here, please forgive me. I am a Java and C# backend-engineer with relatively good knowledge of OOP design patterns. I have recently discovered the debate ...
ndrscodes's user avatar
1 vote
2 answers
64 views

sort a singly linked list formed of 1, 2 and 0s by swapping the nodes through one traversal in C

I'm trying to solve the question that I need to sort a given linked list which values consist of 1, 2 and 0 by traversing the list only once and I need to swap the nodes not values. my code is: #...
user avatar
-1 votes
1 answer
318 views

OCaml loops: imperative vs recursion [closed]

I just stumbled upon some OCaml code that writes a loop like this: let r = ref (f 0) in for i = 1 to k - 1 do r := f i * !r done ; !r in Which is interesting as I normally see ...
David 天宇 Wong's user avatar
3 votes
1 answer
156 views

Updating an outer variable in Haskell

There is a sense in which Haskell is a purely functional language, and certainly, idiomatic code tries to be as functional as reasonably possible. At the same time, Haskell does provide support for ...
rwallace's user avatar
  • 31.9k
1 vote
1 answer
141 views

gotoxy in game condign with C

I am currently developing a Duck Hunt-style game with C language for a university class, but I'm having a problem that I can't move the player's aim while keeping the targets moving, for some reason, ...
Lucasfig's user avatar
2 votes
2 answers
1k views

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 ...
Mandroid's user avatar
  • 6,428
0 votes
2 answers
56 views

Why do I get a type unit when I want to concatenate the element of the array with an empty list?

I am trying to make a list out of a given array and in my code it returns an empty list. I want to know why this is impossible to do with list. Is it because we are supposed to return something in the ...
tacocat's user avatar
  • 23
1 vote
1 answer
65 views

Functional approach to storing element counts in Map

I came across a problem where I needed to count the number of Strings in an Iterable and store the sums in a Map. I came up with the following imperative solution: private static Map<String, ...
TheShinx317's user avatar
0 votes
1 answer
625 views

How can I generate imperative non-OOP python code from UML/SysML model?

I want to generate python code based on UML/SysML. The coding is mainly imperative - calling functions that deliver results, switch states and some main part. How can I create some simple main program,...
DoctorG's user avatar
  • 19
-4 votes
1 answer
91 views

Why is functional-styled code so much faster than imperative code in C?

I've been working on an algorithm for calculating maximum depth of an expression (i.e. how many nested parentheses there are) in various languages just for fun/practice. I noticed there's a huge ...
Dylan Turner's user avatar
1 vote
1 answer
827 views

Spring Reactive implementation calling db multiple times

I a new to reactive and trying to accomplish the below task in efficient way. I have a table having events for each user. I am trying to get latest row of each event name for a given user filtered ...
JUser's user avatar
  • 145
-1 votes
6 answers
2k views

Finding the sum of numbers from x to y and the program prints the answer as "x+(x+1)....+y= (sum of # from x to y)" [closed]

For example, the sum of numbers from 1 to 3 would be printed as 1+2+3=6; the program prints the answer along with the numbers being added together. How would one do this? Any help is greatly ...
anthonydoesntknowhowtocode's user avatar
2 votes
4 answers
458 views

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; ...
Nick's user avatar
  • 10.1k
2 votes
1 answer
197 views

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

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. ...
Perqin's user avatar
  • 785
2 votes
1 answer
400 views

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? @...
SoCal's user avatar
  • 801
50 votes
2 answers
3k views

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 ...
David Copernicus Bowie's user avatar
1 vote
2 answers
3k views

Using ternary operator just for the side effect - Good or Bad?

Suppose we are using AVKit and we have added a target to our play/pause button to handle the playing/pausing of a track. Is it generally bad practice to use a ternary operator just for its side effect,...
Swifty's user avatar
  • 837
2 votes
1 answer
1k views

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 ...
Andrew Schwartz's user avatar
0 votes
3 answers
93 views

Why functional style search acts faster, then imperative in Java

I’m trying to figure out , why compiler looks through the collection using functional style swiftly then imperative. Here is the simple example where functional search goes first and takes 9.5 sec to ...
Gipsy King's user avatar
2 votes
1 answer
145 views

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....
arabian_albert's user avatar
-1 votes
2 answers
665 views

Mutable and Immutable objects are implemented the same in all programming languages?

The main ideas of immutability are kept the same throughout the scope of OOP and functional programming or do, for example, Java and Python have their own versions of immutability. More specifically ...
Ari's user avatar
  • 364
0 votes
1 answer
262 views

Link between models of computation, computer system architectures and programming paradigms

I have been reading about these topics for a while and may have understood something. But I am confused with some connections: i. Turing Machine (RAM model to be exact) & Imperative Programming ...
codecasterz's user avatar
1 vote
1 answer
182 views

How are data structures created in declarative programming?

An article I read gave this example for the difference between declarative and imperative programming: Declarative small_nums = [x for x in range(20) if x < 5] Imperative small_nums = [] for i ...
Nora McDougall-Collins's user avatar
0 votes
2 answers
1k views

How to modify last element of a generator in python?

I have a generator and I want to modify the last element of the generator. I want to replace the last element with another element. I know how to retrieve the last element, but not how to modify it. ...
aa1's user avatar
  • 783
1 vote
2 answers
224 views

Underscore.js - Imperative & Functional exercise

I'm learning about Underscore.js and the higher order functions. I came across the following problem, and I'm just simply stuck. I'm not looking for a handout but at the same time, I don't have ...
josh_c's user avatar
  • 149
3 votes
1 answer
580 views

OCaml variable, which keeps it value between function calls

Is there a way in OCaml for a variable inside a function to keep its value between function calls? It should work like Pythons default argument, which is a reference to the same object in every ...
user avatar
17 votes
4 answers
11k views

Reason for using reactive programming in simple cases

Please, can somebody explain me what are the advantages of using reactive style: Observable<String> greeting = Observable.just("Hello"); Observable<String> yelling = greeting.map(s -> ...
Sever's user avatar
  • 2,456
2 votes
3 answers
2k views

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 ...
Rock Wang's user avatar
0 votes
3 answers
691 views

Pointer to a record in OCaml

I am implementing binary search trees in OCaml, trying to use as much imperative programming as possible. I have the following data type: type tKey = Key of int;; type tBST = Null | Pos of node ref ...
deko's user avatar
  • 485
-1 votes
2 answers
142 views

Is unix's 'cp' command declarative or imperative? [closed]

I'm having a discussion with a coworker, who insists cp is declarative. To me, it seems very imperative. It's an instruction we are asking the computer to do, not a definition or declaration. For it ...
Dominic Bou-Samra's user avatar
1 vote
0 answers
103 views

Haskell MArray performance benchmark

Haskell's MArray is supposed to provide a mutable array. I wonder how does it compare with a normal mutable array in an imperative programming language like Java or C. Is there any performance ...
Mahdi's user avatar
  • 1,949
2 votes
1 answer
322 views

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 ...
while1fork's user avatar
1 vote
5 answers
24k views

The length of a list without the "length" function in Haskell

I want to see how long a list is, but without using the function length. I wrote this program and it does not work. Maybe you can tell me why? Thanks! let y = 0 main = do list (x:xs) = list (xs) ...
Ezeeroc's user avatar
  • 185
3 votes
1 answer
668 views

Imperative vs Functional - understanding the von Neumann bottleneck

In the Coursera course - Functional Programming in Scala - Martin Odersky talks about how Imperative Programming is constrained by the von Neumann bottleneck because it deals largely with mutable ...
harry callahan's user avatar
11 votes
1 answer
167 views

Fast impertive pointers (static, unboxing, etc.) with Struct library

I am interested in using more efficient pointers for a project implementing an imperative language in Haskell. There is already a library for that: Struct. There is a blog post on it and brief ...
mrsteve's user avatar
  • 4,092
-2 votes
3 answers
2k views

Is Haskell an imperative or declarative paradigm?

I have read some sources where the Haskell's paradigm is described as functional but imperative paradigm. The main source where this is said is Wikipedia. How is possible a functional and imperative ...
Iván Cortés's user avatar
-1 votes
2 answers
606 views

Functional Programming vs Imperative Programming: Computation Time

I've got a general question about functional programming vs imperative programming. I am a hobby programmer implementing some engineering problems with C#. You always here a lot concerning the ...
Johannes's user avatar
  • 161
-10 votes
1 answer
1k views

C++ Part of brute-force knapsack

reader, Well, I think I just got brainfucked a bit. I'm implementing knapsack, and I thought about I implemented brute-force algorithm like 1 or 2 times ever. So I decided to make another one. And ...
0x9093717's user avatar
0 votes
0 answers
241 views

Can pure imperative programming incorporate functions

As the question suggests, if a program should be written in a purely imperative style (even if the programming language is an amalgamated language like PHP or Python which support other paradigms like ...
Liam Fell's user avatar
  • 1,302
0 votes
1 answer
68 views

Are data races intrinsic to imperative programming and an obstacle for parallel computing?

I don't study this area of computing to be honest. Actually my references is some web and academic articles then I'm insecure but curious about some concepts of parallel computing. I've formulated ...
Alexandre Thebaldi's user avatar
1 vote
1 answer
98 views

Immutable state is a functional feature in ReactJs?

The most important feature of an imperative program is the state and their modifications. ReactJs encourages as much functional style of programming (e.g. using purity, higher-order functions). I ...
Alexandre Thebaldi's user avatar
4 votes
2 answers
268 views

SICP - Imperative versus Functional implementation of factorial

I am studying the SICP book with Racket and Dr. Racket. I am also watching the lectures on: https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-...
user avatar
0 votes
1 answer
398 views

Better readability and simplicity versus higher complicity and speed in programming, what to chose? [closed]

Solving my homework for Informatics at University, I always find different ways to solve the same problem. One way is the fastest(execution time) but the longest and more complex. And the other is ...
DomainFlag's user avatar
7 votes
3 answers
501 views

Why functional programming language support automated memoization but not imperative languages?

This is a question I read on some lectures about dynamic programming I randomly found on the internet. (I am graduated and I know the basic of dynamic programming already) In the section of ...
shole's user avatar
  • 4,066
0 votes
2 answers
92 views

Possible OCaml code generation bug

The following self contained code highlights a problem in OCaml, possibly with the code generation. Array x has connectivity information for nodes in [0..9]. Function init_graph originally constructed ...
user5754881's user avatar