从小就写字很挫,因此受够了被人鄙视的感受,今天有个coder忽然跟我说,你的代码怎么像小孩写的同样,顿时心情沮丧的极点。愈来愈发现一致的编程风格的重要性,因而把Google的C++编程风格指南看了一遍, 这里记录下于本身有益的rules。当规则有多个选择时,这里只记录我的习惯的用法, 并不表明它是惟一的用法。编程
命名管理是最重要的一致性规则,所以我把它放在最前面。函数
int num_errors; int num_completed_connections;
my_useful_class.cc
my_useful_class.cc
my_useful_class.h
// classes and structs class UrlTable { ... class UrlTableTester { ... struct UrlTableProperties { ... // typedefs typedef hash_map<UrlTableProperties *, string> PropertiesMap; // enums enum UrlTableErrors { ...
my_exciting_local_variable
my_exciting_member_variable_
struct UrlTableProperties { string name; int num_entries; }
bool gInvalid = false;
const int kDaysInAWeek = 7;
AddTableEntry()
DeleteUrl()
class MyClass { public: ... int num_entries() const { return num_entries_; } void set_num_entries(int num_entries) { num_entries_ = num_entries; } private: int num_entries_; };
void swap(int &a, int &b); int max(int a, int b); bool cmp(Type t1, Type t2);
namespace google_awesome_project { ... }
enum UrlTableErrors { kOK = 0, kErrorOutOfMemory, kErrorMalformedInput, };
#define ROUND(x) ... #define PI_ROUNDED 3.0