GoogleC++编程风格指南

  1. 命名约定

记录一下对自己有益的用法:

命名约定

1
2
int num_errors; 
int num_completed_connections;
1
2
3
4
5
6
7
8
9
10
// classes and structs
class UrlTable { ...
class UrlTableTester { ...
struct UrlTableProperties { ...

// typedefs
typedef hash_map<UrlTableProperties *, string> PropertiesMap;

// enums
enum UrlTableErrors { ...
1
2
my_exciting_local_variable
my_exciting_member_variable_
1
2
3
4
struct UrlTableProperties {
string name;
int num_entries;
}
1
bool gInvalid = false;
1
const int kDaysInAWeek = 7;
1
2
AddTableEntry()
DeleteUrl()
1
2
3
4
5
6
7
8
9
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_;
};
1
2
3
void swap(int &a, int &b);
int max(int a, int b);
bool cmp(Type t1, Type t2);
1
2
3
namespace google_awesome_project {
...
}
1
2
3
4
5
enum UrlTableErrors {
kOK = 0,
kErrorOutOfMemory,
kErrorMalformedInput,
};
1
2
#define ROUND(x) ...
#define PI_ROUNDED 3.0
script>