Live data from Hacker News

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

leebriggs.co.uk

11–20 of 77 posts

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

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

They do.

> At their core, imperative and declarative differ in one major and fundamental way. Imperative has control flow and declarative does not.

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

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

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

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

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

They do. > At their core, imperative and declarative differ in one major and fundamental way. Imperative has control flow and declarative does not.

That’s a great rule of thumb to quickly identify whether some new syntax is more likely to be imperative or declarative, but it’s not a great explanation of what the two terms mean for someone new to the terms. A banana doesn’t have control flow but it’s definitely not a declarative programming language.

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

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

> I wonder if a language can be Turing-complete without flow control. My guess is no?

I agree, unless something like pattern-matching does not count as control flow. But then isn't a conditional just a basic pattern? Why does it get a pass?

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

#15

Earlier quoted context omitted.

They do. > At their core, imperative and declarative differ in one major and fundamental way. Imperative has control flow and declarative does not.

That’s a great rule of thumb to quickly identify whether some new syntax is more likely to be imperative or declarative, but it’s not a great explanation of what the two terms mean for someone new to the terms. A banana doesn’t have control flow but it’s definitely not a declarative programming language.

I would eat a declarative banana.

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

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

> I wonder if a language can be Turing-complete without flow control. My guess is no?

I can’t imagine why not. I think you have to make the distinction between explicit control flow in the syntax, which declarative languages don’t have (according to this rule of thumb), and the notion of a computer choosing to do one thing among several options depending on some condition. Of course any Turing-complete system can do the latter, but that’s totally unrelated to the syntax of the programming language.

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

#17
post #15

Earlier quoted context omitted.

That’s a great rule of thumb to quickly identify whether some new syntax is more likely to be imperative or declarative, but it’s not a great explanation of what the two terms mean for someone new to the terms. A banana doesn’t have control flow but it’s definitely not a declarative programming language.

I would eat a declarative banana.

In fact, one should eat a declarative banana.

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

#18
post #12

Earlier quoted context omitted.

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?

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 without saying “if” or “when” or specifying one particular element from a set? Obviously any computer system needs to be able to determine what steps to take depending on specified conditions.

Post reply on HN