Questions tagged [imperative]

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.

57 questions
15
votes
3 answers

Difference between 'kubectl apply' and 'kubectl create'

I created a pod with kubectl create -f pod.xml and kubectl apply -f pod.xml using the below yaml and I don't see any difference, a pod gets created with both the commands. The K8S document, mentions imperative and declarative commands. But, still…
Praveen Sripati
  • 32,799
  • 16
  • 80
  • 117
14
votes
5 answers

closures and objects

Functional programming .. is like classic ( Mark Twain's type). While reading another articles about SICP, where people are talking about the great impact closures had on there thinking, i got reminded of this, which i read ages ago Closures are…
vrdhn
  • 4,024
  • 3
  • 31
  • 39
13
votes
6 answers

If I come from an imperative programming background, how do I wrap my head around the idea of no dynamic variables to keep track of things in Haskell?

So I'm trying to teach myself Haskell. I am currently on the 11th chapter of Learn You a Haskell for Great Good and am doing the 99 Haskell Problems as well as the Project Euler Problems. Things are going alright, but I find myself constantly…
Asaf
  • 815
  • 1
  • 9
  • 25
10
votes
1 answer

Scala Performance: imperative vs functional style

I'm new to Scala and was just reading Scala By Example. In chapter 2, the author has 2 different versions of Quicksort. One is imperative style: def sort(xs: Array[Int]) { def swap(i: Int, j: Int) { val t = xs(i); xs(i) = xs(j); xs(j) =…
sivabudh
  • 31,807
  • 63
  • 162
  • 228
9
votes
3 answers

A Functional-Imperative Hybrid

Pure functional programming languages do not allow mutable data, but some computations are more naturally/intuitively expressed in an imperative way -- or an imperative version of an algorithm may be more efficient. I am aware that most functional…
user793587
8
votes
6 answers

How do I code a tree of objects in Haskell with pointers to parent and children?

I've got the following problem: I have a tree of objects of different classes where an action in the child class invalidates the parent. In imperative languages, it is trivial to do. For example, in Java: public class A { private List
axilmar
  • 836
  • 1
  • 13
  • 17
8
votes
4 answers

transferring an imperative for-loop into idiomatic haskell

I have some difficulties to transfer imperative algorithms into a functional style. The main concept that I cannot wrap my head around is how to fill sequences with values according to their position in the sequence. How would an idiomatic solution…
fuji
  • 1,173
  • 1
  • 10
  • 27
7
votes
2 answers

Nice examples of imperative versus functional solutions to practical problems

I am writing some lesson materials for a course that starts in a couple of weeks. I chose Clojure as a new language for students to learn. I would like to dedicate one chapter to refactoring imperative code to functional code. For this I would like…
Michiel Borkent
  • 34,228
  • 15
  • 86
  • 149
6
votes
4 answers

What functional language techniques can be used in imperative languages?

Which techniques or paradigms normally associated with functional languages can productively be used in imperative languages as well? e.g.: Recursion can be problematic in languages without tail-call optimization, limiting its use to a narrow set…
Rob Lachlan
  • 14,289
  • 5
  • 49
  • 99
5
votes
2 answers

F# Idiomatic Performance

I'm using Exercism to learn F#. The Nth Prime challenge was to build a Sieve of Eratosthenes. The unit test had you search for the 1,001st prime which is 104,743. I modified a code snippet I remembered from F# For Fun and Profit to work in…
EricP
  • 502
  • 2
  • 14
5
votes
5 answers

Are the implementation details of declarative languages inherently imperative

I'm reading 'Functional Programming' by Tomas Petricek & Jon Skeet and I understand the difference between declarative & imperative programming. What I was wondering is how are the primitive operators & functions implemented, are declarative…
4
votes
2 answers

I want to call it side-effect programming, but there's gotta be a better term for this

What is the name of the following programming paradigm: Code is executed based on a set of logical tests resolving to true (the clause). The clause is comprised of operators and operands. Each operand is a value/object. Instead of evaluating the…
Hanoixan
  • 449
  • 3
  • 12
4
votes
1 answer

Is gradle declarative or imperative build tool?

I suppose gradle uses build scripts that can be programmed as per the requirements. Is it a declarative or imperative build tool then?
Vivek
  • 11,938
  • 19
  • 92
  • 127
4
votes
1 answer

When to use declarative programming over imperative programming

As far as I know the main difference between declarative and imperative programming is the fact that in declarative programming you rather specify what the problem is, while in imperative programming you state exactly how to solve a problem.…
VincentDS
  • 310
  • 2
  • 8
4
votes
1 answer

Can programming be truly declarative?

I've been teaching myself a bit about declarative vs imperative programming, and I've come to the (possibly false) understanding that declarative programming is more or less just abstraction. For example, according to how I understand these…
jah
  • 155
  • 1
  • 2
  • 11
1
2 3 4