Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Is there a reason that a semi-colon was chosen as a line terminator instead of a different symbol?

I want to know the history behind this decision, and hope the answers will lead to insights that may influence future decisions.

share|improve this question

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

5  
Erlang and prolog use fullstops. –  Dave Clarke Mar 13 '12 at 16:49
11  
I wonder how many programming languages do you know. There are lots of languages that do not use semicolons. –  knivil Mar 13 '12 at 18:35
34  
I'll bet the answer will turn out to be something like "the ASCII value of the semicolon is particularly durable when used as the last character on an 80-character punch-card." –  Ryan Thompson Mar 13 '12 at 19:47
14  
Your question doesn’t go far enough. The real question is, “why any symbol at all?” –  Konrad Rudolph Mar 14 '12 at 10:09
5  
Because it's on the home row of a qwerty keyboard? –  wim Mar 15 '12 at 6:38
show 8 more comments

12 Answers

It's largely an arbitrary choice. Some languages have made other choices. COBOL terminates statements with the . character. FORTRAN, BASIC, and Python generally terminate statements with newlines (with special syntax for multi-line statements). And Lisp brackets its statements with parentheses.

The main reason ; is so popular as a statement separator/terminator is that most of today's popular languages are based on ALGOL, which used that convention.

instead of a different symbol?

What other symbol could you pick?

The ASCII characters #$@[]^_`{|}~ weren't always present in early character encodings like ISO 646.

The characters ()*+-/<=> are typically used as mathematical operators and would create parsing ambiguities if used as statement terminators.

product = a * b *  // If '*' were a statement terminator,
c * d *            // Are there two factors, or four?

Similar problems would apply to ' and ", which are typically used as string delimiters; ,, which is typically used to separate function arguments, and ., which is typically used as a decimal point (or as a delimiter in constructs like some_struct.some_field).

That leaves !%&:;?.

Choosing ! or ? probably wouldn't cause technical difficulties, but their English meanings would give the wrong mood to the program.

print(x)?  # Yes, you should.
           # It's an IMPERATIVE language; stop questioning my commands.
print(x)!  # OK!  You don't have to shout!

The & would be a more sensible choice as a statement separator (not terminator), because

do_thing_a() &
do_thing_b()

can be read as a command to do thing A and then do thing B. But most languages with an & operator use it as a logical or bitwise AND instead.

The % sign might cause confusion in statements like interest_rate = 2.99% (which would set the variable to 2.99 instead of the expected 0.0299). Of course, the well-known mathematical meaning of % didn't stop C from using it as the remainder operator.

So that leaves : and ;.

: is a sensible choice, and indeed is used as the intra-line statement separator in most dialects of BASIC.

But ; has English grammar on its side; it can be used to separate clauses within a sentence.

share|improve this answer
add comment

Semicolon was originally proposed in Algol 60 as a statement separator, not a terminator.

Prior to Algol 60, the only high-level programming language in existence was Fortran, which required each statement to be on a separate line. Statements spanning multiple lines, like do-loops, were considered an oddity, and they were regarded as 'statement blocks'.

The designers of Algol 60 realized that statements needed a hierarchical structure (if-then-else, do-loops, case statements etc) and they could be nested inside each other. So, the idea of each statement sitting on a separate line didn't make sense any more. Sequential composition of statements of the form S1; S2; ...; Sn optionally enclosed in begin - end brackets were called compound statements, and fit into the hierarchical structure of statements envisaged by Algol 60. So, here, the semicolon is clearly a statement separator, not a terminator.

This gave rise to problems in practice. Algol 60 also had an "empty statement" which was denoted by writing nothing. So, one could write "begin S1; end" where the semicolon appears as if it is terminating S1. But the Algol 60 compiler really treated it as a separator between S1 and an invisible empty statement following it. These subtleties were a bit much for practical programmers. Having been used to line-oriented languages like Assembly and Fortran, they really thought of semicolon as a terminator for statements. When programs were written out, usually semicolon was put the at the end of the statements, like so:

    a[i] := 0;
    i := i+1

and the semicolon really looked like a terminator for the first statement. If the programmers treated the semicolon as a terminator, then statement like this would give a syntax error:

    if i > 0 then
      a[i] := 0;
    else
      a[i] := 1;

because the semicolon terminates the "if" and, so, the "else" becomes dangling. Programmers were thoroughly confused.

So, PL/I, which was the IBM's successor to line-oriented Fortran, decided to make the semicolon a statement terminator rather than a separator. Programmers were happy with that choice. The majority of programming languages followed suit. (Pascal resisted the trend, but its successor Ada gave up on it.)

[Note added: Wikipedia article on programming language comparisons has a nice table summarizing how semicolon is treated in various programming languages.]

share|improve this answer
add comment

Its about visibility.

Early statement separators were the '.' as in COBOL and new line, carriage return in FORTRAN.

The CR proved limiting in that it makes it difficult to flow a statement over several lines.

Full stop caused a more interesting problem. When you read English text your brain processes the full stops at a subliminal level, you are conscious that a sentence has ended and you can pause for breath but you don't really notice the . that signaled it. Also in many fonts the '.' is the smallest possible character sometimes rendered as a single pixel. Missing or extra periods became the single most common cause of errors in COBOL programs.

So learning from early mistakes ALGOL pick a specific terminator which would allow a statement to flow over several lines, and, picked one that was visible and easily noticed by human readers. The semi-colon being both large and unusual enough in common English not to be processed subconsciously.

share|improve this answer
add comment

Rather than trying to answer your headline question, I think it's better to focus on your implicit question:

I want to know the history behind this decision, and hope the answers will lead to insights that may influence future decisions in the design and implementation of programming languages.

If you want to learn about programming language design and implementation history, and gain more insight into the process, then the proceedings of the History of Programming Languages Conferences are a very good place to start. (I think you will need an ACM membership to be able to access the proceedings though.)

Why are statements in many programming languages terminated by semicolons? Is there a reason that a semi-colon was chosen as a line terminator instead of a different symbol?

Taking your headline question as an example question that you might want to try to answer by reading the HOPL proceedings, I'd like to offer the following point: people designing a new programming language usually do so because they consider the ones they know to be broken / deficient somehow. Their new language is, on one hand, designed to fix this deficiency. On the other hand, language designers will also copy design elements from other languages that they think are good, or they simply don't change those elements that they didn't experience a problem with.

Especially that last part is important: instead of trying to find out which programming language ever was the first one to use semicolons as terminators and why a lot of other programming languages copied that, you will probably learn more by looking at languages that did not copy it. For example, while Smalltalk took a lot of inspiration from Simula, it did not copy its syntax and in particular its use of semicolons as statement terminators. It changed terminators (separators really) to a full stop, and uses the semicolon for something else. Conversely, the first language that ever used a semicolon as a statement terminator may have had a reason to change this from what was used in languages that came before it. It's also possible that it was the first language to introduce the whole concept of a statement terminator (or did so independently of other languages) and that the semicolon was used for some reason that is now lost to time. (I suspect the latter is the case here, as none of the other answerers have been able to dig up a quote from the person who introduced the semicolon rather than offer retrofitted suppositions about why the semicolon was a good choice.) But to restate my point, I think you will learn more by looking at why language designers changed things rather than why they copied/kept them. When people change things they usually want or have to explain the change, while they don't do so when copying or keeping things the same because “why would we change it? that's just the way it's done!”

share|improve this answer
add comment

Another reason why use semicolon is because it is one of the characters which we do not require or use more often.

Assume we use it more often as a variable name or some thing and if semicolon would have been used as a keyword or as a operator, it would have been a symbol conflict for the compiler, hence it was important to use a symbol which is not often used in the coding.

I believe C style programming languages made it popular and then authors of new programming languages do not wanted to reinvent the wheel and they continued using it, till now.

share|improve this answer
add comment

Most languages took the semi-colon because it was already widely in use for that purpose and changing made no sense.

And considering the first languages to make that choice, you'll have to consider what are the alternatives. When designing a language, you want the needed characters to be available, and character sets at this time were coded on 6 bits, often with some patterns reserved, often with some characters not firmly defined (for a later occurrence of this, think about the national variants of ISO-646 -- the US variant is well know under the name ASCII -- which reuse the codes for "common" characters such as [, # or $, and see the effect in a context where there is only half as many code positions available and letters and digits reserving more than half of those).

There was probably no other character which could be used as statement separator as intuitively (. is probably already the only serious contender for that criteria) and without introducing lexing or parsing difficulties at a time when the parsing and lexing theory was still in elaboration (. is now out of question due to its usage in real numbers).

share|improve this answer
add comment

In English the semicolon is used to separate items in a list of statements, for example

She saw three men: Jamie, who came from New Zealand; John, the milkman's son; and George, a gaunt kind of man.

When programming you are separating a number of statements and using a full stop could be easily confused for a decimal point. Using the semicolon provides an easy to parse method of separating the individual program statements while remaining close to normal English punctuation.

Edit to add
In the early days when memory was expensive, processing slow, and the first programming languages were being devised, there was a need to split the program up into separate statements for processing. Some languages required that each statement was placed on a line so that the carriage return could act as the statement delimiter. Other languages allowed a more free format to the text layout and so required a specific delimiter character. This character was chosen to be the semicolon, most likely because of the similarity to its use in the English language (this has to be a supposition; I was not there at the time) and as it did not produce a conflict with the other punctuation marks and symbols that were required for mathematical or other syntactic purposes.

Edit again
The need for some terminator character goes back to the requirements for parsing the language text. The early compilers were written in assembly language or, in some cases, directly in hand crafted binary machine instructions. Having a special character that identified the end of the statement and delimited the chunk of text that is being processed makes the processing that much easier. As I said above, other languages have used the carriage return or brackets. The Algol, Pascal, Ada, BCPL, B, C, PL/M, and other families of languages happen to use the semicolon. As to which one was first to use this particular character, I do not go back far enough in history to remember. Its choice and adoption makes perfect sense as

  • Its use mirrors the use in normal English punctuation.
  • Other characters (e.g. the full stop) could be confusing as they already have a common use (a full stop is also used as a decimal point).
  • A visible punctuation character allows free format code layout.
  • Using a similar delimiter character in derivative or later languages builds upon the familiarity gained by all of the programmers that have used the earlier language.

As a final remark, I think that there has been more time spent on these answers and comments than was spent in deciding to use the semicolon to end a statement when designing the first language that used it in this way.

share|improve this answer
17  
Not entirely correct. The semi colon separates sentences into blocks: each block should be a working sentence but we use the semi-colon to denote that there is a strong link between two sentences. It's half way between a comma and a full stop so it is indeed a stopping point but it links one sentence to the next. The above sentence would be : "She saw three men; Jamie: who came from New Zealand, John: the milkman's son and George: a gaunt kind of man." Your use of the semi-colon could be replaced by a comma. Bit off topic but the gist is essentially the same; it breaks up statements. –  alex.p Mar 13 '12 at 13:53
35  
@alex.p actually an acceptable use of a semicolon is in place of a comma when it would cause a sentence to be confusing, which makes this correct. –  Ryathal Mar 13 '12 at 14:48
13  
Critical information about semicolons: theoatmeal.com/comics/semicolon –  Ed Woodcock Mar 13 '12 at 15:55
7  
@alex.p: It appears that you're saying Ian's use is wrong but you might be simply saying his explanation of how we use semi-colons is incomplete. If you're saying that he's wrong, then you're dead wrong. His use of semi-colons is entirely conventional, and I'd guess a lot more common than the example you give. If you're simply saying he does not give an exhaustive explanation, then I'm not sure why that's really worth even mentioning. –  iconoclast Mar 13 '12 at 18:01
14  
@Ian "this has to be a supposition, I was not there at the time" You missed a perfect opportunity to (correctly) use a semicolon there :) –  Travis Christian Mar 13 '12 at 19:38
show 6 more comments

It was my understanding that it was chosen because there was a need for an explicit statement-terminator other than a carriage-return/new-line. Back in the days of 80-column screens, actually having a single line of code wrap across multiple lines was common enough that using \r or \n for the statement terminator would not work.

Semicolons were just convenient because they're not used in logic/math statements. As such, they don't conflict with the actual content of the statements to any significant extent.


Personally, I think the continuing use of the semicolon, together with style requirements to keep lines under 80 characters, is frankly stupid and anachronistic. Languages like python have extensively demonstrated that you can write easy to understand, concise code more easily without them. Also, if you have issues with lines that are longer then 80 chars, you need a bigger monitor.

share|improve this answer
3  
Back in the Dark Ages, there were no "80-column screens". There were 80-column punched cards, and there were printers with different numbers of columns. (Around 130 or so was common.) FORTRAN terminated statements at the end of the card, but allowed for continuation cards to continue the statement. Continuation cards were marked by a character punched in column 6 of the card. (Any character would work. Depending on local convention, you would typically see either a + sign or a single digit, digits counting up for multiple continuation cards.) –  John R. Strohm Mar 13 '12 at 19:39
1  
A language like Python would have been infeasible for the computers that existed in the early days of C. Using a statement termination character makes the parsing simpler, and it was very important to reduce the memory and CPU load of compilers decades ago. Especially on those computers where you paid for CPU time by the second. –  Gigatron Mar 13 '12 at 20:35
    
@Gigatron - I was referring only to the use of carriage returns to end a statement, not to any of the higher-level aspects of python. –  Fake Name Mar 13 '12 at 21:12
1  
@Gigatron, you might want to take a look at LISP, and especially its early history on the IBM 704. You might be surprised at what the Ancients could do, even working with stone knives and bearskins. –  John R. Strohm Mar 13 '12 at 21:48
1  
@Gigatron: FORTRAN ran on the same computers, and it uses newlines to separate statements (with special syntax for multi-line statements). –  dan04 Mar 14 '12 at 13:30
show 2 more comments

Why not any other symbol?

A few languages have used other symbols -- old versions of BASIC used a colon instead, for one example.

Ignoring the few exceptions, however, I think there are two primary reasons. The first is that you're simply looking for something unambiguous. In a typical parser, if you run into a serious enough error that you can't continue parsing the current statement, you normally try to get the parser back in sync by just skipping ahead to the statement terminator and re-start the parser from the beginning of the next statement. For that, you want something that won't normally occur anywhere else in the code, and a semicolon happens to be a symbol with little other meaning attached, so it's pretty easy to dedicate it to this purpose.

The second reason is somewhat similar, but aimed more toward people reading/using the code. Again, it comes back to the fact that the actual symbol you use doesn't matter much. There's a substantial advantage in readability to gain from using the symbol your reader is accustomed to seeing for a particular purpose, when and if possible. That doesn't mean that C is the one perfect syntax and everything else should follow it slavishly, but it does mean that enough people are familiar with that style of syntax that a vaguely similar language gains a lot (and loses very little) by following roughly the same syntax where it can.

I'd note that this is much like designing almost any other program. If I write a program that uses windows of some sort, I'll try to just use the native features of the target platform(s). Many of the decisions that embodies will be largely arbitrary, and could be done differently without any major loss of functionality -- but equally, changing them without a substantial gain in functionality just confuses users without accomplishing anything useful. The same basic principles apply to "what should terminate (or separate) statements in a language?" as "what should a scroll bar look like", or "how should a tree control work?" In all these cases, the decision is mostly arbitrary, and uniformity provides a substantial benefit in and of itself.

I'd add that much the same happens throughout many languages, just in ways that most of us are so accustomed to before programming that few people think about it. Why does everybody use "+" to indicate addition, or "-" to indicate subtraction? Because the shape of the symbol doesn't matter much, but everybody agreeing to apply the same meaning to each symbol matters a lot.

share|improve this answer
    
Very good points (+1), although I can't quite agree with the "mostly arbitrary" part. I think there are very definitely some things which are more intuitive and others which are less intuitive. In Windows' use of an X to close windows, there is some (perhaps only vaguely connected) pre-existing symbolism that it draws on. And certain in OS X's use of colors there is a strong symbolism that it draws on. (I'm ignoring for the moment that M$ Windows may have stolen the X from X Windows, since I don't recall what that used.) –  iconoclast Mar 13 '12 at 18:12
3  
@Brandon: I certainly didn't intend to say that all parts of GUI design are arbitrary -- perhaps I should have said "some" instead of "most" though. It wouldn't be X that defined any particular shape for the "close window" icon -- that would be up to an individual window manager. –  Jerry Coffin Mar 13 '12 at 18:17
    
To the best of my recollection, the original Dartmouth BASIC only used carriage return to terminate statements (i.e., one statement per line). I THINK multiple statements on a line, separated by colons, was a Microsoft extension. –  John R. Strohm Mar 29 '12 at 14:32
add comment

This is pretty much pure guess work, but looking at a standard QWERTY keyboard restricted to ASCII values the natural characters for termination/separation would be .!?,:; and carriage returns. of those !?: should be immediately disqualified for taking multiple keys and statement termination is going to be a very common thing. Periods would be disqualified because they are easily confused with decimal points which would make them unnecessarily complicated to be a terminator given the limited space of initial computers. carriage returns would be disqualified after lines of code had potential to be longer than what can be shown on a single line on the screen, so it would be more difficult to read a program when lines had to be scrolled horizontally, or require additional characters to create a continuation on the next line which again adds complexity. this leaves , and ; as options, of those , is used much more often in writing compared to ; so the semicolon is chosen because its the easier to type, less confusing because its adding meaning to a character with limited meaning and less complicated because special cases don't really exist with its use.

The semicolon was chosen because it was the best character based on laziness and simplicity.

share|improve this answer
    
you have a good point here; I would only re-word "chosen" (which is difficult to prove) to something like "...The semicolon has won because it was the best character based on laziness and simplicity" –  gnat Mar 13 '12 at 15:22
2  
Hardly. Semicolon as statement terminator/separator started at ALGOL (1958), which predated ASCII (work started 1960, first release 1963, major release 1967, last updated 1986). –  John R. Strohm Mar 13 '12 at 19:30
    
@JohnR.Strohm well that is news to me, but all this is pretty much ancient history to me –  Ryathal Mar 13 '12 at 20:16
5  
This is a great theory, but the reality is that keypunches required a shift key to get to the semicolon anyway until modern keyboard input appeared in the 70's. (There are several good photos near the bottom of the wiki article: en.wikipedia.org/wiki/Keypunch ) It's most likely just based on natural English language rules, a fad that was particularly popular at the same time. (I would include all of the late 50's languages: ALGOL, FORTRAN, COBOL, and SQL, excluding LISP.) ALGOL's semi-colon is only one of many English-language conventions used, which BASIC later expanded on further. –  SilverbackNet Mar 13 '12 at 22:52
add comment

FORTRAN used carriage return to delineate statements. COBOL used period. LISP didn't use anything, relying on parentheses for everything. ALGOL was the first language to use semicolon to separate statements. PASCAL followed ALGOL's lead, using semicolon to separate statements.

PL/I used semicolon to terminate statements. There is a difference, and it is easily seen in PASCAL. Ada followed PL/I's lead on this one item, rather than ALGOL's.

Semicolon as statement separator or terminator was quickly accepted by the computer science community as a useful notation, and, as far as I know, every subsequent block-structured language followed ALGOL's lead and used semicolon to separate or terminate statements.

I was told many years ago that BCPL used both semicolon AND carriage return as statement separators/terminators, but I never used the language myself and am unable to verify this. At some point, the use of carriage return to separate or terminate statements was dropped from the BCPL descendants. BCPL begat B, B begat C, C begat C++, Java, D and a whole host of things considerably less well-thought-out than PASCAL and Ada.

share|improve this answer
2  
It should be noted, that the use of semicolon or newline is reappearing lately. Javascript, Lua, Go and Haskell all have implicit semicolon at newline if it is syntactically valid there. And of course some languages that retained newline as separator. Shell and Python come to mind here. –  Jan Hudec Mar 13 '12 at 15:29
2  
+1 for "considerably less well-thought-out than PASCAL and Ada" –  Aditya Mar 13 '12 at 18:30
1  
Algol 58, a precursor to Algol 60, used semicolons. Note that at the time, distinction was often made between the publication form of a language and the actual input form, because the input devices were quite limited: uppercase only, etc. That dichotomy was not really true of FORTRAN, but was true of a number of other languages. –  Dan Halbert Mar 13 '12 at 19:27
1  
@DanHalbert: Token auto-insertion by the compiler is acceptable only if it transforms a syntactically-incorrect program into a syntactically-correct one. Even then, the risk is that the compiler will "correct" the program to something the programmer didn't want. Review the (probably apocryphal) tale of the Venus probe that almost went bye-bye because FORTRAN didn't have mandatory variable declarations, and some poor keypunch operator hit a period instead of a comma, transforming a DO-loop into a simple assignment statement... –  John R. Strohm Mar 13 '12 at 21:39
4  
@kevincline: Would you consider the Boeing 777 to be in common use? Every line of the avionics software that flies that airplane is written in Ada. –  John R. Strohm Jun 25 '12 at 15:26
show 4 more comments

Many languages use syntax that is modeled after C (which was modeled after B - thanks @Crollster). As can be seen in the comments, there is a long chain of such languages... B was inspired by PL/I, which was preceded by ALGOL at using the ; as a separator.

Since in C the statement terminator is ;, these languages follow suit.

As for why it was selected as a statement terminator in C - possibly because of its use in English "to indicate interdependent statements".

C was also invented on the PDP-11 at a time where there was limited amount of memory available for character sets, so the inventors of the languages had to work within these constraints.

share|improve this answer
8  
C just followed the convention of using semicolons as used by its predecessor 'B' –  Crollster Mar 13 '12 at 9:54
8  
B just followed the convention of using semicolons as used by its predecessor 'PL/I' :) –  Skomski Mar 13 '12 at 12:03
13  
@Skomski - Which followed what? I am waiting for that last turtle to come in ;) –  Oded Mar 13 '12 at 12:10
24  
-1; Come on guys, have we all forgotten the hugely influential ALGOL? It had semicolons as statement separators before everything else you are mentioning. (I don't know if it took the idea from somewhere else though) –  hugomg Mar 13 '12 at 12:59
13  
@Oded - I think you'll find it's Turtles all the way down. *8') –  Mark Booth Mar 13 '12 at 14:15
show 12 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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