Live data from Hacker News

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

leebriggs.co.uk

21–30 of 77 posts

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

#22
post #12

Earlier quoted context omitted.

I'm not even sure I agree with the author with that specifically: > Flow control? Imperative. > No flow control? Declarative. I think I'd rather say: Imperative: Tell the system what to do. Declarative: Tell the system what you would like to be . The system figures out what to do to get there. You could well have flow control to say things like "if things are like that, I want things to be such", or "here is a loop b…

> Depends on your definition of "flow control". Yep. That’s why this is a potentially useful rule of thumb for comparing programming languages, especially ones that skew very far in one direction or the other, but it’s not a rigorous definition of the concepts. Some incredibly simple algorithms are difficult to explain naturally without it sounding like control flow. How would you describe the absolute value function…

> How would you describe the absolute value function without saying “if” or “when

How is this? absolute value is distance a number is from 0.

I get your point, though.

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

#23
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?

Prolog would like to have a word.

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

#24
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 tool that uses an imperative language emits a declarative configuration that the tool executes, the original tool is declarative and not imperative.

…because, and this is the core argument here: at the execution step, the commands that are executed, are executed in sequence by the tool without flow control, except that which is internal to the tool itself (eg. check if s3 bucket is present, if so, don’t create it).

So, for example, if I compile source code into a assembly, and then run it… the assembly is executed step by step.

…so, my code is declarative then is it? Since the artifacts emitted by the compile step are a linear sequence of steps with no flow control other than what the compiler emits?

This is just pedantic nonsense.

Look, flat out: if you apply flow control, it is imperative.

It’s completely ridiculous to say that if you generate a declarative configuration in an imperative manner, and execute the declarative configuration, the end-to-end process is declarative.

It’s not. It’s imperative.

No amount of redefining terms is going to change that.

If you want, you could invent something called “declarative infrastructure deployment”, which is where the end user does not manually define imperative code to check the infrastructure state, and relies on the tool to check and resolve the “desired state”. You could also call it “desired state deployments”, or “cool deployments”.

The you could say, sure these tools either are or are not conforming to your definition of this type of tool.

Sure, fine. That’s easy to verify; does the tool expose primitives to express flow control in response to deployed infrastructure state explicitly? It’s a yes / no.

…but, that doesn’t make those tools declarative. They’re just “whatever term you invented here” tools. …but putting “declarative” in the name you invented doesn’t make it declarative.

Pulumi has flow control. It is imperative. QED.

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

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

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

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

#26
post #12

Earlier quoted context omitted.

I'm not even sure I agree with the author with that specifically: > Flow control? Imperative. > No flow control? Declarative. I think I'd rather say: Imperative: Tell the system what to do. Declarative: Tell the system what you would like to be . The system figures out what to do to get there. You could well have flow control to say things like "if things are like that, I want things to be such", or "here is a loop b…

> Depends on your definition of "flow control". Yep. That’s why this is a potentially useful rule of thumb for comparing programming languages, especially ones that skew very far in one direction or the other, but it’s not a rigorous definition of the concepts. Some incredibly simple algorithms are difficult to explain naturally without it sounding like control flow. How would you describe the absolute value function…

> How would you describe the absolute value function without saying “if” or “when” or specifying one particular element from a set?

I don't think you even want a conditional when describing the absolute value function on the complex numbers.

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

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

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.

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

#30

Earlier quoted context omitted.

> Depends on your definition of "flow control". Yep. That’s why this is a potentially useful rule of thumb for comparing programming languages, especially ones that skew very far in one direction or the other, but it’s not a rigorous definition of the concepts. Some incredibly simple algorithms are difficult to explain naturally without it sounding like control flow. How would you describe the absolute value function…

> How would you describe the absolute value function without saying “if” or “when How is this? absolute value is distance a number is from 0. I get your point, though.

True, the syntax will obviously depend on what primitives the language provides. Of course it could also just provide the abs() function directly.
Post reply on HN