Live data from Hacker News

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

leebriggs.co.uk

31–40 of 77 posts

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

#31
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.

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 iterate over each row in the table, if statements to compare values, etc.

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

#32

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.

Unless they're talking about layers, with the function prototypes and function calls being declarative, and the next layer down being where the code is actually written out. Even that doesn't really work, though; main() usually has code in it...

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

#34
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 code then the tool running my IaC might as well be imperative. I guess it’s a cool piece of trivia to know though.

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

#35
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.

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 thing.

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

#38

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…

By that logic everything is imperative. Authoring the data structure for whatever IaC tool is going to take on the characteristics of however you author it. Is the same yaml detailing the desired state declarative when I hand-write it and imperative when I use some language to generate it?

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

#39
post #2

Learn the difference between imperative and declarative! Knowing the difference between imperative and declarative is very important.

Let us discuss this more. If I were more knowledgeable of this, there would surely be benefits.
Post reply on HN