On the Origin of “Hello, World!”

How one of programming’s oldest traditions began

Ozaner Hansha
4 min readJul 10, 2018

What is Hello World?

If you know even a sliver of computer science, you’ve probably heard of it before. When learning to program for the first time, students are often instructed to write a program that outputs the string "Hello, World!". While its explicit purpose is to verify that their programming environment is set up correctly, it’s really done to give aspiring programmers something to latch onto and call their own.

Since the first “Hello, World!” program was written in 1972, it’s become a tradition amongst computer science teachers and professors to introduce the topic of programming with this example. As a result, “Hello, World!” is often the first program most people write.

History

Why and how outputting the string “Hello, World!” became the quintessential beginner program is a matter of interest for both computer scientists and historians alike, due to the prevalence of this practice in computer science education today.

I complied the following notes in trying to answer this question and thought I would share them, as many resources on the topic are either incomplete or contradictory.

Brian Kernighan at the Univ. of Maryland (1982)

The program was first written by Professor Brian Kernighan during his time at Bell Labs., where he used it as an example in his documentation of the B and C programming languages. Below, we delve into more detail and present the first 3 appearances of the example in programming literature:

1) A Tutorial Introduction to the Language B

B is a programming language developed at Bell Labs around 1969 and is a simplified successor to an even older language called BCPL. It was in 1972 that Kernighan was tasked with writing a manual for using B that was to be used internally at Bell Labs. This memorandum, titled A Tutorial Introduction to the Language B, is the first documented instance of “Hello, World!” in all of programming cannon.

The program appears in section 7 — External Variables in the following form to demonstrate the piecing together of several char variables:

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

It appears again in the next section, 8 — Functions, to demonstrate the composition of functions:

main( ) {
extrn a,b,c,d;
put2char(a,b) ;
put2char(c,d) ;
}
put2char(x,y) {
putchar(x);
putchar(y);
}
a ’hell’; b ’o, w’; c ’orld’; d ’!*n’;

2) Programming in C: A Tutorial

The next instance of “Hello, World!” appeared in another internal memorandum at Bell Labs titled Programming in C: A Tutorial. The document was again authored by Prof. Kernighan and was for the programming language C, developed between 1969 and 1973 by Dennis Ritchie.

The program is the first code seen in the document, appearing in section 2 — A Simple C Program:

main( ) {
printf(“hello, world”);
}

3) The C Programming Language

While the above instances of “Hello, World!” came first, it wasn’t until Kernighan and Ritchie published their famous book The C Programming Language, in 1978 that the example program would catch on. It first appears in section 1.1 — Getting Started:

#include <stdio.h>main()
{
printf(“hello, world\n”);
}

The #include statement in the first line was added to the second edition of the book and is not present in the first.

Another example appears later in the section, but split up to demonstrate the use of the \n escape sequence:

#include <stdio.h>main()
{
printf(“hello, “);
printf(“world”);
printf(“\n”);
}

Again, the first edition doesn’t include the #include statement.

Indeed the book, often abbreviated K&R for its authors, remains a cornerstone of programming literature even today. It should be no surprise then, that the practice of using “Hello, World!” as a test program for beginners would originate from it.

Side note on BCPL

Several sources on the internet claim that Prof. Kernighan first wrote the “Hello, World!” program in his documentation of the Basic Combined Programming Language (BCPL) at Bell Labs before he wrote it for the B tutorial. This however is untrue. Unsure myself of whether the first documented use of “Hello, World!” was in BCPL or B, I emailed Prof. Kernighan and he confirmed it:

I have never written a line of BCPL, so I definitely never wrote a hello world example for BCPL documentation. As best I can recall, the original example was for the internal B manual that I wrote at Bell Labs…

Examples

Below are 3 examples of “Hello, World!” programs in Java, Python, and C++ respectively. You can find many more examples of it for different languages at the Hello World Collection website.

Java

public class HelloWorld {
public static void main(String[] args) {
System.out.println(“Hello, World!”)
}
}

Java is a class based, object oriented language. Because of this we must first define a HelloWorld object class with a main() method. Here we can call the println() method to output the string ”Hello, World!”.

Python

print(“Hello, World!”)

In Python, programs are often just a list of commands run from beginning to end. As such, its “Hello, World!” program contains no boilerplate code and is simply a print() statement.

C++

#include <iostream>int main() {
std::cout << “Hello, World!”;
return 0;
}

All C++ programs start by executing the main() function. Here we can print out the desired string to the standard character output device, std::cout.

--

--

Ozaner Hansha

Interested in Machine Learning, Math, Quantum Computing, Philosophy, etc. My projects/notes are on https://ozaner.github.io