Size: 4716
Comment:
|
Size: 6394
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 49: | Line 49: |
= 空白缩进(Whitespace) = 每个缩进的大小为4个空格键,不允许使用Tab键。强烈建议为每个代码段另起一行,这使代码中的控制结构的缩进更清晰。 Indentation is 4 spaces per indent. Tabs are not allowed. It is preferred that every block appear on a new line, so that control structure indentation is always visible. = 模块(Modules) = 模块的名称全部小写,并尽可短,最好是一个单词。如果模块的名称包含多个单词,可以使用下划线分隔或是直接将几个单词连起来写。 Modules must be named in all lower-case, preferably short, single words. If a module name contains multiple words, they may be separated by underscores or not separated at all. 大多数情况下,模块应该包含多个类,函数或是方法。如果一个模块只包含一个对象,可以考虑通过代码重构将一些相关的功能包含的该模块中。 In most cases, modules should contain more than one class, function, or method; if a module contains only one object, consider refactoring to include more related functionality in that module. 根据具体情况,下面的几种import方式都是可以的: Depending on the situation, it is acceptable to have imports that look like this: {{{ from twisted.internet.defer import Deferred }}} 或是: or like this: {{{ from twisted.internet import defer }}} 也就是说,可以通过from ... import语句来导入module、class和function,但是不能通过from ... import语句导入一个package。 That is, modules should import modules or classes and functions, but not packages. |
在这里编辑"PyTwisted/WorkingOnTheTwistedCodeBase/CodingStandard".
Twisted编码标准 (Twisted Coding Standard)
命名(Naming)
应该选择一个容易记又有具体含义的名字。模块的命名可以随意一些(例如 twisted.spread ...),但是类命名必须十分清晰明了。写代码的时候请保证手边就有字典或是辞典,方便随时查看。
Try to choose names which are both easy to remember and meaningful. Some silliness is OK at the module naming level (see twisted.spread...) but when choosing class names, be as precise as possible. Write code with a dictionary and thesaurus open on the table next to you.
应该避免用一个术语表示多种含义。要避免这个问题比想象中难的多,因为大多数常用的单词已经被许多其它软件用过了,所以这个规则经常被破坏。更重要的是,应该避免使用那些没有任何意义的单词。特别是像handler、processor、engine、manager和component这些词,这些词只能说明某个东西确实能做一些事情,但是并不能真的表述出这个东西的实际功能,
Try to avoid overloaded terms. This rule is often broken, since it is incredibly difficult, as most normal words have already been taken by some other software. More importantly, try to avoid meaningless words. In particular, words like handler, processor, engine, manager and component don't really indicate what something does, only that it does something.
在命名和python的doc字串请使用美式拼写方法。例如,对于像filesystem这样的合成技术名词,在编码和doc字串中都应该使用没有连字符的拼写方式,以避免不必要的单词首字母大写问题。
Use American spelling in both names and docstrings. For compound technical terms such as 'filesystem', use a non-hyphenated spelling in both docstrings and code in order to avoid unnecessary capitalization.
测试(Testing)
单元测试应该使用twisted.trial框架编写。twisted.test包中有许多例子可以参考。测试模块的名称应该以“test_”开头。每个源码文件中都应该有一个“test-case-name”标签来指定与之相关的测试代码。
Unit tests are written using the twisted.trial framework. Many examples are in the twisted.test package. Test modules should start with 'test_' in their name. Source files should have test-case-name tags that point to their related tests.
验收测试(acceptance test)现在全部由admin/accepttests中的脚本自动完成。(TODO: 真正的验收测试策略)
Acceptance tests are all automated by the admin/accepttests script currently. (TODO: real acceptance tests strategy!)
在你checkin任何修改之前,请运行单元测试来测试你的代码。
Run the unit tests tests before you check anything in.
再次重申,在你checkin任何修改之前,请运行单元测试来测试你代码。由于验收测试通常是不可移植的,并且在某些情况下验收测试自身的运行也会出错,所以出现破坏功能约束的代码这种事儿也是不可避免的,我们也能理解,也可以原谅的。但如果不进行验收测试就提交代码,并造成了对原有功能的损害,就可能会导致从“大家对你的代码所造成的破坏的无情嘲弄”到“取消你在cvs上的commit权限”等各种后果。
Let me repeat that, for emphasis: run the unit tests before you check anything in. Code which breaks functionality is unfortunate and unavoidable. The acceptance tests are highly nonportable and sometimes a pain to run, so this is pardonable. Code which breaks the unit tests in a way that you could have prevented by running them yourself, however, may be grounds for anything from merciless taunting through revertion of the breakage to revocation of cvs commit privileges.
强烈建议开发者学会使用Emacs,并在Emacs中把TwistedEmacs包中的twisted-dev.el文件与F9绑定在一起用来运行单元测试。其它编辑器中现在还没有做类似的支持,但是如果您确实有需要,我们很乐意提供给你。
It is strongly suggested that developers learn to use Emacs, and use the twisted-dev.el file included in the TwistedEmacs package to bind the F9 key to run unit tests and bang on it frequently. Support for other editors is unavailable at this time but we would love to provide it.
如果你修改或是撰写了一个新的HOWTO文档,请参考Lore documentation来学习文档的编写格式。
If you modify, or write a new, HOWTO, please read the Lore documentation to learn the format the docs.
空白缩进(Whitespace)
每个缩进的大小为4个空格键,不允许使用Tab键。强烈建议为每个代码段另起一行,这使代码中的控制结构的缩进更清晰。
Indentation is 4 spaces per indent. Tabs are not allowed. It is preferred that every block appear on a new line, so that control structure indentation is always visible.
模块(Modules)
模块的名称全部小写,并尽可短,最好是一个单词。如果模块的名称包含多个单词,可以使用下划线分隔或是直接将几个单词连起来写。
Modules must be named in all lower-case, preferably short, single words. If a module name contains multiple words, they may be separated by underscores or not separated at all.
大多数情况下,模块应该包含多个类,函数或是方法。如果一个模块只包含一个对象,可以考虑通过代码重构将一些相关的功能包含的该模块中。
In most cases, modules should contain more than one class, function, or method; if a module contains only one object, consider refactoring to include more related functionality in that module.
根据具体情况,下面的几种import方式都是可以的:
Depending on the situation, it is acceptable to have imports that look like this:
from twisted.internet.defer import Deferred
或是:
or like this:
from twisted.internet import defer
也就是说,可以通过from ... import语句来导入module、class和function,但是不能通过from ... import语句导入一个package。
That is, modules should import modules or classes and functions, but not packages.