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
3
votes
1 answer

How to reformat Java from Allman to K&R with line comments using Eclipse?

I started out coding using the Allman style, with aligned braces: void foobar() { if(foo) { bar(); } } After decades I've decided I want that extra screen space; and besides, my client uses non-matched braces, so it's hard to switch back…
Garret Wilson
  • 14,167
  • 20
  • 115
  • 211
3
votes
4 answers

{$_GET['action']}(); What does mean all these braces?

Could someone please help to understand this syntaxe trick in php: enter $controller->{$_GET['action']}(); I'm talking about the {$_GET['action']}(); I'm trying to understand the mvc pattern on this blog http://r.je/mvc-in-php.html but it's realy…
3
votes
2 answers

Tcl adds curly braces when using `$` sign

set B {pc_0::!mx_0 pi::$mx_0} puts $B set A "" foreach x $B { lappend A $x } puts $A The output of this program is pc_0::!mx_0 pi::$mx_0 pc_0::!mx_0 {pi::$mx_0} It is strange that tcl adds curly braces in second output. I guess it is…
Ashot
  • 9,891
  • 12
  • 56
  • 100
3
votes
2 answers

For a structure variable,why is the initializer {21,19,3.6} same as {{21,19},3.6},but not vice-versa?

In the following example,I've illustrated this using two structures test1 and test2.The first has two elements-an integer array sized two,and a float element.The second structure has 3 elements,2 integers and one float. I initialize two structure…
Rüppell's Vulture
  • 3,453
  • 7
  • 33
  • 47
2
votes
2 answers

What is the difference between [myString length] and myString.length in objective-c?

I'm currently learning objective-c. What exactly do the square braces around things signify and is there any difference between using that and using a period (I'm from a .NET world so this would be simpler for me). Thanks.
Matt B
  • 733
  • 3
  • 9
  • 17
2
votes
1 answer

How to disable IntelliJ's indentation-based brace handling?

IntellIJ 2020.2 added Indentation-based brace handling for Scala mentioned on the website here whatsnew. How do I disable this feature? I've searched for keywords "indent brace" and "brace handling" and cant see a setting that would disable it under…
captain-inquisitive
  • 3,277
  • 6
  • 32
  • 55
2
votes
2 answers

Eclipse Java Formatter. New line before curly braces, but not after

we have here at work a very strange coding convention, and I didn't managed to setup the Java Formatter in Eclipse right to do what I want. The convention says: Before a curly brace "{" there should always be a new Line [UPDATE] There is no rule…
Asturio
  • 525
  • 7
  • 21
2
votes
3 answers

Scoping rules in Java

Can someone help me understand the scoping rules in Java? This is clearly not valid: { int i = 0; System.out.println(i); // fine, of course } System.out.println(i); // syntax error i is declared within the {}, and it's…
Matthew Gilliard
  • 8,783
  • 3
  • 28
  • 47
2
votes
1 answer

Substituting braces {} with quotes "

I want to replace braces {} with quotes ". I tried the following code, the problem is that the \ appaers in the string and I can not delete it. Code used: makebib <- function(string){ # replace { by " string <- gsub("\\{",'"',string) #…
2
votes
2 answers

c++ - initializing an array member with aggregate initialization

With this code: struct Structure { int a; char b[4]; }; void function() { int a = 3; char b[] = {'a', 'b', 'c', 'd'}; } Can I initialize Structure with the values of a and b using aggregate initialization? I tried Structure{a, b},…
2
votes
1 answer

Lone braces inside a class?

I couldn't find anything about this online, because I didn't know what to search for, but Java doesn't mark this code as having an error: public class Test { // ... { int test; } // ... } Does this serve any purpose in…
2
votes
2 answers

brace after else on same line in spite of changing it in formatter

I would like to have my else as follows else { } However, at the moment it still looks like else { } I have gone and edited the Braces tab in Window -> Preferences -> Java -> Code Style -> Formatter and changed everything to Next line.…
tubby
  • 1,844
  • 3
  • 23
  • 46
2
votes
2 answers

Powershell: Does calling .NET a function always require parenthesis?

I know that PowerShell function calls don't need specific parentheses like C#, but when I try to call .NET class functions, it seems parentheses are always needed, like: [Int32]::Parse("12") So is this a syntax rule?
vik santata
  • 2,525
  • 5
  • 24
  • 47
2
votes
1 answer

PyParsing Parse nested loop with brace and specific header

I found several topics about pyparsing. They are dealing with almost the same problem in parsing nested loop, but even with that, i can't find a solution to my errors. I have the following format : key value; header_name "optional_metadata" { …
user1130
  • 1
  • 3
2
votes
1 answer

How do I indent lines with vim when there are commented-out braces?

I usually use the vim re-indent operator ('=') in order to indent my sourcecode according to its syntax. I also use it on the whole file, especially if I have to read sourcecode that was written by someone else and they have different tab settings…
Viktor Dick
  • 111
  • 1