I was recently trying to find the reasons that led to the use of curly braces for blocks (compound-statements) in the C language and other languages of the same family.
Thinks like square brackets for arrays or parentheses to change operator precedence seems to come from the mathematical notation used for these things so it makes sense to me. The semicolon makes sense too, it's meant to separate related sentences with independent clauses, and it does something like that in C.
But I couldn't find something similar for curly braces: they are used for sets in mathematics, and something somehow similar is their use in musical notation (Ensemble staves) where they are used to indicate that the music on all the staves is to be played simultaneously (not quite the same use but I thought it was closer than their use in mathematics for sets).
Also, I was wondering if C is actually the first language to introduce this block syntax or did it just popularize it?
The first curly brace programming language was BCPL in 1966, although it allowed $(
and $)
to delimit blocks in addition to {
and }
.
BCPL was based on CPL which used the unusual (to modern programmers' eyes) §
to open a block and the same symbol with a line through it to close the block. Martin Richards, the inventor of BCPL in "How BCPL evolved from CPL": says:
CPL used a section symbol (
§
) to be equivalent to Algol’sBEGIN
and a section symbol overprinted with a slash to representEND
. BCPL adopted$(
and$)
for these tokens and as with CPL such section brackets could be tagged, allowing a close section bracket to close multiple sections. Unfortunately this convention lead to rather obscure programming errors and so when curly brackets ({
and}
) became available, they were only used as untagged section brackets and the use of$(
and$)
was discouraged.
Curly braces came to C (1972) via B (1969).