7 ms·
Why does nobody seem to know what imperative and declarative mean?
- trollski 4y ago
- k__ 4y agoIn my experience, the critique of Pulumi and the CDK came down to not using the Cloud Formation service directly and adding needless abstractions over it. I didn't see much complaint about imperative vs declarative.
- blacksqr 4y agoLearn the difference between imperative and declarative! Knowing the difference between imperative and declarative is very important.
- inkeddeveloper 4y agoI see what you did there.
- Infernal 4y agoLook at what you did there.
- bashmelek 4y agoLet us discuss this more. If I were more knowledgeable of this, there would surely be benefits.
- msie 4y agoYes, sadly, I have seen this too many times.
- fjdbeb76 4y agoAmazing rant but I really wish they gave you a quick tldr on what the fuck the difference is between imperitive and declarative.
- TedDoesntTalk 4y agoFlow 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?
- anyfoo 4y agoI'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 building up what I would the state of the system to look like", still without telling the system what to do to get to that state. > I wonder if a language can be Turing-complete without flow control. My guess is no? Depends on your definition of "flow control". Untyped lambda calculous is effectively entirely just declaration and application of anonymous functions with only one argument, but it's Turing complete. You can even try it in any language that has lambdas as first class citizens, e.g. here's a factorial function I wrote in Lambda calculous, but implemented in python: fac = ((lambda p: p(p)(lambda q: lambda n: ((n(lambda e: lambda e: lambda a: a)(lambda i: lambda l: i))(lambda d: lambda c: c) (lambda m: (lambda m: lambda z: m(n(z)))(q(m)))((lambda c: lambda x: n(lambda g: lambda h: h(g(c)))(lambda u: x)(lambda u: u)))))) (lambda s: lambda q: lambda w: q(s(s)(q))(w))) Does it have flow control? Depends. No python flow control is used, but some of those lambdas implement flow control. But they're not any part of the language (Lambda calculous), we just build them. Would I call Lambda calculous declarative? Not at all!
- tshaddox 4y ago
- cyanydeez 4y ago
- rektide 4y agoYes, Pulumi is nouns not verbs. It is declarative. Like Terraform, you're not saying: "make me an virtual machine," you're saying, "this virtual machine", which gets created if needed. But like Terraform can be if you start importing data-sources, Pulumi can get dynamic. Your Pulumi code might have some actions/verbs it does to figure out what to write. You might slip up one day and get a little bit pregnant. Oops I mean get a little bit imperative. In Terraform, these external dependencies are declared, are declarative style, but they carry the risk of imperativeness, in that they don't have idempotency, they don't clearly delineate what is expected: they're commands-as-structures, actions-as-structures, executed via higher level systems. Pulumi might not be imperative, but there's less clear lines (unlike an explicit Terraform data-source) & it's less clear when you get a little bit imperative.
- mdale 4y agoGreat comments so far ;)
- hkgjjgjfjfjfjf 4y ago
- formerkrogemp 4y ago"It is ever the province of specialists to overstate their domain. Generalists don't know too much or a lot of anything in particular!"
- wokwokwok 4y agoI 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.
- andreareina 4y agoThe 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?
- s-zeng 4y agoTaking a moment to plug https://dhall-lang.org/ https://dhall-lang.org/, a truly non-imperative solution in this space
- throwaway23329 4y agoAs much as I like Dhall, it needs unions like in typescript so we don't see `Some` littered everywhere.
- hither_shores 4y agoLike other forms of subtyping, unions make type inference much harder - typically undecidable. This is, of course, incompatible with guaranteed termination.
- _8j50 4y agoWould it help if functional langs were instead called declarative?
- marcosdumay 4y agoWell, 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.
- _8j50 4y agoPerhaps 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
- marcosdumay 4y agoWell, "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.
- shepherdjerred 4y agoedit: 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.
- andreareina 4y agoBy 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?
- shepherdjerred 4y agoI 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.
- hosh 4y agoI 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.
- theknocker 4y ago
- philliphaydon 4y agoI can’t take him seriously! He didn’t like pineapple on pizza!!!!
- staticassertion 4y agoI 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.
- Dylan16807 4y ago> 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.
- staticassertion 4y agoI 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.
- Dylan16807 4y ago
- justinludwig 4y agoTLDR: 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).
- RandyRanderson 4y agoRandy'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.
- SAI_Peregrinus 4y agoIt doesn't have to become an imperative language. It could turn into Prolog.
- falcor84 4y ago>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.
- capableweb 4y agoPuppet 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.
- SomaticPirate 4y agoThe 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/1486463852313133058?s=21&t=jKkYJ6i2sDrGQKQMV-peRQ https://twitter.com/dave_universetf/status/14864638523131330...
- Spivak 4y agoIs 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.
- cnunciato 4y agoNot to a Node.js programmer!
- mbrodersen 4y agoDeclarative: Describe the result you want (without any implementation details). Imperative: Describe step by step how a global mutable state is manipulated. Functional: Describe how an immutable value is calculated.