DEV Community

Muhammad Zeeshan
Muhammad Zeeshan

Posted on

Apache AGE:Code Style Guide

In this blog we will look at the coding style guide to make a pull request in Apache AGE repository. In our previous blog we explored that how we can create a PR in apache AGE repository. If you want to know about doing a Pull request to Apache AGE you can checkout this blog first.

Indentation

In AGE's official coding style guide they mentioned about using 4 spaces per indentation level instead of using a tab for indentation. Use the same method to indent code even working with switch statement.

switch (suffix) {
    case 'G':
    case 'g':
        mem <<= 30;
        break;
    case 'M':
    case 'm':
        mem <<= 20;
        break;
    case 'K':
    case 'k':
        mem <<= 10;
        // fall through
    default:
        break;
}
Enter fullscreen mode Exit fullscreen mode

In the code above we have used 4 spaces instead of a single tab.

Breaking long lines and Strings

Line length is 79 columns. So, if the length of code line exceeds 79 columns, move the string to next line. And if there is a case in which the String is exceeding 79 columns we don't need to break the string.

Placing Braces and Spaces

All opening or closing braces are to be placed on a single line solely. Example

void function(int x)
{
    body of function
}

if(x is true)
{
do task a
}
else if(y is true)
{
do task b
}
else
{
do task c
}
Enter fullscreen mode Exit fullscreen mode

The main thing to keep in mind in the above code is braces, each opening or closing brace is placed on a single line and no code on that line.
Note
If all the bodies of if/else statements contains a single line, omit braces. Example

if(x is true)
    do task a
if(y is true)
    do task b
else
    do task c
Enter fullscreen mode Exit fullscreen mode

Naming

Use the underscore name convention for all variables, functions, structs, and enums.

Commenting

For multi-line comments, use C style multi-line commments. And for single line comments use the style format as shown below.

/*
 * This function
 * does x
 */
void f(void)
{
    // This is to check...
    if (y is true)
        we do b
/*
 * We need to do this here
 * because of ...
 */
for (;;)

}
Enter fullscreen mode Exit fullscreen mode

NewLines

For newlines, only \n is allowed, not \r\n and \r.

Note

For a list of all the coding style guidelines, visit the clang-format.5 in the official AGE git repository.

Reference

https://age.apache.org/contribution/guide/#code-style-guilde

Top comments (0)