Live data from Hacker News

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

leebriggs.co.uk

61–70 of 77 posts

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

#61

Earlier quoted context omitted.

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…

Exactly. You could even write declarative style C, or make your code _more_ declarative. It’s not some binary decision. It generally just means writing higher level language describing the result you want, rather than all the instructions to produce it. Functional languages are very good at letting you right declarative code, especially when it comes to dealing with sequences and lists. Ruby’s enumerator in particular allows you to write code in that style, rather than complicated nested for loops full of conditional logic.

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

#62

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…

I think ultimately you're just demonstrating the larger point. There is no value trying to label it as imperative or declarative except in the niche situation where one is debating whether it is imperative or declarative, which at some point is just a philosophical question.

I think it was Plato who asked this question - if I take two pieces of clay and smash them together, which piece grew? You can argue all day about it, and it has some fun implications about identity, but that's philosophy.

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

#64

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.

It doesn't have to become an imperative language. It could turn into Prolog.

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

#65

>Unless I’m mistaken, Terraform was the first tool to drive home the importance of defining infrastructure declaratively. Puppet started popularizing declarative configuration management almost a full decade earlier.

Puppet is declarative configuration. Terraform is declarative infrastructure. Usually you'd use both together (or replacing one with something similar, like Ansible instead of Puppet).

Idea is, you run Terraform to create/modify the infrastructure, and Puppet to configure the software running on that infrastructure.

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

#66
The author is making a pedantic point. While I agree with the main thesis that Pulumi *as a tool* is declarative, one of the main selling features (and the first thing I think of with Pulumi) is how languages like Python can be used to write it. Hence, the association of everyone besides the the author with Pulumi == imperative code.

The imperative vs declarative argument has been used to keep Pulumi out of several infra repos I have been responsible for. A ball of horrible Terraform is much better than a ball of terrible Node.js Pulumi.

https://twitter.com/dave_universetf/status/14864638523131330...

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

#67

Earlier quoted context omitted.

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

And I’m not arguing that. The article is dealing with those blurry edges, though, and what layer “matters” in evaluating the distinction is very much at issue. So if we’re going to compare to SQL/C, we need to bring in the relevant analogous nuances

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

#68

The author is making a pedantic point. While I agree with the main thesis that Pulumi *as a tool* is declarative, one of the main selling features (and the first thing I think of with Pulumi) is how languages like Python can be used to write it. Hence, the association of everyone besides the the author with Pulumi == imperative code. The imperative vs declarative argument has been used to keep Pulumi out of several i…

Is Vagrant suddenly not declarative just because the config is written in Ruby?

Also that rant is just a woeful misunderstanding of well everything, but in particular AWS and k8s. If you do it in Terraform you couldn’t specify the AZs either and instead have to define a VPC config with two subnets. That’s an AWSism not Pulimi.

“I will learn nothing and complain the whole time!” isn’t as damning of a criticism as they think.

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

#69

Earlier quoted context omitted.

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

I think ultimately you're just demonstrating the larger point. There is no value trying to label it as imperative or declarative except in the niche situation where one is debating whether it is imperative or declarative, which at some point is just a philosophical question. I think it was Plato who asked this question - if I take two pieces of clay and smash them together, which piece grew? You can argue all day abo…

If you care about the type of thing you need to write, there's tons of reason to make the distinction.

The thing about writing "code that outputs a data structure" is that you can voluntarily choose to use no control flow.

The tool takes declarative input, and optionally you can use imperative code to make the job of writing that input easier.

That's very different from a tool that gives you helper functions for writing an imperative core. In that case you're always writing something that's full of control flow, and it's up to you to make sure you get all the state transitions to be consistent with each other.

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

#70
post #20

Earlier quoted context omitted.

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.

The "has control flow" vs "doesn't have control flow" description is a bad one, an attempt to reduce "declarative vs imperative" down to syntax instead of semantics. The parent to my comment is still in imperative style, despite having no control flow: It's specifying what actions to take to reach the desired outcome ("eat"). Declarative is describing the desired outcome, then letting the system figure out how to get there.

When you write an SQL query, you're not describing steps to take, you're describing the outcome you want (what rows and fields from which tables and how those tables relate to each other). The query engine then takes that description and figures out how to actually do the query (what indices to use, in what order, how to actually loop/hash/map/scan the tables and indices, etc). This is what EXPLAIN shows you, the actual imperative plan the query engine came up with given the declarative query you gave it.

Another common example would be CSS: It's all about describing the desired result and spatial relationships between elements, then the CSS engine takes those rules and figures out how to actually get those elements to do what you want. Like something as seemingly simple as "float: left" - for the text to wrap around it, the engine has to deal with the image size, position, font and font size, figuring out when to wrap the text, height of the font, which line of text is greater than the image height, etc. The engine does a lot of work figuring out the steps to take to get the result you've described.

Post reply on HN