• Create Account

### #ActualNightCreature83

Posted 15 April 2013 - 03:29 PM

My method is similar to the one CornStalks mentioned, with minor differences.

For simple single-line statements, I'd go without brackets:

if(...) //simple single-line statement
if(...) //simple single-line statement
But if they are chained ('else-if' or 'else'), I make the entire chain use brackets:
if(...)
{
//...more complex statements....
}
else if(...)
{
//...more complex statements....
}
If an 'if' is stand-alone, but is multi-lined, or even single-lined but cluttered, I'll fully brace it.
Or, even if the statement itself is simple, but the conditional is more complex, I'd brace it.
if(x == foo && y == (N - 7)
|| z == PI)
{
//Fully braced, because of non-simple conditional.
}

I'd say always use brackets and on new lines, you never know when you want to extend an if or else clause in the future with additional code. If it is a simple statement use a ternary operator for it, if you really wanna keep it on one line.

Btw here is the insomniac coding guide line and this is or something very similar (mostly comes down to camel casing on members and local variable declarations that's different) is used in a few places: http://www.insomniacgames.com/core-coding-standard/

### #1NightCreature83

Posted 15 April 2013 - 03:29 PM

My method is similar to the one CornStalks mentioned, with minor differences.

For simple single-line statements, I'd go without brackets:

if(...) //simple single-line statement
if(...) //simple single-line statement
But if they are chained ('else-if' or 'else'), I make the entire chain use brackets:
if(...)
{
//...more complex statements....
}
else if(...)
{
//...more complex statements....
}
If an 'if' is stand-alone, but is multi-lined, or even single-lined but cluttered, I'll fully brace it.
Or, even if the statement itself is simple, but the conditional is more complex, I'd brace it.
if(x == foo && y == (N - 7)
|| z == PI)
{
//Fully braced, because of non-simple conditional.
}

I'd say always use brackets and on new lines, you never know when you want to extend an if or else clause in the future with additional code. If it is a simple statement use a ternary operator for it, if you really wanna keep it on one line.

Btw here is the insomniac coding guide line and this is or something similar is used in a few places: http://www.insomniacgames.com/core-coding-standard/

PARTNERS