如果有一天,有人告诉你,你将来需要和一帮只会说英语和泰语的家伙工作在一起,而你的工作是要告诉他们如何写整洁的代码,如何做重构,什么是TDD,什么是面向对象,你该怎么办?
你问我,我只能告诉你,我需要重新读一次《整洁代码》,《重构》以及《
敏捷软件开发:原则、实践和模式》的英文版,然后整理出里面可以为我使用的术语和表达。
第四章:Formatting(格式)
neatness, consistency(整洁一致)
When people look under the hood, we want them to be impressed with the neatness, consistency, and attention to detail that they perceive.
Dependent Functions. (被依赖的函数)
If one function calls another, they should be vertically close, and the caller should be above the callee, if at all possible. This gives the program a natural flow. If the convention is followed reliably, readers will be able to trust that function definitions will follow shortly after their use.
Team rules(团队规则)
The title of this section is a play on words. Every programmer has his own favorite formatting rules, but if he works in a team, then the team rules.
A team of developers should agree upon a single formatting style, and then every member of that team should use that style. We want the software to have a consistent style. We don’t want it to appear to have been written by a bunch of disagreeing individuals.
其实重读这一章节,有许多已经是默认约定,有一些也因为工作环境的变化,有更好的选择,Uncle Bob讲到最为重要的其实是保证团队的规则一致性,以及一些实践操作的习惯,比如:不要直接使用IDE的Code Formatting,稍微手动调整一下或者只format自己相关的部分代码。
让代码看上去像是一个人写的,才是最终目的。
To be continued(未完待续)