What's the difference between brackets, braces and parentheses?

 

Parenthesis vs braces vs 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.

However, there really is no such thing as a round bracket or a curly bracket. Their proper names are parentheses and braces.

  • Parentheses is the proper term for curved, round brackets.
  • Braces is the proper term for curly brackets.
  • Square brackets are simply called brackets.
Brackets vs. braces vs. parentheses
Proper name Alternative names Typical uses
Braces Curly braces, squiggly braces, chicken lips Define the start and end of a class, method, loop or code block
Brackets 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[] programming

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 programming {}

In languages such as Java and C, braces or curly brackets to 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.

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

Round vs. square vs. curly brackets

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 nice to know the proper technical terms for various programming language symbols and artefacts.

 

App Architecture
Software Quality
Cloud Computing
Security
SearchAWS
Close