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, only in source files.
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 /** * \brief do something * * \param bar Magic number */ void foo(int bar); ``` | ```cpp /** * @brief do something * * @param bar Magic number */ void foo(); ``` |