120

'hello, world' is usually the first example for any programming language. I've always wondered where this sentence came from and where was it first used.

I've once been told that it was the first sentence ever to be displayed on a computer screen, but I've not been able to find any reference to this.

So my question is:
Where does the practice to use 'hello, world' as the first example for computer languages originate from?
Where was it first used?

Update
Although the answers are quite interesting, I should have noted that I had read the Wikipedia article. It does answer the question about the first use in literature, but does not answer when 'hello world' was first used.
So I think that it is safe to conclude that it was not the first sentence ever to be displayed on a computer screen and that there is no record about when it was first used?

0

7 Answers 7

111

Brian Kernighan actually wrote the first "hello, world" program as part of the documentation for the BCPL programming language developed by Martin Richards. BCPL was used while C was being developed at Bell Labs a few years before the publication of Kernighan and Ritchie's C book in 1972.

enter image description here

As part of the research for a book I was writing about the Alice programming environment, I corresponded with both Prof. Kernighan at Princeton and Martin Richards at Cambridge (when I was teaching a seminar there in the 1990’s). They helped me to track the first documented use of code to print the message "Hello, World!” Brian Kernighan remembered writing the code for part of the I/O section of the BCPL manual. Martin Richards -- who seems to have a treasure trove of notes, old documents, etc. -- found the manual and confirmed that this was the original appearance of the program. The code was used for early testing of the C compiler and made its way into Kernighan and Ritchie's book. Later, it was one of the first programs used to test Bjarne Stroustrup's C++ compiler.

It became a standard for new programmers after it appeared in Kernighan and Ritchie, which is probably the best selling introduction to programming of all time.

8
  • 1
    The C book was not in 1972. The B book was 1972. The The first edition of the C book, was published in 1978 en.wikipedia.org/wiki/The_C_Programming_Language_(book) There was a "a 1974 Bell Laboratories internal memorandum by Brian Kernighan, Programming in C: A Tutorial" en.wikipedia.org/wiki/Hello_world_program
    – barlop
    Jan 19, 2014 at 19:05
  • 1
    There is an I/O section to his 1974 C tutorial though lysator.liu.se/c/bwk-tutor.html printf ("hello, world\n"); and above that, in section 2, without the \n and in a program. main( ) { printf("hello, world"); } Be interesting to see something from B and BCPL.
    – barlop
    Jan 19, 2014 at 19:16
  • 3
    well done for for actually conversing with the man himself, and "confirming" the appearance, found in a "treasure trove of notes" but can you present the actual program in your answer?
    – barlop
    Jan 19, 2014 at 19:31
  • 1
    I found an image on wikipedia, image - en.wikipedia.org/wiki/Computer_program#/media/…. Source page - en.wikipedia.org/wiki/Computer_program
    – Daryn
    Oct 7, 2018 at 17:01
  • 3
    I think you may be mistaken. I was writing an article about the origin of Hello World and, seeing as this answer is the first result on google yet seemed to contradict the BCPL manual, decided to email Prof. Kernighan myself. A fuller response can be found here, but the gist of it was that he first wrote "Hello World" as an example for an internal B manual at Bell Labs. You probably just switched BCPL and B since the latter is a sort of successor to the former. Jan 14, 2019 at 4:48
51

According to wikipedia:

While small test programs existed since the development of programmable computers, the tradition of using the phrase "Hello world!" as a test message was influenced by an example program in the seminal book The C Programming Language. The example program from that book prints "hello, world" (without capital letters or exclamation mark), and was inherited from a 1974 Bell Laboratories internal memorandum by Brian Kernighan, Programming in C: A Tutorial, which contains the first known version:

 main() {
        printf("hello, world");
 }

The first known instance of the usage of the words "hello" and "world" together in computer literature occurred earlier, in Kernighan's 1972 Tutorial Introduction to the Language B[1], with the following code:

main( ) {
  extrn a, b, c;
  putchar(a); putchar(b); putchar(c); putchar('!*n');
}
a 'hell';
b 'o, w';
c 'orld';
1
10

The first C program in the book "The C Programming Language" was to print "hello world!" on the screen.

Since then it is used as the first program to introduce the basic details of a programming language.

7

From http://en.wikipedia.org/wiki/Hello_world_program:

The first known instance of the usage of the words "hello" and "world" together in computer literature occurred earlier, in Kernighan's 1972 Tutorial Introduction to the Language B[1], with the following code:

main( ) {
  extrn a, b, c;
  putchar(a); putchar(b); putchar(c); putchar('!*n');
}
a 'hell';
b 'o, w';
c 'orld';
5

I should have been more careful with language in my original post about this --

Of course Barlop is right, K&R was published in 1978. A coma was missing in my post. I meant that the BCPL manual with Dr. Kernighan's Hello World code was dated 1972. The memorandum with a reference to this is from 1974.

Martin Richards has these documents. I have a bad photocopy of the manual and a copy of the memorandum.

I believe the original had no punctuation.

The BCPL and the B code appeared almost at the same time. I always thought the B code cited by therefromhere came first, but Martin Richards seemed to think the BCPL code was first. In either case, "Hello Word!" predates K&R, and its first documented use in code appears to have been written by Brian Kernighan at Bell Labs.

1

First time I came across it in print was (I think) the first edition of K&R, so tha would have been circa 1982, but I'd been writing my own "Hello world" programs long before that, as had everyone else.

1

From Wikipedia

While small test programs existed since the development of programmable computers, the tradition of using the phrase "Hello world!" as a test message was influenced by an example program in the seminal book The C Programming Language. The example program from that book prints "hello, world" (without capital letters or exclamation mark), and was inherited from a 1974 Bell Laboratories internal memorandum by Brian Kernighan, Programming in C: A Tutorial, which contains the first known version:

http://en.wikipedia.org/wiki/Hello_world_program

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