The History of { Curly Braces }

The History of { Curly Braces }

Pop quiz! What do C, Python, Ruby, Go, Java, PHP, Oz, D++, Rust, and Perl have in common?

The answer? They all use curly braces to group statements, but { } weren’t always the symbol of choice. When I learned to program, there was no symbol at all.

FORTRAN GOTO

My first programming language was FORTRAN, and it didn’t have braces—it didn’t know how to group statements at all. Each line stood alone.

If a line said “A = A + 1” the FORTRAN compiler generated code to do just that.

If a statement said “DIMENSION A(12),” the compiler would make a note and, after all the executable code was laid down, emit space for the array.

The statement “SUBROUTINE FOO(I1, I2, I3)” would produce the entry prolog for passing variables.

Instead of groupings, FORTRAN used the infamous GOTO statement to jump around code. (Actually, FORTRAN deleted spaces within a line, so GO TO or even G O T O would have done the trick.)

The bit of FORTRAN on the left is in C to the right:

Here’s the classic if-then-else sequence:

GOTO just seemed natural to us assembly language programmers.

COBOL.

The contemporary language COBOL is different because it was originally intended to be a programming language for non-programmers, a failed goal that many technologies have aspired to over the years, such as 4GL languages, database management systems in general, and SQL in particular.

COBOL, interestingly, can be compiled with simple pattern matching because its syntax contains no recursive definition. It was designed to be English-like (for some definitions of English anyway).

So, COBOL had statement grouping. Well, sort of. COBOL had half a grouping.

For example, the syntax for an if statement was
     IF I IS EQUAL TO 4 THEN
     MOVE 1 TO B
     MOVE 2 TO C
     ELSE
     MOVE 2 TO B
     MOVE 3 TO C.

The final period closed the IF-THEN-ELSE sequence. (Later, COBOL added a END-IF.)

BEGIN ALGOL END

ALGOL first had the idea of using keywords to group statement, which gave birth to the compound statement.

The IF statement had the syntax of
     IF relational THEN statement

In place of the “statement” you could insert multiple statements enclosed in the two keywords BEGIN and END. In fact, the body of functions themselves were mandatorily sandwiched between those two keywords.

DO PL/I END

The IBM language PL/I was a melting pot of ideas from COBOL, FORTRAN, and ALGOL. It used the keyword DO instead of BEGIN but picked up all the interesting ideas from ALGOL.

(I’m typing BEGIN, DO, and END in uppercase for a reason. These languages were designed for punch cards, which, for the most part, were limited to upper case, as were all the early timeshare systems. The CDC machines, for example, used display code to represent a character. This crammed everything—letters, digits, punctuation, all of it— into a six-bit character. With only 64 combinations, there was no room for lowercase.)

$( BCPL $)

A consequential change happened in Cambridge, UK. For his doctorate thesis, Martin Richards designed a very low level programming language, intending for it to be used to compile a larger, higher level language: the Combined Programming Language (CPL).

Cambridge University was going to implement CPL, an ALGOL like language, in cooperation with London University, hence the name “combined.” Others have wondered if the C stands for Cambridge.

Whatever the case, Richards designed a simplified basic language: Basic Combined Programing Language (BCPL). For this, he specified special symbols to create compound statements instead of using the larger BEGIN and END. The specification used a unusual “section” symbol, the closing instance being underlined. In his book, and I think on the early MIT CTSS systems, the BCPL compilers used the notation “$ (” and “$ )” as the section brackets.

BCPL had a huge impact on many researchers. Microsoft’s Hungarian naming convention is a result of early MS developers leaping from XEROX PARC to the Redmond software mill, carrying their BCPL derived coding conventions with them.

BCPL also had an impact on Ken Thompson.

{ B }

Around 1969, Thompson designed a new programming language he called B, the precursor to C. It was very much influenced by Richard’s BCPL, and the section brackets to define a compound statement was take from it. Only when Ken looked at the then new Teletype model 37 keyboard and notice the new curly bracket symbols, minted in 1967, did he choose them as the section brackets for his new programming language.

This meant that Dennis Ritchie used curly brackets for his C programming language, an extension of Ken’s B language, and the rest is history.

The influence of C is far reaching, as shown by the fact that almost every programming language devised since C has used curly brackets to create compound statements.

Oberon to Go

It’s interesting that Go, the relatively new Google programming language, is very much a modern version of Niklaus Wirth’s excellent Oberon.

Oberon, true to its ALGOL roots, adopted more explicit statement bracketing, dropping the extra BEGIN when executing more than one statement.

For example, Pascal, Wirth’s earlier language, used the following
     IF i = 3 THEN BEGIN
          a := 1;
          b := 2
     END

Oberon said the same thing as
     IF i = 3 THEN
          a := 1;
          b := 2
     END

Go streamlined this into
     if i == 3 {
          a = 1
          b = 2
     }

There’s more to Go than recycled Oberon ideas, but by replacing the longer keywords with curly brackets, Go is the final chapter in a long history of bracketing compound statements with keywords.

But none of this would have been possible, of course, had it not been for the Teletype Model 37 and Ken Thompson’s independent spirit. Without them, we might all be still typing DO and END.

Charlie Greenman

Razroo | AI Ticketing System

4y

These are my favorite sort of articles! Thank you for writing this. 

keep writing! love this series...

Marcio Lopes de Faria

Curious Software Developer and Problem Solver

8y

Depending of how the variables are declared, the Go example could be more similar, almost identical to Oberon. For example, when use the short variable definition, like the spec: https://golang.org/ref/spec#Short_variable_declarations, as placed bellow: a := 1 b := 2 Oberon is really great, and a good reference to learn how things work as a whole. I hope that others continue to look for inspiration on this examples. Small is Beautiful.

David Paulsen

Retired and Loving It

8y

For fun, in Python, try "from __future__ import braces" :)

Like
Reply

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics