logoalt Hacker News

adrian_byesterday at 1:30 PM1 replyview on HN

Anything that causes a persistent change of the state of a system is imperative, regardless of how detailed the command is.

  printf("Hello world!");
also does not tell anything to the system about how to accomplish this.

Anyone who claims that an SQL command like insert a row, create a table or destroy a table is not imperative, is just plainly wrong.

Even in real life, when humans communicate commands to each other, from where the term "imperative" comes, the commands normally do not tell anything to the recipient about how to accomplish the order, they just name the action, because it is supposed that whoever receives the command knows how to do it.

After programming languages were invented there was a clear partition between commands a.k.a. imperative statements, expressions and definitions a.k.a. declarations ("definition" and "declaration" were originally synonymous terms, "declaration" being the ALGOL 60 term and "definition" being the CPL term; the use of the 2 words with different meanings, like in C, where it is required by a defect of the compiler, which needs additional declarations besides a definition, is only recent.)

Later the meanings of these terms have become muddled by their careless use by many authors, which usually had political reasons, i.e. because they somehow considered the words "imperative" or "command" as shameful, they attempted to present their pet languages as purely functional or purely declarative, so they twisted the words in various ways, despite the fact that any practical program must contain imperative parts, not only functional or declarative parts.


Replies

da_chickenyesterday at 7:48 PM

> Anything that causes a persistent change of the state of a system is imperative, regardless of how detailed the command is.

No. That's more to do with imperative vs functional programming, which is a subset of declarative, but even then you can't simply say "I changed state so it's imperative." That's a drastic oversimplification. That's like saying Haskell can't write to a file, which is plainly false. Declarative (functional) can absolutely change the state of the system. It just doesn't let you do it except by calling fixed commands, which is exactly what `INSERT` is.

When we're talking about imperative vs declarative, state can still be manipulated in both, but it's abstracted away with declarative programming. Like, a `filter()` or a `map()` transform in JavaScript is declarative programming, even in an otherwise imperative language. That's why it returns a new object with an updated state.