原文
Function names, variable names, and filenames should be descriptive; eschewabbreviation.Give as descriptive a name as possible, within reason. Do not worry about saving horizontal space as it is far more important to make your code immediately understandable by a new reader. Do not use abbreviations that are ambiguous or unfamiliar to readers outside your PRoject, and do not abbreviate by deleting letterswithin a Word.```一句話,就是不要擔心浪費內存空間,命名少用縮寫,語義明確才是最重要的。## 文件名 ##原文Filenames should be all lowercase and can include underscores () or dashes (-).Follow the convention that your project uses. If there is no consistent local pattern to follow, prefer ““.
規則:字母全部小寫,可以使用下劃線‘_' 或者擴折號 '-'。另外,文件名最好多加一些定義。例如 http_server_logs.h 而不是logs.h.## 類型名 ##Type names start with a capital letter and have a capital letter for each new word,with no underscores: MyExcitingClass, MyExcitingEnum. The names of all types — classes, structs, typedefs, and enums — have the same naming convention. Type names should start with a capital letter and have a capital letter for each new word. No underscores.
類型名包括類名,結構體,枚舉,以及typedef。其命名方式符合大駝峰法,也就是名字由一個或者多個單詞組成,每個單詞首字母大寫。## 變量名 ##The names of variables and data members are all lowercase, with underscores between words. Data members of classes (but not structs) additionally have trailing underscores. For instance: a_local_variable, a_struct_data_member,a_class_data_member_
變量名字母全部小寫,字母間使用下劃線聯接。類成員變量需要在名稱后增加一個尾下劃線,例如 a_local_variable,而類成員變量 a_class_data_member_.## 全局變量名##There are no special requirements for global variables, which should be rare in any case, but if you use one, consider prefixing it with g_ or some other marker to easily distinguish it from local variables.
在谷歌規范中并沒有對全局變量的具體限制,只是建議我們為全局變量起一個明顯的區別相對于其他,比如在名字前加個統一的前綴例如g_。##常量名##Use a k followed by mixed case, e.g., kDaysInAWeek, for constants defined globally or within a class.As a convenience to the reader, compile-time constants of global or class scope follow a different naming convention from other variables. Use a k followed by words with uppercase first letters “` 常量名字的規范是混合型即前綴k+駝峰法,例如 const int kDaysInAWeek=3.
新聞熱點
疑難解答
圖片精選