Coding Style
4.8. Intermezzo: Coding Style
- Use 4-space indentation,and no tabs.
使用四格缩进,而非Tab. //我一直都是用的Tab.... 在.vimrc里设置的 set tabstop=4 应该也是四格缩进吧
- Wrap lines so that they don't exceed 79 characters.
折行以确保其不会超过79个字符. // 过长的话直接来个 \ 好了
- Use blank lines to separate functions and classes, and larger blocks of code inside functions.
使用空行分隔函数和类,以及函数中的大块代码. //每一函数或类之后总是习惯性的回车几下看来是个好习惯
- When possible, put comments on a line of their own.
肯能的话,让注释独占一行. //想这样只有几个字的"注释"就没必要换行了吧,多浪费...
- Use docstrings.
使用文档字符串
- Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4).
在操作符和逗号两边放空格,但括号里不加 //每次都忘记空格..
- Name your classes and functions consistently; the convention is to use CamelCase for classes and lower_case_with_underscores for functions and methods. Always use self as the name for the first method argument
统一函数和类名,合适的用法是 类为 CamelCase 骆驼式命名,函数和方法为 lower_case_with_underscires 小写加下划线式命名.总是把 self 作为方法的第一个参数 //骆驼式命名.....下次注意
- Don’t use fancy encodings if your code is meant to be used in international environments. Plain ASCII works best in any case.
在国际化环境中不要用自己喜欢的编码,纯ASCII总是工作最好的. //貌似UTF-8 更好....
每个人都会有自己的Coding Style,虽然我没写过几行代码,自然也有,只是我还没发现哈~