Questions tagged [parentheses]

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 parentheses "(" and ")" are special cases of brackets, along with square brackets ("[" and "]") and curly brackets (or braces) ("{", "}").

Parentheses (singular parenthesis) have many uses in most programming languages, such as:

  • indicate the arguments of a function call;
  • specify the order of evaluation/execution of expressions;
  • create lists/arrays/vectors.
1024 questions
370
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
  • 59,296
  • 21
  • 173
  • 234
345
votes
1 answer

Complex Git branch name broke all Git commands

I was trying to create a branch from master with the following command, git branch SSLOC-201_Implement___str__()_of_ProductSearchQuery when Git suddenly stopped responding. I suspect the unescaped () are to blame, somehow. Now, whenever I try to…
ruipacheco
  • 15,025
  • 19
  • 82
  • 138
270
votes
11 answers

How to select between brackets (or quotes or ...) in Vim?

I'm sure there used to be a plugin for this kinda stuff, but now that I need it, I can't seem to find it (naturally), so I'll just ask nice and simple. What is the easiest way to select between brackets, or quotes, or generally a list of matching…
Rook
  • 60,248
  • 49
  • 165
  • 242
224
votes
3 answers

What do the parentheses around a function name mean?

In one of my project source files, I found this C function definition: int (foo) (int *bar) { return foo (bar); } Note: there is no asterisk next to foo, so it's not a function pointer. Or is it? What is going on here with the recursive call?
user1859094
  • 1,899
  • 2
  • 12
  • 5
170
votes
3 answers

Why was the statement (j++); forbidden?

The following code is wrong (see it on ideone): public class Test { public static void Main() { int j = 5; (j++); // if we remove the "(" and ")" then this compiles fine. } } error CS0201: Only assignment, call,…
user10607
  • 3,011
  • 4
  • 24
  • 31
144
votes
6 answers

"assert" statement with or without parentheses

Here are four simple invocations of assert: >>> assert 1==2 Traceback (most recent call last): File "", line 1, in ? AssertionError >>> assert 1==2, "hi" Traceback (most recent call last): File "", line 1, in ? AssertionError:…
new name
  • 15,861
  • 19
  • 68
  • 114
132
votes
4 answers

Advanced JavaScript: Why is this function wrapped in parentheses?

Possible Duplicate: What is the (function() { } )() construct in JavaScript? I came across this bit of JavaScript code, but I have no idea what to make out of it. Why do I get "1" when I run this code? What is this strange little appendix of (1)…
nerdess
  • 10,051
  • 10
  • 45
  • 55
102
votes
14 answers

Enclosing in parentheses with Vim

Is there a way to enclose some text in parentheses (or curly brackets) in vim? In other words, how would you do this? Initial string: It is sunny outside. Final string: It is (sunny) outside. On a funny note, I just hit :w to submit this…
eqb
  • 1,650
  • 3
  • 20
  • 25
101
votes
8 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
  • 51,090
  • 44
  • 144
  • 286
99
votes
1 answer

What is Round brackets / parentheses () in try catch in Java

As per as my knowledge we use try catch as follows: try { //Some code that may generate exception } catch(Exception ex) { } //handle exception finally { //close any open resources etc. } But in a code I found following try( …
Partha Sarathi Ghosh
  • 10,936
  • 20
  • 59
  • 84
96
votes
2 answers

When do extra parentheses have an effect, other than on operator precedence?

Parentheses in C++ are used in many places: e.g. in function calls and grouping expressions to override operator precedence. Apart from illegal extra parentheses (such as around function call argument lists), a general -but not absolute- rule of C++…
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
74
votes
7 answers

Remove Text Between Parentheses PHP

I'm just wondering how I could remove the text between a set of parentheses and the parentheses themselves in php. Example : ABC (Test1) I would like it to delete (Test1) and only leave ABC Thanks
Belgin Fish
  • 803
  • 2
  • 7
  • 7
72
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,529
  • 3
  • 14
  • 27
61
votes
9 answers

Is there a good reason for always enclosing a define in parentheses in C?

Clearly, there are times where #define statements must have parentheses, like so: #define WIDTH 80+20 int a = WIDTH * 2; // expect a==200 but a==120 So I always parenthesize, even when it's just a single number: #define WIDTH (100) Someone new to…
weston
  • 54,145
  • 21
  • 145
  • 203
59
votes
1 answer

Why import statements with parentheses?

Lately have seen imports like this from module import (function, another_function, another_function) Seemingly this has been done to be able to stretch the import statement over more than one line. In cases like this I usually…
LarsVegas
  • 6,522
  • 10
  • 43
  • 67
1
2 3
68 69