curly-braces

Basic Code Layout Question

HI, I have a simple question, I've asked 3-4 different people and have had different answers from each of them. Which code layout is better and used more? does it really matter as long as it's consistent? Which is seen as better practice in the world of working as a programmer? Eg A) for(int i=0;i<8;i++) { for(int p=0;p<8;p++)...

Odd compiler error on if-clause without braces

The following Java code is throwing a compiler error: if ( checkGameTitle(currGame) ) ArrayList<String> items = parseColumns( tRows.get(rowOffset+1), currGame, time, method ); checkGameTitle is a public static function, returning a boolean. The errors are all of the type "cannot find symbol" with the symbols being variable ArrayL...

JavaScript: When should I use a semicolon after curly braces?

Many times I've seen a semicolon used after a function declaration, or after the anonymous "return" function of a Module Pattern script. When is it appropriate to use a semicolon after curly braces? ...

A regular expression that moves opening { braces to a new line, for C/C++/PHP/etc code

This kind of code structure makes, IMHO, code less readable: int func() { [...] } It's just a matter of taste, but I prefer this one: int func() { [...] } So I've trying to make a regular expression to apply in my text editor in order to make code in the first example look like the second one. I've come up with something lik...

curly brackets in url will not pass through validation vb.net

i have this url, http://www.poer.com/oneup.htm?zip={zip}. I need the {zip}, because in my code, when this page opens, I replace the {zip} with a zipcode say 10001. But in aspx, when i put validation for that txtbox, it wont let the {} pass through. This is the validation - ValidationExpression="http://([\w-]+.)+[\w-]+(/[\w- ./?%&=]*)?" ...

Parameters with braces in python

If you look at the following line of python code: bpy.ops.object.particle_system_add({"object":bpy.data.objects[2]}) you see that in the parameters there is something enclosed in braces. Can anyone tell me what the braces are for (generically anyway)? I haven't really seen this type of syntax in python and I can't find any documenta...

Why do I not see stricter scoping more often?

I've found myself limiting scope fairly often. I find it makes code much clearer, and allows me to reuse variables much more easily. This is especially handy in C where variables must be declared at the start of a new scope. Here is an example of what I mean. { int h = 0; foreach (var item in photos) { ...

Braces: [Brackets], (Parentheses) & {Curlies} in Ruby & Rails

So the loose tolerance of Ruby to use braces sometimes and not REQUIRE them has led to alot of confusion for me as I'm trying to learn Rails and when/where to use each and why? Sometimes parameters or values are passed as (@user, @comment) and other times they seem to be [ :user => comment ] and still others it's just: :action => 'edit'...

Extra brace brackets in C++ code

Sometimes you run into code that has extra brace brackets, that have nothing to do with scope, only are for readability and avoiding mistakes. For example: GetMutexLock( handle ) ; { // brace brackets "scope" the lock, // must close block / remember // to release the handle. // similar to C#'s lock construct } ReleaseMutexLock...

why results varies upon placement of curly braces in javascript code

Hello All, i have read this javascript article, where an exmaple is shown , Please explain why below codes return different output due to changes the place of curly braces { curly brace { on new line function test() { return { /* <----curly brace in new line*/ javascript : "fantastic" }; } var r = test(); try { alert(r.ja...

How to use constants with Complex (curly) syntax?

I was surprised to see that the following doesn't work as expected. define('CONST_TEST','Some string'); echo "What is the value of {CONST_TEST} going to be?"; outputs: What is the value of {CONST_TEST} going to be? Is there a way to resolve constants within curly braces? Yes, I am aware I could just do echo "What is the value of "....

C# Switch statement with/without curly brackets.... what's the difference?

Has C# always permitted you to omit curly brackets inside a switch() statement between the case: statements? What is the effect of omitting them, as javascript programmers often do? Example: switch(x) { case OneWay: { // <---- Omit this entire line int y = 123; FindYou(ref y); break; ...

How to make eclipse automatically add braces to an IF statement?

In Java the following is completely valid: if (x == null) Y(); else Z(); I personally don't like it at all. I like all my IF statements to have braces: if (x == null) { Y(); } else { Z(); } The eclipse formatter is wonderful and can beautify my code in many other ways. Is there a way to have it add the braces to IF ...

Netbeans PHP - add/remove curly braces plugin/shortcut

I love short if statements without braces (PHP) like if ($x === $y) echo $z; If I want to add a few lines (maybe just temporary for debugging) I have to manually add the braces. Is there a plugin for netbeans that does that via shortcut, something like "toggle (add/remove) previous statement braces"? ...

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()<cursor> I would like typing an "{" to cause this to happen void foo(){ <cursor> } I would like this to only happen in cc-mod...

Is for ({statements;}; condition; {statements;}) legal C?

Bad style notwithstanding, is it legal C to have a for loop with braces inside the parens? Like this: char *a = "a "; char *b = "b "; for ( { int aComesFirst = 1; char *first = a; char *second = b; }; aComesFirst >= 0; { aComesFirst--; swap(first, second); } ) { printf("%s%s\n", first,...

JavaScript formatting: must braces be on the same line as the if/function/etc keyword?

Possible Duplicate: why results varies upon placement of curly braces in javascript code We have company policies that dictate that in PHP opening curly braces should be on their own lines for readability and so that they can line-up with the closing brace; thus: if (true) { ... } but in JS they should be kept on the s...

Can I make Visual Studio place curly braces on the same line as an if statement (in HTML)?

In Visual Studio while designing MVC views (in .aspx or .ascx files) I often use if statements. When I auto-format (Ctrl-K,D), VS wraps the braces in this really ugly and hard to read way: <% if (Model.UserIsAuthenticated) {%> (some HTML goes here...) <% }%> Is there any way to make Visual Studio auto-format like this instead:...

Why doesn't PHP support curly-brace expansion of consts in a string?

PHP supports this: $z = 5; $str = "z is $z"; // result: "z is 5" and it supports this: $c = new StdClass(); $c->x = 9; $str = "x is {$c->x}"; // result: "x is 9" but it does NOT support this: class abc { const n = 2; } $str = "x is {abc::n}"; // result: "x is {abc::n}" Why does PHP not support insertion of consts via the c...