Questions tagged [curly-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 symbols "{" and "}", commonly used in programming languages. Please be sure that the specific usage of these symbols is a relevant part of the question.

652 questions
12
votes
1 answer

Can curlies be omitted for try and/or catch blocks, as for if and else ones?

if (foo) { bar; } can be shortened to if(foo) bar; since it's only one statement in the block. I'm wondering if the same applies to try/catch... I don't like extra cruft in my code.
wwaawaw
  • 6,867
  • 9
  • 32
  • 42
11
votes
1 answer

Uniform initialization on a vector of vectors of integers

C++11 The program initializes a vector, named myVec, of int vectors, and then uses a loop to print out each inner vector's elements. But I got unexpected results when trying to see what happens when I use extra curly braces. The following is also on…
CodeBricks
  • 1,771
  • 3
  • 17
  • 37
11
votes
5 answers

Double curly braces in perl

I was looking at perl code online and came across something I hadn't seen before and can't find out what it's doing (if anything). if($var) {{ ... }} Does anyone know what the double curly braces mean?
Chris
  • 143
  • 10
10
votes
3 answers

How can I escape curly braces inside jade templates?

ho can I escape curly braces inside a jade teplate? (I use jade inside node.js) I want to render jQuery templates to the client. The part I want to escape looks like this: div(class='clear') script(id='BoardListTemplate',…
Juergen Gutsch
  • 1,774
  • 2
  • 17
  • 28
10
votes
2 answers

paredit curly brace matching in swank-clojure repl

I am using emacs 24 on Windows 7 and have installed technomancy's clojure-mode along with paredit 23 beta. I load the source file from my leiningen project and get a repl using clojure-jack-in. The problem is that while paredit is enabled in both…
pventura
  • 117
  • 6
10
votes
1 answer

How to make Xcode put starting brace on new line in Swift?

I have noticed that the coding style in Swift appears to be to put braces on the same line as a method signature or if statement etc. Without getting into a debate about which is right or wrong, my aim is simply tom get Xcode to put the braces on a…
Alan Spark
  • 8,152
  • 8
  • 56
  • 91
10
votes
6 answers

"using" statement vs. curly brackets

I wonder why we do use using statement in C#. I looked it up, and found that it is used for executing the statements and then cleaning up the objects. So my question: Isn't it the same thing if we open and close curly brackets( { } ) to define a…
hevele
  • 903
  • 6
  • 20
  • 38
9
votes
7 answers

Can Someone Explain This Snippet (Why Are These Braces Here)?

I apologize for this overly simplistic question, but I can't seem to figure out this example in the book I'm reading: void f5() { int x; { int y; } } What are the braces surrounding int y for? Can you put braces wherever you…
Gary
  • 13,303
  • 18
  • 49
  • 71
9
votes
7 answers

How can can I get emacs to insert closing braces automatically

I've just started using emacs, and there's one feature I'd really like, and searching around a bit was fruitless. I hope someone else has done this because I don't want to learn elisp just yet. void foo() I would like typing an "{" to cause…
Bwmat
  • 4,314
  • 3
  • 27
  • 42
9
votes
0 answers

Xcode 7: Change { (brace) location to start on a new line

I've read responses from 1, 2, and 3. I was wondering how one could do this in Xcode 7? I tried downloading Snippet Edit, but it doesn't seem to have the code for the built-in class methods stub like: override func prepareForSegue(segue:…
stumped
  • 3,235
  • 7
  • 43
  • 76
9
votes
1 answer

What are JSDoc @type curly braces for?

The JSDoc @type tag allows specification of a variable type, such as /** @type {Number} */. However I've also see /** @type Number */ without the curly braces, and it seems equally valid. Use JSDoc has an example both with and without the curly…
orlade
  • 2,060
  • 4
  • 24
  • 35
9
votes
2 answers

Which is the use of curly braces in Haskell?

The code below getSpareBuffer :: Handle__ -> IO (BufferMode, CharBuffer) getSpareBuffer Handle__{haCharBuffer=ref, haBuffers=spare_ref, haBufferMode=mode} = do case mode of NoBuffering -> return…
Dragno
  • 3,027
  • 1
  • 27
  • 41
8
votes
6 answers

Valid Braces - CodeWars Challenge

There is a challenge on codewars that asks you to check whether a string of parentheses, brackets, and curly braces is valid. A string of braces is considered valid if all braces are matched with the correct brace. I.e. "()" is valid and "[(])" is…
HappyHands31
  • 4,001
  • 17
  • 59
  • 109
8
votes
3 answers

Why do Java array declarations use curly brackets?

I would like to know why Java array declarations use curly brackets as opposed to the standard parenthesis. As illustrated here. I imagine this may take further understanding of curly brackets in general, but this specifically is on my agenda right…
Evan
  • 279
  • 1
  • 2
  • 11
8
votes
3 answers

Curly brackets indention in Visual Studio for Mac

I use Visual Studio for Mac and the curly brackets in my code are not indented automatically and they are aligned to the left. Have somebody encountered this issue? How can I fix it? .
morkan
  • 171
  • 2
  • 3
  • 6