Skip to content

Rcpp Coding Guidelines

James J Balamuta edited this page Jul 16, 2016 · 1 revision

Rcpp Coding Guidelines

The development model for Rcpp necessitates the use of a version control system. In this case, we've opted to use git. To contribute code via git, we ask that all code changes are first proposed in an issue where the merits of the change can be weighed before work is begun on the code. Once the code has been written, we then encourage PR to include unit tests if new functionality is added. Furthermore, please update the ChangeLog and NEWS to describe what was contained within your contribution. It is imperative that the code contributed passes the aforementioned unit tests run by Travis. In the event that the contribution fails, please spend time trying to figure out what went wrong.

Please note that C++ code in Rcpp must adhere to the C++98 standard. C++11 (and above) extensions are allowed, but must be appropriately guarded so that such code still successfully compiles under the C++98 standard.

If you have questions, feel free to ask within an issue. We are more than happy to provide answers and help.

Coding Style Guide

In order to streamline the contributions from multiple authors, we have established code styling guidelines. We expect that all contributed code will follow the guidelines. The use of a style guide is not meant to discourage potential contributors, but to inform them of how we expect contributed code to conform to the pre-existing codebase.

#define SOME_CONSTANT                         // all uppercase
#define Rcpp_class_h                          // header inclusion guard  

typedef double SomeType;                      // camelcase, starting capital

class SomeClass {                             // camelcase, starting capital
  public:
    void method();
    Real anotherMethod(Real x,                // camelcase, starting lowercase
                       Real y) const;
    Real member() const;                      // getter, no leading "get"
    void setMember(Real);                     // setter, leading "set"
  private:
    Real member_;                             // camelcase, starting lowercase,
    Integer anotherMember_;                   // trailing underscore
};

struct SomeStruct {
    Real foo;                                 // struct members:
    Integer bar;                              // no trailing underscore
};

class SomeOtherClass {
  public:
    typedef Real* iterator;                   // no camelcase for consistency
    typedef const Real* const_iterator;       // with STL conventions
};

Size someFunction(Real parameter,             // one parameter per line,
                  Real anotherParameter) {    // camelcase, starting lowercase
    Real localVariable = 0.0;
    if (condition) {                          // brackets here...
        localVariable += 3.14159;
    } else {                                  // ...here...
        localVariable -= 2.71828;
    }                                         // ...and here.
    return 42;
}

The overall style is largely inspired by the QuantLib Style Guidelines

Clone this wiki locally