Why does ROS c++ codestyle wiki contradict google c++ codestyle

asked 2018-03-05 01:27:14 -0600

Alberth gravatar image

updated 2018-03-05 02:17:36 -0600

While looking for the standard C++ codestyle, I ended up at the wiki: http://wiki.ros.org/CppStyleGuide It is based on the google cpp style guide, since "..it is a well-written document on the topic at hand..". Nothing wrong with that I think.

While reading the ROS wiki, I noticed that curly brace codestyle is to have the culry brace on a line of its own (in Section 6). The google c++ code style does not do that however, it places the open curly brace always at the end of the line. The ROS wiki does not give any explanation whatsoever on why this was chosen.

Example:
ROS wiki:

    if(a < b)
    {
      // do stuff
    }
    else
    {
      // do other stuff
    }

google style guide:

    if (condition) {  // no spaces inside parentheses
      ...  // 2 space indent.
    } else if (...) {  // The else goes on the same line as the closing brace.
      ...
    } else {
      ...
    }

In other words, ROS cppstyle wiki uses a "well-written document on the topic on hand" as guide for the code style, and then simply discards that wisdom with some other code style, without any explanation as to why.

Can someone please enlighten me why google code style is not followed here?

edit retag flag offensive close merge delete

Comments

Can you please post a code example of what you're talking about?

jayess gravatar image jayess  ( 2018-03-05 02:01:12 -0600 )edit

@jayess this is a general question, so not related to particular code. ROS wiki states "Braces on seperate lines", Google uses opening braces on same line.

mgruhler gravatar image mgruhler  ( 2018-03-05 03:50:21 -0600 )edit
1

@mig I understand, but sometimes it's useful to have examples

jayess gravatar image jayess  ( 2018-03-05 04:10:40 -0600 )edit