In this post I will talk briefly about what are the C++ conventions.

C++ Conventions

CC licensed photo by Martino Sabia on Flickr
CC licensed photo by Martino Sabia on Flickr

Apparently the C++ coding conventions are a set of rules that guide the programming around the world. This rules are essential in order to create programs that can actually be useful in different parts of the world.

Each programming language has its own inherent rules such as any other language. Just as there are some rules besides grammar and spelling in English, in programming language there are also other rules. If you want to code properly, you mut follow this conventions.

Summing up, the coding conventions are a set of guidelines for a programm language that suggest an style, practices and ways of doing certain things when programming.

There seems to be several different conventions for any given language which I still don’t know. For example in this link (https://gcc.gnu.org/wiki/CppConventions) there is a page where you can find the different GCC G++ coding conventions that were valid until 2012-08-16. However, there are updates once in a while since programming languages evolve and become more sophisticated. Programmers should always try to be updated with the last coding convetions.

Look at an example of a simple convention about braces:

if (a > 5) {
  // This is K&R style
}

if (a > 5) 
{
  // This is ANSI C++ style
}

if (a > 5) 
  {
    // This is GNU style
  }

For example, a program could as well be written using as follows:

// Using an indentation size of 2
if ( a > 5 )  { b=a; a++; }

However, the same code could be made much more readable with proper indentation:

// Using an indentation size of 2
if ( a > 5 )  {
  b = a;
  a++;
}

// Using an indentation size of 4
if ( a > 5 )
{
    b = a;
    a++;
}

I hope this little post help you to learn what coding conventions are.

References:

https://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/C%2B%2B/Code/Style_Conventions

CC BY 4.0 Mastery08 by Octavio Rojas is licensed under a Creative Commons Attribution 4.0 International License.