Click here to Skip to main content
11,414,670 members (65,842 online)
Click here to Skip to main content

Tagged as

Braces and brackets

, 3 Nov 2000 CPOL
Rate this:
Please Sign up or sign in to vote.
Options for placing braces

Options for Parentheses

Option 1: Spaces between inside and outside the parentheses. 

if ( something )
...

Option 2: Spaces outside parentheses, no space inside.

if (something)
...

Option 3: Spaces inside parentheses, no space outside.

if( something )
...

Option 4: No white space.

if(something)
...

Options for braces

Option 1: Braces starting on control line.

if (something) {
  // statements
}

Option 2: Braces starting on line under control line, non-indented.

if (something) 
{
    // statements
}

Option 3: Braces starting on line under control line, indented.

if (something) 
    {
    // statements
    }

Option 4: Braces starting on control line, closing brace indented.

if (something) {
    // statements
    }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.

His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.

He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.

Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralOld post Pin
mbaocha6-May-09 13:32
membermbaocha6-May-09 13:32 
GeneralRe: Old post Pin
Harsimran Singh (.NET)20-Jan-10 13:25
memberHarsimran Singh (.NET)20-Jan-10 13:25 
GeneralRe: Old post Pin
AlluvialDeposit2-May-13 2:23
professionalAlluvialDeposit2-May-13 2:23 
GeneralBalancing between disk usage & readability Pin
Anonymous1-Sep-01 4:10
memberAnonymous1-Sep-01 4:10 
GeneralRe: Balancing between disk usage & readability Pin
NebuGranny29-Mar-04 10:51
memberNebuGranny29-Mar-04 10:51 
GeneralRe: Balancing between disk usage & readability Pin
Derek Bartram22-Mar-08 12:26
memberDerek Bartram22-Mar-08 12:26 
QuestionHow about spaces Pin
AlexMarbus27-Feb-01 8:27
memberAlexMarbus27-Feb-01 8:27 
AnswerRe: How about spaces Pin
Jason Douglas2-Mar-01 4:38
memberJason Douglas2-Mar-01 4:38 
AnswerRe: How about spaces Pin
Anonymous2-Mar-01 7:05
memberAnonymous2-Mar-01 7:05 
GeneralRe: How about spaces Pin
James R. Twine4-Mar-01 8:51
memberJames R. Twine4-Mar-01 8:51 
> I use this
> if( a )

   Same for me.  Same goes for function calls, and brackets.  I also tend to space out "pointer to member".  My spacing looks like this:

    CSomeObj    *pObj = m_soaSomeObjectArray[ 2 ];  // Get Object From Array...
    
    if( pObj )                                      // If We Have An Object
    {
        pObj -> CallThisFunction(...);              // Call Function
        _ASSERTE( sizeof( wchar_t ) == 2 );         //(In)Sanity Check...
        ::_putts( _T( "Write out THIS!" ) );        // Yell At User
    }

   Peace!


-=- James.
AnswerRe: How about spaces Pin
Simon Hughes2-Apr-01 1:24
memberSimon Hughes2-Apr-01 1:24 
AnswerRe: How about spaces Pin
Yoko1-May-01 5:06
memberYoko1-May-01 5:06 
AnswerRe: How about spaces Pin
James Pullicino4-May-01 5:45
memberJames Pullicino4-May-01 5:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150427.4 | Last Updated 4 Nov 2000
Article Copyright 1999 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid