Live data from Hacker News

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

leebriggs.co.uk

51–60 of 77 posts

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

#51
post #45

Earlier quoted context omitted.

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

Well, "introduce it to the public" is quite a badly defined action, isn't it?

I mean, what practical thing do you think people should do differently?

Besides, we are just arguing about the definition of some words that people can't really agree on their meaning (most people are close to each other, so the words aren't meaningless, but they are still different). Piling-up more of those words isn't a benefit.

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

#52
post #20

Earlier quoted context omitted.

In fact, one should eat a declarative banana.

The declarative banana should be in my stomach.

After the 20 or so comments that responded I'm still no closer to understanding.

The SQL guy sort of made sense I guess maybe.

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

#53
TLDR: everyone does know what imperative and declarative mean, but when it comes to Pulumi (an infrastructure-as-code development kit), nobody other than the author makes a distinction between Pulumi itself (declarative) and the code that uses Pulumi (imperative).

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

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

Example Problem: Calculate the sum of the first N natural numbers.

Declarative: N(N+1)/2

Imperative: for(int sum=0, int i=1; i<=N; i++) {sum = sum+i;}

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

#55

Earlier quoted context omitted.

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.

I don't know what you're trying to get at, you seem to be agreeing with me. Function calls (present in C and other structured, procedural, and OO paradigm languages which are also imperative) do not make a language declarative.

That they're also present in the functional and logic paradigms doesn't change that. It's a feature common to both, so not a feature that can be used to distinguish the categories from each other.

And regarding expressions, Rust is more expression oriented than most mainstream procedural languages today, and it's not declarative, though it may have more declarative-style (particularly its heavy use of the iterator style) compared to many other imperative languages.

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

#56
Randy's law of config files:

In the limit, all config files become a language.

So if you have a so-called "declarative" config file, it eventually becomes a ... ? Language - that's imperative. Every time. Yes, really.

What is the only time this doesn't happen? If the config system ceases to exist.

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

#57

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?

I would say yes. If you're writing that YML by hand, and that YML doesn't have extensions that provides control-flow (e.g. CloudFormation's if syntax), then you're writing something declarative. If you're using an imperative language, and you're using control-flow, then you're using that tool in an imperative way.

It doesn't make sense to define the attributes of a tool by its artifacts. If we applied that logic across the board then Haskell isn't a purely functional language because it eventually gets compiled to machine code which is imperative.

What matters is the source, not the artifact. In the case of Pulumi you are using imperative languages, so Pulumi is effectively imperative, although it can technically be considered declarative when you consider the Pulumi runtime. If Pulumi had support for a declarative language, then I would consider it a declarative tool.

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

#58

Earlier quoted context omitted.

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

I don't know what you're trying to get at, you seem to be agreeing with me. Function calls (present in C and other structured, procedural, and OO paradigm languages which are also imperative) do not make a language declarative. That they're also present in the functional and logic paradigms doesn't change that. It's a feature common to both, so not a feature that can be used to distinguish the categories from each ot…

> Function calls (present in C and other structured, procedural, and OO paradigm languages which are also imperative) do not make a language declarative.

“Declarative” and “imperative” are not really features of languages in the first place. They are features of code (and coding paradigms), and you can write code of either style (and usually most paradigms) in almost any real-world, Turing-complete, higher-level-than-assembly language.

The specific replacement of an imperative loop with a map call you made the non-sequitur response about function calls to upthread however, made the code it was in more declarative, though, and is typical of the ways that the functional paradigm (where map is typically the idiomatic way to do that) is more declarative than the structured/procedural paradigm (where building up a collection in an imperative loop would be.)

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

#59

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 i…

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

I'd still take issue with that description. There is a massive UX distinction here that isn't under the hood.

Your imperative Pulumi code is at a meta/macro/preprocessor level. That's completely different from writing imperative code that manipulates your servers.

Your code generates declarations. It does not take actions.

Boiling that down to one word is likely not the best way of doing it, but I agree with the author that in this situation the function/output of what you write is more important than how it gets there. The stuff you write doesn't configure servers, it describes servers.

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

#60

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 tha…

I’m not asserting that terraform is declarative, or that pulumi and terraform are technically different.

I’m saying, this article is about the pedantic definition of what it means to be declarative vs imperative.

…and pedantically, if you’re partially imperative, you’re imperative.

Otherwise, you’re choosing to redefine the terms to suit your convenience.

Which you’re welcome to do too… but you can’t pedantically tell people they don’t know what a term means and redefine it to mean something convenient.

Post reply on HN