Good | Bad |
---|---|
```cpp // crepe startup message std::string message = "Hello, world!"; ``` | ```cpp // crêpe startup message std::string message = "こんにちは世界"; ``` |
Good | Bad |
---|---|
```cpp class Foo {}; ``` | ```cpp class Cars {}; ``` |
Good | Bad |
---|---|
```cpp int add(int a, int b) { // add numbers int out = a + b; return out; } ``` | ```cpp int add(int a, int b) { int out = a + b; // add numbers return out; } ``` |
Good | Bad |
---|---|
```cpp
#include |
```cpp
#include |
using namespace
may not be used in header files (.h, .hpp), only
in source files (.cpp).
Good | Bad |
---|---|
example.h: ```cpp namespace crepe { void foo(); } ``` example.cpp: ```cpp #include "example.h" using namespace crepe; void foo() {} ``` |
example.h:
```cpp
namespace crepe {
template |
get_
and set_
.
Good | Bad |
---|---|
```cpp class Foo { public: int get_speed() const; void set_speed(int speed); private: int speed; }; ``` | ```cpp class Foo { public: int speed() const; void set_speed(int speed); private: int speed; }; ``` |
Good | Bad |
---|---|
```cpp class Foo { Foo & get_instance() { static Foo instance; return instance; } }; ``` | ```cpp Foo Foo::instance {}; class Foo { static Foo instance; Foo & get_instance() { return Foo::instance; } }; ``` |
Good | Bad |
---|---|
```cpp class Foo { int speed = 0; }; ``` | ```cpp class Foo { Foo() : speed(0) {} int speed; }; ``` |
Good | Bad |
---|---|
```cpp class Foo { public: Foo() : bar("baz") {} private: std::string bar; }; ``` | ```cpp class Foo { public: Foo() : bar(0) {} private: int bar; }; ``` |
Good | Bad |
---|---|
```cpp struct Foo { int bar = 0; std::string baz; }; ``` | ```cpp struct Foo { int bar; std::string baz; }; ``` |
Good | Bad |
---|---|
```cpp class Bar; class Foo { Bar & bar; }; ``` | ```cpp #include "Bar.h" class Foo { Bar & bar; }; ``` |
.h
header, and
defined in a matching .hpp
header.
Good | Bad |
---|---|
add.h:
```cpp
template |
add.h:
```cpp
template |
Good | Bad |
---|---|
```cpp enum Color { Red, Green, Blue, }; ``` | ```cpp enum Color { Red, Green, Blue }; ``` |
#pragma
should be used instead of include guards
Good | Bad |
---|---|
```cpp #pragma once // ... ``` | ```cpp #ifndef __INCLUDED_H #define __INCLUDED_H // ... #endif ``` |
std::move
Good | Bad |
---|---|
```cpp using namespace std; string foo = "bar"; ref_fn(std::move(foo)); ``` | ```cpp using namespace std; string foo = "bar"; ref_fn(move(foo)); ``` |
Good | Bad |
---|---|
```cpp void foo(const Point & p); ``` | ```cpp void foo(Point & p); void bar(Point p); ``` |
Good | Bad |
---|---|
```cpp class Foo { public: Foo(); ~Foo(); Foo(const Foo &); Foo(Foo &&) noexcept; Foo & operator=(const Foo &); Foo & operator=(Foo &&) noexcept; }; ``` | ```cpp class Foo { public: Foo(); ~Foo(); Foo(const Foo &); }; ``` |
Good | Bad |
---|---|
```cpp class Foo { public: int get_value() const; void set_value(int new_value); const std::string & get_name() const; void set_name(const std::string & new_name); private: int value; std::string name; }; ``` | ```cpp class Foo { public: int get_value(); void set_value(int new_value); std::string get_name(); void set_name(std::string new_name); private: int value; std::string name; }; ``` |
Good | Bad |
---|---|
```cpp MyClass.h MyClass.cpp MyClass.hpp ``` | ```cpp my_class.h my_class.cpp my_class.hpp ``` |
Good | Bad |
---|---|
```cpp class Foo { public: int get_value() const { return 42; } }; ``` | ```cpp class Foo { public: int calculate_value() const { int result = 0; // complex calculation return result; } }; ``` |
Good | Bad |
---|---|
```cpp
#include |
```cpp
#include "iostream"
#include |
Good | Bad |
---|---|
```cpp /** * \brief do something * * \param bar Magic number */ void foo(int bar); ``` | ```cpp /** * @brief do something * * @param bar Magic number */ void foo(); ``` |