The following English sentences have different forms (syntax):

  • Declarative: You are my friend.
  • Interrogative: Are you my friend?
  • Imperative: Be my friend!
  • Exclamative: What a good friend you are!

They also have different meanings (semantics):

  • Statement: You are my friend.
  • Question: Are you my friend?
  • Command: Be my friend!
  • Exclamation: What a good friend you are!

The form and meaning of a sentence usually match, but not always, as professor of English linguistics Bas Aarts explained:

Incidentally, you might be interested to know that sometimes we have a mismatch between the structure of a sentence, and how it is used. If I say to you at dinner Can you pass me the salt? then this is technically a question that has ‘yes’ or ‘no’ as possible answers, but in fact the pattern is used here to tell you to do something. It’s because of these possible mismatches that linguists prefer to use two sets of terms to describe the phenomena above. For the sentence patterns they use declarative, interrogative, imperative and exclamative. Corresponding to this are statement, question, command and exclamation to describe how these patterns are used.

The grammars of human languages such as English are flexible enough to allow the four forms of sentences (declarative, interrogative, imperative, and exclamative). I wonder if this also holds true for computer languages such as Python, HTTP, SQL, HTML, and CSS.

Are the following sentences declarative? (This seems to exclude HTTP and SQL.)

  • Python: assert x == 3
  • HTTP: ?
  • SQL: ?
  • HTML: <!DOCTYPE html><html lang=""><title>x</title>
  • CSS: h1 { font-size: 3rem; }

Are the following sentences interrogative? (This seems to exclude HTML and CSS.)

  • Python: x == 3
  • HTTP: GET / HTTP/1.1\r\nHost: domain.org
  • SQL: SELECT x FROM relation;
  • HTML: ?
  • CSS: ?

Are the following sentences imperative? (This seems to exclude HTML and CSS.)

  • Python: x = 3
  • HTTP: PUT / HTTP/1.1\r\nHost: domain.org\r\n\r\n{"x": 3}
  • SQL: INSERT INTO relation (x) VALUES (3);
  • HTML: ?
  • CSS: ?

Are the following sentences exclamative? (This seems to exclude all languages.)

  • Python: ?
  • HTTP: ?
  • SQL: ?
  • HTML: ?
  • CSS: ?

If that is so, it means that Python is the most flexible computer language (declarative, interrogative, and imperative), followed by HTTP and SQL (interrogative and imperative), and HTML and CSS are the least flexible (only declarative).

  • $\begingroup$ This sounds like a matter of opinion. How would you define precisely what declarative, interrogative, imperative, exclamative means for a programming language? It sounds like you're trying to draw an analogy, inviting us to extend a loosely-defined analogy, and then apply it. That doesn't sound like a technical question about computer science -- it sounds like an invitation to speculation about what kinds of analogies might feel right to different people. $\endgroup$
    – D.W.
    Jul 20 '21 at 18:48
  • $\begingroup$ @D.W. In linguistics, declarative form usually means a statement, interrogative form a question, imperative form a command, and exclamative form an exclamation. On Wikipedia Python is classified as both declarative and imperative, and SQL and HTML as declarative. I am trying to understand why. $\endgroup$
    – Maggyero
    Jul 20 '21 at 22:27
  • $\begingroup$ Computer programming languages are not natural language, despite using the word "language" in both cases. It's not clear what the definition of "statement" or "question" or "command" or "exclamation" should be in the context of a computer programming language. $\endgroup$
    – D.W.
    Jul 20 '21 at 23:59
  • 1
    $\begingroup$ I would argue that the closest thing to exclamations in a programming language are comments, which have no expected response from the receiver but allow the communicator to express themselves. but I agree that the analogy is unclear $\endgroup$
    – Silver
    Jul 21 '21 at 9:59
  • $\begingroup$ @Silver Interesting analogy! $\endgroup$
    – Maggyero
    Jul 21 '21 at 10:10

The grammatical classification of the sentence types you're asking about isn't well-defined for programming languages because they refer to common ways humans respond to being talked to, which don't apply closely to computers.

The declarative, interrogative, imperative and exclamative grammatical forms are so named because those are the purposes to which they are usually put by people using them. An interrogative form may often carry a connotation that its content is a question, but compared to programming languages the semantics of natural language are so vastly complex that it's difficult to assign a singular meaning to any syntactic property of sentences.

Statements of programming languages on the other hand are generally held to have specifically identifiable meanings, ie. the machine instructions that are executed as a result of entering them. But if the Church-Turing thesis is to be believed, there is some possible computer whose behaviour (in terms of input-output) is the same as any given human mind's, and for that computer there is an exact mapping of natural language inputs to machine instructions*. So why do we not say that natural languages are programming languages for brains? Because it may be true that speaking to someone is an attempt to use the effect of language to change how they act, but people are too complex for that to be a useful way of looking at it. You may as well try to describe the growth of a plant in terms of the subatomic particles that make it up.

A computer on the other hand is simple enough to be predictable. When you 'speak to' a computer, you know with considerable accuracy (maybe total exactness if you happen to be an expert on a particularly simple system) what effect that will have on the 'listener', and so have near-total control over what the 'listener' 'thinks'. If communication is violence, programming is premeditated murder.

*Accounting for the fact that successive inputs can change state. This is true of computers as well, it just happens that the changes are limited and predictable and there are convenient ways to reset to a known state.

  • $\begingroup$ Thanks. But in the computer language sense given in the Wikipedia article Programming paradigm, is assignment (e.g. x = 3 in Python, PUT / HTTP/1.1\r\nHost: domain.org\r\n\r\n{"x": 3} in HTTP, or UPDATE relation SET value = 3 WHERE key = 'x'; in SQL) declarative or imperative? $\endgroup$
    – Maggyero
    Jul 21 '21 at 10:06
  • 2
    $\begingroup$ @Maggyero I think it's still a question of user intent which category it's best to put them in, rather than inherent to the language. If you say 'x = 1' and mean 'x is equal to 1, act accordingly' then it's declarative, but if you say 'x = 1' and mean 'now put 1 in the notional box marked x' or even 'now write 1 to the section of memory x is the name of', then it's imperative. Even in the programming language sense of the words, imperative and declarative are ways to help humans think about what programs mean rather than measurable properties $\endgroup$
    – Silver
    Jul 21 '21 at 10:23

I see the misconception. We have a name collision, where the same word is used to mean two different things in two different contexts.

When Wikipedia says that SQL is a declarative programming language, that has little or nothing to do with the notion of a declarative sentence in English / natural language. Despite both appearing to use the same word "declarative", the meaning of "declarative" is entirely different in these two contexts.

In computer science, we make a loose distinction between declarative programming languages vs imperative programming languages. In a declarative programming language, the programmer specifies what should be accomplished (the goal) without specifying how to achieve it. In an imperative programming language, the programmer specifies how to achieve it. It would be like the difference between saying "Give me a 1-pound cake that is round and tastes like chocolate" vs "Mix 1 cup flour, 2 eggs, 1 cup sugar, 1/2 cup cocoa powder, etc., cook in oven at 350 degrees, etc. etc.".

The word "language" is another of these that might cause problems. While we use the word "language" to describe both a programming language (like Python) and a natural language (like English), the analogy between those two is a bit loose, and I encourage you to not put too much weight on it. Computer programming languages have some similarities, but also many differences, from human natural languages.

  • $\begingroup$ Thanks. On the Wikipedia page Programming paradigms, declarative is defined as a paradigm ‘in which the programmer merely declares properties of the desired result, but not how to compute it’, and imperative as a paradigm ‘in which the programmer instructs the machine how to change its state’. This looks very similar to the definitions for natural languages where declarative is defined as a sentence stating something and imperative as a sentence commanding something. $\endgroup$
    – Maggyero
    Jul 21 '21 at 8:42
  • $\begingroup$ Let’s ignore exclamative and interrogative sentences for a moment and focus on declarative and imperative sentences, as they are defined in both natural languages and computer languages. Is assignment (e.g. x = 3 in Python, PUT / HTTP/1.1\r\nHost: domain.org\r\n\r\n{"x": 3} in HTTP, or UPDATE relation SET value = 3 WHERE key = 'x'; in SQL) a declarative sentence or an imperative sentence (in the natural language or computer language sense, I don’t mind)? $\endgroup$
    – Maggyero
    Jul 21 '21 at 9:23
  • $\begingroup$ @Maggyero, neither - there is no definition or notion of "declarative sentence" or "imperative sentence" for individual statements written in a computer programming language. $\endgroup$
    – D.W.
    Jul 21 '21 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.