Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The term "clause" in the context of programming

I've come across statements such as "the default clause" in the context of a switch statement or "the JOIN clause" in the context of SQL and I know what these statements mean but still I'd like to see a clear definition of the term.

like image 625
Emanuil Rusev Avatar asked Feb 02 '11 17:02

Emanuil Rusev


People also ask

What is a clause in programming?

Clause. A disjunction of one or more literals. In Prolog, it is a unit of information in a Prolog program ending with a full stop. A clause may be a fact or a rule.

What is a term programming?

Definition of programming 1 : the planning, scheduling, or performing of a program. 2a : the process of instructing or learning by means of an instructional program. b : the process of preparing an instructional program for a device (such as a computer)


2 Answers

It's pretty much the same as in English (or another language). A clause is an incomplete fragment of a sentence, or in this case a statement, that encapsulates an actor and an action. In your example of a join clause, the action is the join and the actor is the table being joined.

like image 129
tvanfosson Avatar answered Sep 28 '22 09:09

tvanfosson


I think that there is a parallel between a sentence and a dependent clause in natural languages and between a statement and a clause in computer languages.

A clause does not stand by itself, but only makes sense within the context of a statement.

For example, the clauses

  • "at 2:30" (adverbial clause)
  • WHERE A.ID = B.ID (JOIN clause)

don't stand meaningfully on their own. However, those clauses make sense in the context of a sentence or statement.

  • "Meet me at 2:30."
  • SELECT A.NAME, B.ADDRESS FROM A, B WHERE A.ID = B.ID

A default clause in a switch statement of Java refers to the branch that is taken if none of the checked values match. The word "default" is somewhat problematic, as it usually means a failure of some sort (as in, "Your mortgage is in default"). With computer languages, it tends to mean "the unchosen choice."

It is a "clause" because it makes sense only in the context of other choices.

like image 24
rajah9 Avatar answered Sep 28 '22 08:09

rajah9