Member-only story
The Story of Curly Braces in Coding
Where it came from, how it’s doing, will it last?
If you look at the programming languages we have today, more often than not, you will find this wonderful symbol {
and }
used in the programming language.
What is it for? Simple, it is to tell the compiler (or interpreter) the beginning and the end of the code block. And of course, you can have blocks within a block.
// A very simple example from C#
public class MyClass
{
public void myFunction(bool isToPrint)
{
if (isToPrint)
{
Console.WriteLine("Hello, world!");
}
}
}
Ever wonder how it came about? Where should we put it? What’s the trend moving forward?
Has It Always Been There?
No. When computers were first invented, the programming language was so different from what we have today. An excellent medium blog by Michael McMillan wrote the entire history of it.
I’m just summarizing it below (credit to Michael McMillan)
In the days of ALGO58 (in 1958)
In those days, the block concept was brought into programming, which is a big step forward for the programming world. It’s introduced through the ALGO58 language.
if x > -1 then
begin
if x ≠ 0 then
x := 1/x
end;
It uses the begin
and end
as you can see. Clear, visible. Anyone who reads it understands, without wondering what {
and }
are.
In the days of BPCL (~10 years later), the father of C language
The begin
and end
was good. But to make coding easier and more efficient, a shorter method was introduced, i.e. $(
and $)
.
IF A < B
$( LET T = A
A := B; B := T
$)
Neat, we no longer need to type the words. But this didn’t last that long.