google python/c++ code style naming
python:
Guidelines derived from Guido's Recommendations
Type | Public | Internal |
---|---|---|
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 = ;
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 = ,
- kErrorOutOfMemory,
- kErrorMalformedInput,
- };
- enum AlternateUrlTableErrors {
- OK = ,
- OUT_OF_MEMORY = ,
- MALFORMED_INPUT = ,
- };
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
google python/c++ code style naming的更多相关文章
- Intellij IDEA 配置 Code Style
前言 昨天自说自话,闲扯了界面设计和代码规范.设计确实需要一些经验,也不一定能取悦所有人.而代码规范却是程序员所起码应当做到的,多人协作中,杂乱的代码就好像批阅潦草的作文,可读性极差. 然而这是个懒人 ...
- 在IntelliJ IDEA中配置Google Java Code Style及代码格式化快捷键
google-java-format plugin should intercept the “Reformat Code” action in IDEA (Ctrl+Alt+L) and apply ...
- Google's C++ coding style
v0.2 - Last updated November 8, 2013 源自 Google's C++ coding style rev. 3.274 目录 由 DocToc生成 头文件 ...
- Java Code Style
近期困惑于团队成员代码风格迥异,代码质量不可控,作为一名老司机,忧患于后期服务的可维护性,多次一对一的代码Review,耗时耗力不说,效果也不明显.痛定思痛,多次反思之后得出结论:无规矩不成方圆,可靠 ...
- _rqy's Code Style for OI
_rqy's Code Style for OI Inspired by Menci's Code Style for OI 本文介绍_rqy的OI中的代码规范.其来源主要为_rqy的长期积累及参考G ...
- Google Summer of Code 2017 经验谈
Google Summer of Code (GSoC) 2018 又要开始了. 如果想实现你心中的开源梦想, 用代码让世界变得更美好. 参加GSoC可能是你进入开源的世界最好途径. GSoC是什么 ...
- intelij IDEA设置goole code style风格
1.安装google-java-format 插件 file ->Setings... ->pligins 输入上诉插件安装 2.下载IntelliJ Java Goog ...
- 倒计时第3天!Google Summer of Code报名即将截止!(Casbin社区还有空缺名额)
Google Summer of Code 介绍 Google Summer of Code ( GSoC ,即 Google 编程之夏)是 Google (谷歌)组织并提供经费,面对全球在读学生的在 ...
- 与你相遇好幸运,The Moe Node.js Code Style Guide
The Moe Node.js Code Style Guide By 一个最萌的开发者 @2016.9.21 >>代码是人来阅读的,格式规范的代码是对编程人员最好的礼物 :) > ...
随机推荐
- struts2学生信息管理系统篇章②进度报告篇章
之前做这个系统的时候是什么都不懂的! 经过一个月的时间,慢慢的java的知识都捡起来了. 对struts2和mvc模式都有一一定程度的了解,汇报一下上次的进度. 这个系统我所有的功能中我暂时只做到了下 ...
- hibernate篇章三-- hibernate配置文件hibernate.cfg.xml的详细解释
<!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式--> <?xml version='1.0' ...
- linux的终端,网络虚拟终端,伪终端(转)
转自http://www.xuebuyuan.com/877887.html 2013年09月07日 ⁄ 综合 ⁄ 共 4047字 ⁄ 字号 小 中 大 ⁄ 评论关闭 Linux上许多网络服务应用,如 ...
- Android中log4j的运用
网上一查关于android上面运用Log4j的运用,各种说需要添加多样的包的,照着log4j的官网教程看了下,给了个简单的输出到console上面的代码,似乎没什么用.看网上关于Log4j更多是在ja ...
- oracle 11g 64位安装sqldeveloper打开不了
oracle 11g 64位安装sqldeveloper打开不了解决方法: 1.到官网下载对应版本的sqldeveloper. 2.找对应安装路径下的F:\app\Administrator\prod ...
- Cookie / Session / URL重写
Cookie //创建一个Cookie对象 Cookie cookie = new Cookie("username","JACK"); //在客户端存储的时间 ...
- Spring 和 MyBatis 环境整合
本案例主要是讲述Spring 和 MyBatis 的环境整合 , 对页面功能的实现并没有做的很完整 先附上本案例的结构 1 . 创建项目并导入相关jar包 commons-collections4 ...
- 零基础Visual Fox Pro 6.0自学笔记(VFP6.0图文教程)
序:有个哥们读大一,学的金融,由于考试需要去学VFP.拜托我帮忙找教程,发觉网上没有合适的,教学视频多半要收费,优秀文档很少.微软官方也不重视VFP了,真可惜.遂生出写一个入门教程的想法.图文并茂的可 ...
- phaser源码解析(三) Phaser.Utils类下isPlainObject方法
/** * #这是一个对jQuery.isPlainObject(obj)稍加修改的方法. 一个 普通对象 obj.toString() => "[object Object]&quo ...
- weblogic 12c 配置jvm的内存大小
每个weblogic server 都是运行在一个java虚拟机上 ,对weblogic的内存设置也就是对java虚拟机的内存设置. MEM_ARGS=-Xms512m -Xmx1024m -XX:M ...