ethz-asl / programming_guidelines

This repository contains style-guides, discussions, eclipse/emacs auto-formatter for commonly used programming languages
139 stars 38 forks source link

Eclipse / Emacs auto formatter style following the google style guide instead of ROS #8

Closed simonlynen closed 11 years ago

simonlynen commented 11 years ago

ROS and google are quite similar. http://google-styleguide.googlecode.com/svn/trunk/eclipse-cpp-google-style.xml http://www.ros.org/wiki/IDEs?action=AttachFile&do=view&target=ROS_format.xml

Main difference: Indentiation in spaces: ROS: 4, Google: 2 (I vote for Google) Curly bracket on new line for conditionals: ROS: yes, Google: no (I vote for Google) Initializer list break: ROS: no, Google: yes (I vote for ROS)

ROS:

/*
 * A sample source file for the code formatter preview
 */
#include <math.h>

class Point
{
public:
  Point(double x, double y) :
      x(x), y(y)
  {
  }
  double distance(const Point& other) const;

  double x;
  double y;
};

double Point::distance(const Point& other) const
{
  double dx = x - other.x;
  double dy = y - other.y;
  return sqrt(dx * dx + dy * dy);
}

I would vote for Google which formatted the following example:

/*
 * A sample source file for the code formatter preview
 */
#include <math.h>

class Point {
 public:
  Point(double x, double y)
      : x(x),
        y(y) {
  }
  double distance(const Point& other) const;

  double x;
  double y;
};

double Point::distance(const Point& other) const {
  double dx = x - other.x;
  double dy = y - other.y;
  return sqrt(dx * dx + dy * dy);
}
simonlynen commented 11 years ago

lets got with the google one as it saves space