Cpp: Formatting
Posted in Google, Open Source, Programming, Software | 6 Comments »
As a programmer and designer I always try my hardest to get my code clear,concise and pretty. Mainly for my own benefit for looking over projects that have dust on them, and also for the publics benefit for when I release code as open-source. In this post I’m going to take a slightly less formal route and try and find out your preferences when coding to get an understanding of commonly used methods when working on a project.
Parenthesis
void function_name(int nCount, float val); // No spacing void function_name( int nCount, float val ); // Spacing
Code Blocks
void function_name(int unused){
// Blank
}
void function_name(int unused)
{
// Blank
}
Tab Width
void function_name( void )
{
string tab_space;
tab_space = "2";
cout << "Tab Space:" << tab_space << endl; // Two
tab_space = "4";
cout << "Tab Space:" << tab_space << endl; // Four
tab_space = "8";
cout << "Tab Space:" << tab_space << endl; // Eight
}
Function & Variable Naming
void function_name(int nCount, float val); // Underscore void functionName( int nCount, float val ); // Capitals int my_variable; int myVariable;
My personal preference is underscores for variables and function names, 4 space tab width and spacing between parenthesise, however these are just a few formatting methods on my mind, if your a coder and you are reading this, leave a comment below saying what you prefer, If you have any alternative methods please share I’d love to hear them!











