136

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.

14
  • 6
    Erlang and prolog use fullstops. Commented Mar 13, 2012 at 16:49
  • 13
    I wonder how many programming languages do you know. There are lots of languages that do not use semicolons.
    – knivil
    Commented Mar 13, 2012 at 18:35
  • 51
    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." Commented Mar 13, 2012 at 19:47
  • 22
    Your question doesn’t go far enough. The real question is, “why any symbol at all?” Commented Mar 14, 2012 at 10:09
  • 5
    Because it's on the home row of a qwerty keyboard?
    – wim
    Commented Mar 15, 2012 at 6:38

14 Answers 14

134
+50

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.

12
  • 19
    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
    Commented Mar 13, 2012 at 13:53
  • 40
    @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
    Commented Mar 13, 2012 at 14:48
  • 13
    Critical information about semicolons: theoatmeal.com/comics/semicolon
    – Ed James
    Commented Mar 13, 2012 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
    Commented Mar 13, 2012 at 18:01
  • 18
    @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 :) Commented Mar 13, 2012 at 19:38
71

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.

17
  • 8
    C just followed the convention of using semicolons as used by its predecessor 'B'
    – Crollster
    Commented Mar 13, 2012 at 9:54
  • 8
    B just followed the convention of using semicolons as used by its predecessor 'PL/I' :)
    – Skomski
    Commented Mar 13, 2012 at 12:03
  • 15
    @Skomski - Which followed what? I am waiting for that last turtle to come in ;)
    – Oded
    Commented Mar 13, 2012 at 12:10
  • 27
    -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
    Commented Mar 13, 2012 at 12:59
  • 13
    @Oded - I think you'll find it's Turtles all the way down. *8')
    – Mark Booth
    Commented Mar 13, 2012 at 14:15
55

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.

11
  • 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
    Commented Mar 13, 2012 at 15:29
  • 2
    +1 for "considerably less well-thought-out than PASCAL and Ada"
    – Aditya
    Commented Mar 13, 2012 at 18:30
  • 2
    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. Commented Mar 13, 2012 at 19:27
  • 6
    @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. Commented Jun 25, 2012 at 15:26
  • 2
    @kevincline Skype: written in Delphi (Pascal.) Microsoft attempted to change this after they acquired it, but they couldn't port it successfully, so now they're buying Delphi licenses. Ever watch TV in the US? The station probably runs on software by WideOrbit, written in Delphi; they're the market leader by a huge margin. Ever been to a theme park? There's a good chance the ticketing system was written in Delphi. Pascal is all over the place; it's just that it provides such a strong competitive advantage that a lot of people try to keep quiet about it so their competitors don't find out. Commented Jan 9, 2016 at 11:24
14

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.

3
  • 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
    Commented Mar 13, 2012 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. Commented Mar 13, 2012 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. Commented Mar 29, 2012 at 14:32
7

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.]

6

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.

6
  • 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
    Commented Mar 13, 2012 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). Commented Mar 13, 2012 at 19:30
  • @JohnR.Strohm well that is news to me, but all this is pretty much ancient history to me
    – Ryathal
    Commented Mar 13, 2012 at 20:16
  • 6
    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. Commented Mar 13, 2012 at 22:52
  • @SilverbackNet which is why "pure guess work" probably shouldn't be the basis of an answer here. Commented Jan 9, 2016 at 16:17
6

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.

3

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

2

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.

1

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.

7
  • 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.) Commented Mar 13, 2012 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
    Commented Mar 13, 2012 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
    Commented Mar 13, 2012 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. Commented Mar 13, 2012 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
    Commented Mar 14, 2012 at 13:30
0

Here are two questions: Why ALGOL got semicolon and why other languages went after it.

The first question is already answered in many ways here.

As the second one, The ALGOL was very widely used as a pseudocode language for algorithms writing. So, semicolons soon became natural for users of different languages. And naturally they were taken for the younger languages.

0

I might be wrong, but I think this has something to do with the fact that in many assemblers a semicolon was used to start a comment, usually put after an instruction. Everything after a ; was a comment, and no longer a part of the instruction itself.

Then there is a need to terminate instructions when you're typing them in an interpreter. Short instructions (e.g. mathematical expressions) could be terminated by simply hitting the Enter key, telling the interpreter that the expression is ready to be calculated and it produced a result. But sometimes one wanted to input multiple lines of code for the instruction, so one way to achieve that was to use some special character as a terminator of the instruction instead of depending on just the Enter key. This way, the user could enter more lines of code at once, because Enter didn't send it to the interpreter yet. Only when the interpreter found the terminating character in a line entered with Enter, it would finally execute it and calculate its result.

Now combine these two things together, and the semicolon appears to be an obvious choice for the terminating character: it tells where the instruction part ends and the comment part starts, so when the interpreter encounters it in a line, it knows that it can flush all the lines of the expression it buffered so far and execute it, because the instruction has just ended, now we're in a comment (well, at least up to the end of this line, because the next line will start in the code mode again, starting a new expression/instruction).

This assumes, of course, that it was really the semicolon that has been used for comments by the person who come up with this idea of reusing it as instruction terminators. Having it been any other character, we might have ended up with a different instruction terminator.

Inb4: No, this is not a historical account. I don't have any evidence that this is the actual way semicolons came to life. It's just how I imagine it might have possibly happened.

-1

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).

-1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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