c++cindentationgoogle-style-guide

Why people like aligning function parameters with the left parenthesis?


I saw many repositories using google c++ style, they format function parameters like this

void Foo(int param1, int param2,
         int param3, int param4,
         int param5, int param6)

or

void Foo(int param1, int param2, int param3, int param4,
         int param5)

or

void Foo(int param1,
         int param2,
         int param3,
         int param4)

I know this style makes the parameters stand out, but if we had to rename Foo to FooBar, the first parameter wouldn't be in the same column with other parameters. Like this,

void FooBar(int param1,
        int param2,
        int param3,
        int param4)

Do they have to format the whole project again to make all parameters of FooBar in the same column?


Solution

  • All code styles like that will need to be reformatted anytime you change something. c'est la vie.

    The common excuse for formatting like the 3rd example is that any variable change will affect only 1 line, and not affect source control diffs so much. Obviously if you change the function name itself then the diff will change all parameters. This can be a good thing - it shows the function changed and not the 1st parameter.

    In short, there are much better things to worry about than indentation styles being good or bad. Just ensure you follow whatever is already there as changing from 1 style to another is the worst thing anyone can do.