【C++】Google C++ Style GuideのNaming Rules(命名規則)メモ

Google C++ Style GuideのNaming Rulesメモ

命名規則の種類

一般的に、以下の4種類の命名規則が使われる。

命名規則 説明
PascalCase 先頭大文字、それ以降の単語区切りも大文字
camelCase 先頭小文字、それ以降の単語区切りは大文字
snake_case すべての小文字、単語区切りを"_"でつなぐ
SCANE_CASE すべて大文字、単語区切りを"_"でつなぐ

型の名前(Type Names)

  • 頭文字は大文字
  • それぞれの単語の頭文字も大文字
  • アンダースコアは付けない
// classes and structs
class UrlTable { ...
class UrlTableTester { ...
struct UrlTableProperties { ...

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

// using aliases
using PropertiesMap = hash_map<UrlTableProperties *, string>;

// enums
enum UrlTableErrors { ...

変数名(Variable Names)

  • すべて小文字
  • 単語は"_"で接続してもよい
string table_name;  // OK - uses underscore.
string tablename;   // OK - all lowercase.
  • クラスのデータメンバは最後に"_"をつけること.(structの場合はつけない)
class TableInfo {
  ...
 private:
  string table_name_;  // OK - underscore at end.
  string tablename_;   // OK.
  static Pool<TableInfo>* pool_;  // OK.
};
struct UrlTableProperties {
  string name;
  int num_entries;
  static Pool<UrlTableProperties>* pool;
};

関数名(Function Names)

  • 頭文字は大文字
  • 単語の頭文字は大文字
  • "_"はつけない
AddTableEntry()
DeleteUrl()
OpenFileOrDie()