zoukankan      html  css  js  c++  java
  • google python/c++ code style naming

    python:

    Guidelines derived from Guido's Recommendations

    TypePublicInternal
    Packages lower_with_under  
    Modules lower_with_under _lower_with_under
    Classes CapWords _CapWords
    Exceptions CapWords  
    Functions lower_with_under() _lower_with_under()
    Global/Class Constants CAPS_WITH_UNDER _CAPS_WITH_UNDER
    Global/Class Variables lower_with_under _lower_with_under
    Instance Variables lower_with_under _lower_with_under (protected) or __lower_with_under (private)
    Method Names lower_with_under() _lower_with_under() (protected) or __lower_with_under() (private)
    Function/Method Parameters lower_with_under  
    Local Variables lower_with_under  

    c++:

    File Names:

    my_useful_class.cc
    my-useful-class.cc
    myusefulclass.cc
    myusefulclass_test.cc // _unittest and _regtest are deprecated.
    url_table.h      // The class declaration.
    url_table.cc     // The class definition.
    url_table-inl.h  // Inline functions that include lots of code.

    classes and structs:

    // classes and structs
    class UrlTable { ...
    class UrlTableTester { ...
    struct UrlTableProperties { ...
    
    // typedefs
    typedef hash_map<UrlTableProperties *, string> PropertiesMap;
    
    // enums
    enum UrlTableErrors { ...

    Variable Names:

    Common Variable names
    
    For example:
    
    string table_name;  // OK - uses underscore.
    string tablename;   // OK - all lowercase.
    string tableName;   // Bad - mixed case.
    Class Data Members
    
    Data members (also called instance variables or member variables) are lowercase with optional underscores like regular variable names, but always end with a trailing underscore.
    
    string table_name_;  // OK - underscore at end.
    string tablename_;   // OK.
    Struct Variables
    
    Data members in structs should be named like regular variables without the trailing underscores that data members in classes have.
    
    struct UrlTableProperties {
      string name;
      int num_entries;
    }

    Constant Names

    Use a k followed by mixed case: kDaysInAWeek.
    All compile-time constants, whether they are declared locally, globally, or as part of a class, follow a slightly different naming convention from other variables. Use a k followed by words with uppercase first letters:
    
    const int kDaysInAWeek = 7;

    Function Names

    Regular Functions
    
    Functions should start with a capital letter and have a capital letter for each new word. No underscores.
    
    If your function crashes upon an error, you should append OrDie to the function name. This only applies to functions which could be used by production code and to errors that are reasonably likely to occur during normal operation.
    
    AddTableEntry()
    DeleteUrl()
    OpenFileOrDie()
    Accessors and Mutators Accessors and mutators (
    get and set functions) should match the name of the variable they are getting and setting. This shows an excerpt of a class whose instance variable is num_entries_. 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_; }; You may also use lowercase letters for other very short inlined functions. For example if a function were so cheap you would not cache the value if you were calling it in a loop, then lowercase naming would be acceptable.

    Enumerator Names

    Preferably, the individual enumerators should be named like constants. However, it is also acceptable to name them like macros. The enumeration name, UrlTableErrors (and AlternateUrlTableErrors), is a type, and therefore mixed case.
    
    enum UrlTableErrors {
      kOK = 0,
      kErrorOutOfMemory,
      kErrorMalformedInput,
    };
    enum AlternateUrlTableErrors {
      OK = 0,
      OUT_OF_MEMORY = 1,
      MALFORMED_INPUT = 2,
    };

    Macro Names

    You're not really going to define a macro, are you? If you do, they're like this: MY_MACRO_THAT_SCARES_SMALL_CHILDREN.
    Please see the description of macros; in general macros should not be used. However, if they are absolutely needed, then they should be named with all capitals and underscores.
    
    #define ROUND(x) ...
    #define PI_ROUNDED 3.0
  • 相关阅读:
    Centos7 安装Postgres11(更改数据目录)
    将trj保存成.gpx文件方便进行地图匹配(来自徐博士的支援)
    将北京路网OSM文件导入到PostgreSQL + PostGIS 中,并利用osm2pgrouting工具+osmosis工具构建路网Graph拓扑结构
    SQL-时间-UTC-时间戳-日期-年查询在PG+PostGIS
    地理坐标系4326--投影坐标系3857/2436
    基于postgis时空查询-记录而已
    Java 接口
    单例模式
    weblogic启动一闪而过
    oracle存储过程中is和as区别
  • 原文地址:https://www.cnblogs.com/springbarley/p/3299151.html
Copyright © 2011-2022 走看看