Questions tagged [braces]

The symbols "{" and "}", commonly used in programming languages. Please use this tag only if the specific usage of these symbols is a relevant part of the question.

The curly brackets (or braces) "{" and "}" are special cases of brackets, along with parentheses and square brackets ("[" and "]").

Curly brackets have many uses in most programming languages, such as:

  • identify code blocks;
  • create lists and arrays;
  • pass arguments to commands in TeX.
170 questions
347
votes
9 answers

What is the formal difference in Scala between braces and parentheses, and when should they be used?

What is the formal difference between passing arguments to functions in parentheses () and in braces {}? The feeling I got from the Programming in Scala book is that Scala's pretty flexible and I should use the one I like best, but I find that some…
Jean-Philippe Pellet
  • 56,205
  • 18
  • 161
  • 223
77
votes
7 answers

List of all unicode's open/close brackets?

What is a list of every unicode bracket-like characters (including, for example: {}[]()<>)? What is a good way to search for unicode characters?
MaiaVictor
  • 45,122
  • 42
  • 127
  • 254
53
votes
5 answers

What is the meaning of curly braces?

Just starting to figure Python out. I've read this question and its responses: Is it true that I can't use curly braces in Python? and I still can't fathom how curly braces work, especially since pages like Simple…
JeanSibelius
  • 1,329
  • 3
  • 13
  • 26
40
votes
9 answers

Strange behavior using braces in Java

When I run the following code: public class Test { Test(){ System.out.println("1"); } { System.out.println("2"); } static { System.out.println("3"); } public static void main(String args[]) { new Test(); } } I…
Eng.Fouad
  • 107,075
  • 62
  • 298
  • 390
36
votes
5 answers

PHP curly braces in array notation

I'd just come across a very weird bit of php code: $oink{'pig'} = 1; var_dump($oink); $oink{'pig'} = '123123'; echo $oink{'pig'}; /* => 123123 */ echo $oink['pig']; /* => 123123 */ It works like an array, but nowhere mentioned in the manual. What…
Jauzsika
  • 2,881
  • 3
  • 21
  • 32
31
votes
3 answers

Why is this Java code in curly braces ({}) outside of a method?

I am getting ready for a java certification exam and I have seen code LIKE this in one of the practice tests: class Foo { int x = 1; public static void main(String [] args) { int x = 2; Foo f = new Foo(); …
nairdaen
  • 1,017
  • 2
  • 10
  • 19
25
votes
3 answers

Customizing the formatting output of .sass?

#foo { color:black; } Is there some sort of option to prefix a newline before the trailing } when a .css file is generated from .sass? I would appreciate it if someone included an example of combining sass --watch style.scss:style.css, which is…
meder omuraliev
  • 171,706
  • 64
  • 370
  • 423
24
votes
3 answers

IntelliJ IDEA braces, brackets and quotes customize color highlighting

How to change color of brackets when they are selected ?
Anton Dozortsev
  • 4,404
  • 3
  • 29
  • 63
23
votes
3 answers

How to put braces in django templates?

I need to produce an id surrounded by braces ( for example "{1234}" ). With the django template language, braces are also used to start a variable substitution, so I have some trouble in obtaining what I want. I tried {{{ id }}} {{ '{'id'}' }} {{…
Stefano Borini
  • 125,999
  • 87
  • 277
  • 404
22
votes
1 answer

Bash command groups: Why do curly braces require a semicolon?

I know the difference in purpose between parentheses () and curly braces {} when grouping commands in bash. But why does the curly brace construct require a semicolon after the last command, whereas for the parentheses construct, the semicolon is…
Digital Trauma
  • 13,834
  • 2
  • 40
  • 73
20
votes
1 answer

How to change brace indentation levels in Emacs?

I can't for the life of me find any answer to this through conventional Internet means, so I'm hoping for some help. Emacs for me right now tends to do indentation on braces as follows: if( ... ) { } Which I find incredibly irritating; I've…
Derek H
  • 10,678
  • 7
  • 34
  • 39
16
votes
5 answers

Highlight BOTH matching braces into Gedit

Any way to highlight both braces on Gedit?, it's annoying when you have several braces joined and is not clear which one are you pointing. Highlighting both braces would be a simple solution to know exactly what are the starting and ending…
Htechno
  • 5,025
  • 3
  • 24
  • 37
14
votes
2 answers

Change brace coding style in QtCreator

I want to change the braces coding style in Qt Creator 2.7.1. Currently, it is: void bar(int i) { static int counter = 0; counter += i; } But I want to change it to: void bar(int i) { static int counter = 0; counter += i; } If I go…
Niklas
  • 18,855
  • 28
  • 114
  • 153
13
votes
7 answers

Why brackets are necessary in catch block in java?

In java if we have to execute only one statement after if or for the brackets are not necessary. We can write: if(condition) executeSingleStatement(); or for(init;condition;incr) executeSingleStatement(); But in the case of catch block why we…
Harry Joy
  • 55,133
  • 29
  • 149
  • 204
12
votes
7 answers

How can I extract a string between matching braces in Perl?

My input file is as below : HEADER {ABC|*|DEF {GHI 0 1 0} {{Points {}}}} {ABC|*|DEF {GHI 0 2 0} {{Points {}}}} {ABC|*|XYZ:abc:def {GHI 0 22 0} {{Points {{F1 1.1} {F2 1.2} {F3 1.3} {F4 1.4}}}}} {ABC|*|XYZ:ghi:jkl {JKL 0 372 0} {{Points…
Srilesh
  • 123
  • 1
  • 1
  • 7
1
2 3
11 12