Brackets vs braces vs parentheses: What's the difference?

When to use round, square and curly brackets

To become a 10x software developer, you need to master a language — the English language.

Languages including Java, C++, JavaScript and C# use various types of brackets to denote different aspects of code.

For example:

  • Round brackets () are used for methods.
  • Square brackets [] are used for arrays.
  • Curly brackets {} are used to set scope.

Difference between braces, brackets & parentheses

As often as you may hear the terms round bracket, square bracket or a curly bracket, those are not the proper or official names of these notations. The proper names are braces, brackets and parentheses. Here are the differences between them:

  • Parentheses is the proper term for curved or round brackets.
  • Braces is the proper term for curly brackets.
  • Square brackets are simply called brackets.
Bracket vs. brace vs. parenthesis
Proper name Alternative names Typical uses
Brace Curly braces, squiggly braces, chicken lips Define the start and end of a class, method, loop or code block
Bracket Square brackets Used for array declaration, or access an element in a collection class
Parenthesis Round brackets Define a method signature, or pass arguments into a method

Square bracket [] languages

In most programming languages, square brackets are used to define an array:

String[] data = {"I", "need", "arrays"};

In C#, you’ll also see square brackets to select a range of array values, as in this example:

var array = new int[] { 1, 2, 3, 4, 5 };
var slice1 = array[2..^3];

The other common use for square brackets is to access elements in a dictionary or a map, as in this Python example:

value = data_dictionary['key']

Groovy and C# also use brackets to access properties of an object.

Parenthesis programming ()

Many programming languages, including Java, typically associate round brackets or parentheses with methods.

The parameter list for a method is always placed in round brackets in Java:

public void doSomething(String round, int brackets){return 0;}

When a method is invoked, round brackets are used again.

int x = doSomething("data", 42);

Braces in code {}

In languages such as Java and C, braces or curly brackets define the start and end of language constructs such as classes, methods and loops.

Generally speaking, braces also define the scope of a variable. For example, a variable defined within brackets that delineate the start and end of a class will have scope inside all of the class’s methods.

A variable defined within the braces that mark the start and end of a method has method scope.

A variable defined within the braces that mark the start and end of a for or while loop has scope only within that loop.

curly brackets or braces and variable scope

Braces, also known as curly brackets, set the scope for a Java variable.

When to say brackets, braces & parentheses

It’s unlikely anyone will ever correct you for not knowing the difference between brackets, parentheses and braces.

The truth is, the terms round brackets, square brackets and squiggly brackets are just part of the programming vernacular.

Nevertheless, it is good to know the proper technical terms for various programming language symbols and artefacts.

 

App Architecture
Software Quality
Cloud Computing
Security
SearchAWS
Close