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.

A Coder
  • 1,343
  • 2
  • 9
  • 17
  • 6
    Erlang and prolog use fullstops. – Dave Clarke Mar 13 '12 at 16:49
  • 13
    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
  • 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." – Ryan C. Thompson Mar 13 '12 at 19:47
  • 22
    Your question doesn’t go far enough. The real question is, “why any symbol at all?” – Konrad Rudolph Mar 14 '12 at 10:09
  • LISP uses semicolons to denote comments. – schellack Mar 14 '12 at 14:16
  • More on semicolons: http://abstrusegoose.com/445 – Manishearth Mar 15 '12 at 02:53
  • 5
    Because it's on the home row of a qwerty keyboard? – wim Mar 15 '12 at 06:38
  • 4
    I doubt there was a 14-hour marathon lock-in meeting with transparencies and multiple vendors to agree on the solution. Someone just did it and it stuck, simple as that. I'm with Ryan. Also if somebody answers "does it even matter" I will be tempted to upvote it. There's been a few history-related questions I've seen here lately and frankly I think these are all accidents of the past. – jasonk Mar 15 '12 at 11:32
  • 1
    If statements were terminated by another symbol, say `§`, would it have prevented you from asking a similar question? – mouviciel Mar 16 '12 at 12:08
  • 2
    @wim: In some keyboard layouts only. My Spanish keyboard has it in the bottom row, and needs Shift. – CesarGon Mar 16 '12 at 13:00
  • I have closed this question based on the quality of answers, comments on the question, and moderator flags to prevent further answers pending a discussion on our [Meta site](http://meta.programmers.stackexchange.com/questions/3325/is-the-question-about-statements-being-terminated-by-semicolons-appropriate-for). – Thomas Owens Mar 16 '12 at 13:02
  • 4
    @ACoder May I ask what's the point of the bounty? "The current answers do not contain enough detail." makes little sense, most of the answers are extremely detailed. – yannis Mar 28 '12 at 10:31
  • 3
    @CesarGon, I second your comment! When switching from a German to an English keyboard, suddenly the have use of ; [ and { made sense, as they were not hard to access anymore at all. I think, most of them are chosen for practical reasons. (Accidently up-and-down-voted you, so I can't up you anymore.) – Amelse Etomer Apr 13 '12 at 05:07
  • @RyanThompson Fortran and Cobol don't use semicolons, so the punch cards are unlikely to be the reason. – gnasher729 Jul 01 '18 at 12:06

14 Answers14

134

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.

uɐɪ
  • 3,001
  • 1
  • 16
  • 17
  • 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 Mar 13 '12 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 Mar 13 '12 at 14:48
  • 13
    Critical information about semicolons: http://theoatmeal.com/comics/semicolon – Ed James 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
  • If you are basing it on English then "." fullstop would be more logical but would probably cause confusion with a decimal point – Martin Beckett Mar 13 '12 at 18:35
  • 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 :) – Travis Christian Mar 13 '12 at 19:38
  • 2
    Hmm, perhaps they should add a "Migrate comments thread to english.se" button to programmers.se? – Rich Mar 14 '12 at 08:02
  • @Travis Christian - Semicolon added :) – uɐɪ Mar 14 '12 at 09:50
  • @Brandon I think what I was trying to say was that the use of the semi-colon in programming is more to do with separating out statements rather than for it's use in a list; for the most part a comma would be used. I'm not sure if my use is more common or not, I wouldn't be able to say, but it's certainly a rare case where you'd need to use a semi-colon to define a list. At least the programming semi-colon is used to define statements not lists. – alex.p Mar 14 '12 at 10:14
  • In English; the semicolon is more often used; to just make; one; look; smarter. – Manishearth Mar 14 '12 at 10:19
  • @alex.p yes that makes sense now. I would agree that your example is far more similar to how we use semi-colons in code, since he was separating noun phrases, and in code there is generally some(thing at least analogous to a) verb. Point well taken. – iconoclast Mar 14 '12 at 22:55
  • @alex.p Even in your example, the part after your semicolon is not a "working sentence". – user253751 Oct 16 '15 at 06:35
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.

Oded
  • 53,326
  • 19
  • 166
  • 181
  • Check the correct answer for this question: http://stackoverflow.com/questions/6464436/what-is-semicolon-in-c – c0da Mar 13 '12 at 09:47
  • @c0da - You have linked to the correct answer to a _different_ question (that question asks what the `;` means in C++, this question asks _why_ the semicolon character was used for the function). – Oded Mar 13 '12 at 09:49
  • 8
    C just followed the convention of using semicolons as used by its predecessor 'B' – Crollster Mar 13 '12 at 09:54
  • @Oded I knew that the question was about C++... But isn't the ; a sort of punctuator in c as well? It goes with what you answered: to indicate spearate statements. – c0da Mar 13 '12 at 09:54
  • @c0da - My point is that the linked questions is about _what_ it means (in the language), this one is about _why_ it was used. – Oded Mar 13 '12 at 10:01
  • Ahh... I was confused when you write the word **function**... :) – c0da Mar 13 '12 at 10:22
  • 8
    B just followed the convention of using semicolons as used by its predecessor 'PL/I' :) – Skomski Mar 13 '12 at 12:03
  • 15
    @Skomski - Which followed what? I am waiting for that last turtle to come in ;) – Oded Mar 13 '12 at 12:10
  • 1
    The most important thing to note is that the semicolon actually came from BCPL -- where it was only required between statements on a single line. It was optional at the end of a line (a change implemented in B). So when it was first chosen, its use was almost exactly analogous to its use in English. – Plutor Mar 13 '12 at 12:45
  • 26
    -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
  • 4
    Is there any evidence that perhaps the semi-colon's convenient position on QWERTY layout keyboards contributed to its common use? – Chris Bye Mar 13 '12 at 14:15
  • 13
    @Oded - I think you'll find it's [Turtles all the way down](http://en.wikipedia.org/wiki/Turtles_all_the_way_down). *8') – Mark Booth Mar 13 '12 at 14:15
  • 3
    @MarkBooth - Aye, indeed what I was referring to. – Oded Mar 13 '12 at 14:16
  • @Oded - I know, I was helping inform others who may not have read [Gödel, Escher, Bach](http://en.wikipedia.org/wiki/G%C3%B6del,_Escher,_Bach) (where I first saw this, having never read [A Brief History of Time](http://en.wikipedia.org/wiki/A_Brief_History_of_Time), which I really should get around to). – Mark Booth Mar 13 '12 at 14:19
  • 2
    +1 this is the correct reason. Regardless of *why* C chose to use semicolons, the reason many other languages use semicolon separators is because they're based (sometimes loosely) on C. – BlueRaja - Danny Pflughoeft Mar 13 '12 at 14:22
  • 7
    In the beginning there were only semi-colons, and the major invention was to add programming language statements in their midst. :) – Ricky Clarkson Mar 14 '12 at 16:36
  • @ChrisBye: The placement of the semicolon is standard on modern keyboards, but I don't think that was necessarily true when the languages that use them were first designed. – supercat Feb 15 '14 at 23:09
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.

John R. Strohm
  • 18,043
  • 5
  • 46
  • 56
  • 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
  • 2
    [Algol 58](http://www.softwarepreservation.org/projects/ALGOL/standards/#ALGOL_58_report), 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
  • I used BCPL starting in 1974 and worked on a BCPL compiler. The compiler would insert semicolons at line breaks if insertion would make the statements parse properly. There's plenty of mention of this on the web. BCPL had many syntactic niceties which were unfortunately not carried forward into its successors. – Dan Halbert Mar 13 '12 at 19:35
  • 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
  • 1
    +1 - and LOL: "LISP didn't use anything, relying on parentheses for everything." – yati sagade Mar 15 '12 at 11:41
  • "Less well thought-out" Have you attempted to write an application in Pascal or Ada? Is there a Pascal or Ada application in common use? – kevin cline Jun 24 '12 at 21:28
  • 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. – John R. Strohm Jun 25 '12 at 15:26
  • 1
    `LISP didn't use anything, relying on parentheses for everything.` You know this is self contradictory, right? LISP *does* use something: closing parentheses. – Thomas Eding Aug 13 '13 at 21:06
  • 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. – Mason Wheeler Jan 09 '16 at 11:24
  • 2
    @kevincline: While I'm thinking about it, a few years later: Texas Instruments DSEG (now part of Raytheon) had a group that did 6DOF simulation. Traditionally, 6DOF sims were written in FORTRAN. About the time I joined TI DSEG, they decided to try writing our project's sim in PASCAL, to see how bad the performance hit was. Their report: They took a few percent hit, but the readability and maintainability improvement was so dramatic that they were NEVER going back to FORTRAN for sims. – John R. Strohm Jan 09 '16 at 18:22
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.

Jerry Coffin
  • 44,385
  • 5
  • 89
  • 162
  • 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
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.]

Uday Reddy
  • 297
  • 1
  • 9
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.

Ryathal
  • 13,317
  • 1
  • 33
  • 48
  • 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
  • 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: https://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
  • @SilverbackNet which is why "pure guess work" probably shouldn't be the basis of an answer here. – user1717828 Jan 09 '16 at 16:17
  • Multiple keys? Guess you just disqualified () for function calls, which should be [] instead. – user253751 Nov 05 '20 at 11:18
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.

dan04
  • 3,748
  • 1
  • 24
  • 26
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!”

Rinzwind
  • 411
  • 3
  • 8
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.

James Anderson
  • 18,049
  • 1
  • 42
  • 72
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.

iconoclast
  • 204
  • 1
  • 8
Fake Name
  • 464
  • 1
  • 3
  • 11
  • 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
  • @John R. Strohm - Frankly, I wish they had maintained the use of an explicit *line continuation*, rather then an explicit line ending. – Fake Name Mar 13 '12 at 21:14
  • 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
  • @JohnR.Strohm: Actually, FORTRAN terminated statements at column 72. Columns 73-80 were reserved for sequence numbers. – TMN Mar 14 '12 at 23:55
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.

Gangnus
  • 2,805
  • 4
  • 21
  • 31
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.

BarbaraKwarc
  • 111
  • 4
-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).

AProgrammer
  • 10,404
  • 1
  • 30
  • 45
-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.

gnat
  • 21,442
  • 29
  • 112
  • 288
Basav
  • 111
  • 4