Member-only story

The Case Against Curly Braces {} Languages

C, C++, Java, C#, Go, JavaScript and many more languages use curly braces to group statements or declarations. But is this a good choice?

Okay, what the hell. In this story I will argue against one of the most popular syntax conventions by far in the programming world. Programmers love their curly braces. And few new programming languages dare break with this tradition firmly established with the C programming language.

C gained massive popularity early and C++ piggy backed on this popularity. Then came Java which wanted to also piggy back on this success and thus adopted a similar syntax. The huge success of Java caused Microsoft to make their own Java clone, which later became C#. And over at Netscape they where making a LISP or Scheme language, meaning lots of parenthesis, but for marketing reasons it got a last minute remake and got curly braces too.

Bottom line is that curly braces is a bit of an accident of history. I will here try to make the case that using keywords to denote scope like Pascal, Algol, Lua, Ada, Basic and Matlab to name a few examples is better.

In many of these languages begin end marks a scope.

Julia code using begin-end to mark scope. When keyword like if, and while is used the begin can be omitted.

Blocks and their indentation level is easier to identify because begin end is lager and more visible markers than { and }.

But this is not really the main issue. It is that braces must be able to make a case for why they are needed. Why? Because different forms of brackets and braces are of outmost importance in programming languages and we are in limited supply of them. We need them for the following:

  • Grouping arithmetic expression. Most use ( and ). (2 + x) * 4
  • Grouping array elements and perform array access. Most use [ and ]. x = array[4]
  • Specifying type parameter. vector<int> items.

In the latter case all the curly braces language have been forced to adopt < and > despite these brackets being a terrible choice. Why?

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Erik Engheim
Erik Engheim

Written by Erik Engheim

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

Responses (32)

I used to think like you. Then I tried Python (where whitespace has meaning), and suddenly I got renewed respect for the much-maligned {}
Curly braces aren't dependent on someone's editor setup, for example. Copy-paste will always work, which in…

--

Most of that just looks messy. Old time programmer here using C-like languages for 40 years. Currently a C# fan. I find using braces on a line to themselves makes skimming through code really fast. Everything stands out and you don't have to…

--

Who cares about typing efficiency these days? Autocompletion and autonisertion of matching braces makes typing efficiency less of issue. With modern AI-based autocompletion tools, even variable naming is not an issue in most cases.

--