Live data from Hacker News

Why does nobody seem to know what imperative and declarative mean?

leebriggs.co.uk

41–50 of 77 posts

Re: Why does nobody seem to know what imperative and declarative mean?

#41

edit: fixed a mistake where I put imperative instead of declarative So what I get from this is that Pulumi is declarative, but authoring Pulumi is imperative (unless you’re using an declarative language, which afaik Pulumi doesn’t support any). I’m a pretty pedantic person, so I’d probably make this same argument once I had the knowledge. I don’t see what it changes for a developer though. If I’m writing imperative c…

I wrote my own Ruby code to manage Kubernetes manifests. Instead of messing with templates, I generate or transform manifests, sometimes functionally, sometimes not.

Declarative is necessary if one is trying to have something maintain a desired state and do what is necessary to move the current state to the desired state.

I wonder if this is why I hear a lot of people say K8S is complex. I mean, it isn’t simple, but it isn’t _that_ complex.

Re: Why does nobody seem to know what imperative and declarative mean?

#43
post #33

Would it help if functional langs were instead called declarative?

Well, if you use the definition of "functional" that is the most popular nowadays, you will just lose some specificity, because there are many other declarative language paradigms besides the functional.

Re: Why does nobody seem to know what imperative and declarative mean?

#44
I think it's just a weakness of the terms. Kind of like "interpreted vs compiled" at this point very little is strictly interpreted, almost everything goes through a bytecode compilation step.

In this case, you're using imperative languages to generate declarative policies. Things just aren't black and white.

Importantly, it doesn't really matter. We say "Python is interpreted" because the it gives you the UX of an interpreted language. We say "Pulumi is imperative" because it gives you the UX of an imperative language. Under the hood they do their own thing, but unless you're trying to have a really precise conversation it's usually easiest to stick to those terms.

Re: Why does nobody seem to know what imperative and declarative mean?

#45
post #33

Would it help if functional langs were instead called declarative?

Well, if you use the definition of "functional" that is the most popular nowadays, you will just lose some specificity, because there are many other declarative language paradigms besides the functional.

Perhaps have a hierarchy where functional is a subset of declarative but introduce it to the public as declarative first then delve into functional as needed

Re: Why does nobody seem to know what imperative and declarative mean?

#46

I gotta say, the core argument in this article is quite weak. Here it is, quoted from the middle of the article: While the operation of checking the value of isMinikube is indeed imperative, the result is still declarative. What does this mean? Pulumi as a tool is declarative. It’s the language you’re using to write things that’s imperative, not Pulumi itself. Ooo.. fighting words. So let me get this straight, if a t…

The tool takes in a data structure that doesn't encode any control flow. How that data structure is generated is a separate issue. I'm sure there are tools to imperatively generate whatever input Terraform needs (yaml?), does that make Terraform declarative as well?

Fundamentally the model is still: this is the state I want, and Pulumi figures out how to make that happen. Just like Terraform. The specification of that state can be static, fill-in-the-blank templated, or make use of imperative logic to build the final data structure. Just like Terraform, albeit one step removed because of the yaml intermediary.

Is it easier to write an imperatively-specified boondoggle of a state because of the direct access to an imperative runtime, sure. But that's against best practice and not what they're advocating here. Hell, I could hide the ternary behind a declarative interface (function) and then what's the difference between the imperative code hidden by my function and the imperative code hidden behind Pulumi's or Terraform's state evaluation and application functions?

Re: Why does nobody seem to know what imperative and declarative mean?

#47

Earlier quoted context omitted.

It's much like the difference between "how" and "what". SQL select statements are my favored example of declarative: you simply "declare" what you want ("all rows from this table with these values in those columns") and it's up to an engine to actually figure out how to do that for you. In an imperative language like C you could produce the same output, but you'd be specifying how, not just what: a for loop to iterat…

But each layer’s what is the layer above its how. My C code is just declaring the program I want to run. How it is run is determined by a compiler, assembler, linker, operating system, and CPU. There’s a sort of useless sense in which everything is declarative if you are allowed to shift around what the relevant “thing to be done” is, and it seems like many people are complaining that the article does this exact thin…

Sure it's a spectrum and the exact edges can be blurry. But no-one's going to argue that there isn't a qualitative difference between a sql query and the same logic written out in c

Re: Why does nobody seem to know what imperative and declarative mean?

#48

Earlier quoted context omitted.

As an example, declarative would be something like squares = map(square, inputs) While imperative would be a for loop, store this here, multiply that with this, push that onto the end of my results array, etc

Function calls don't make something declarative, otherwise C is declarative. And once you accept that, then words have no meaning anymore and we can't meaningfully discuss the topic.

> Function calls don't make something declarative

Expressions instead of statements is a key tool to make things declarative; the functional and logic paradigms are both declarative programming paradigms, as opposed to the structured/procedural and OO paradigms, which are imperative.

Re: Why does nobody seem to know what imperative and declarative mean?

#49
post #28

Taking a moment to plug https://dhall-lang.org/ , a truly non-imperative solution in this space

As much as I like Dhall, it needs unions like in typescript so we don't see `Some` littered everywhere.

Like other forms of subtyping, unions make type inference much harder - typically undecidable. This is, of course, incompatible with guaranteed termination.

Re: Why does nobody seem to know what imperative and declarative mean?

#50
post #5

Amazing rant but I really wish they gave you a quick tldr on what the fuck the difference is between imperitive and declarative.

Flow control? Imperative. No flow control? Declarative. What is flow control? Typically if/then/else statements. Importantly, setting a variable with a conditional does not make the language necessarily imperative. I wonder if a language can be Turing-complete without flow control. My guess is no?

The author seems as confused as the people he complains about.

Just his example of `x = a ? b : c`, I never saw anybody try to claim code like this makes a language imperative. Instead, I've seen many people calling this logic "functional if".

If you go with his definition, only simple variable declaration is declarative.

(By the way, a very popular definition is that imperative languages have flow, not flow control. AKA, it makes a difference if you go and execute the instructions on a different order. That one is reasonable, but then, why single out non-associativity of operations when there are many other things that no language makes non-associative?)

Post reply on HN