Chapter 4: Key Construction Decisions
4.1 Choice of Programming Language
编程语言的选择从多个方面影响生产率和代码质量。使用熟悉的语言比使用不熟悉的语言生产率要高。使用高级语言比使用较低级语言能达到更好的生产率和质量。
高级语言(eg. C++)比低级语言在生产率、可靠性、简洁性、易理解性等方面高5到15倍,高级语言比低级语言的表达力更强,每行代码能表达更多的含义。某些语言更能表达编程中的各种概念。
编程语言影响程序员的思维。对于不熟悉的语言,虽然能写出可以编译通过的代码,但是往往采用的是熟悉语言的思维方式,忽略不熟悉语言的的高级特性。
4.2 Programming Conventions
针对变量名称、类的名称、子程序名称、格式约定、注释约定等方面的编程约定,将使得编程实现与架构保持一致。
编程约定使得程序的结构平衡,统一编程语言的细节,使得各个部件都能反映整体架构的内涵。没有统一的规则,创作出来的东西充斥着各种不同的风格,混乱而邋遢,把握这些不同风格,给工程师的大脑带来沉重负担。
编程约定的细节要达到编码完成后几乎不可能改变所遵循的编程约定的精度。
4.3 Your Location on the Technology Wave
信息技术日新月异,不同时期的技术环境完全不同。在成熟时期编码会更容易。但是即使在技术浪潮的初期或者是某个新技术的早期,决定项目成败的更多是程序员的编程思路。
大多数的编程原则并不依赖特定的语言,而依赖于你使用语言的方式。如果你使用的语言缺乏你希望用的构件,应该试着去弥补它,发明自己的编码约定、标准、类库以及其他改进措施。
4.4 Selection of Major Construction Practices
构建的实践方法的种类比任何单个项目中用到的要多,需要有意识的选择最适合项目的时间方法;如某些项目使用结对编程和测试驱动开发,而其他项目使用单人开发和形式化检查。
[主要的构建实践核对表]
Key Points
Every programming language has strengths and weaknesses. Be aware of the specific strengths and weaknesses of the language you’re using.
Establish programming conventions before you begin programming. It’s nearly impossible to change code to match them later.
More construction practices exist than you can use on any single project. Consciously choose the practices that are best suited to your project.
Ask yourself whether the programming practices you’re using are a response to the programming language you’re using or controlled by it. Remember to program into the language, rather than programming in it.
Your position on the technology wave determines what approaches will be effective or even possible. Identify where you are on the technology wave, and adjust your plans and expectations accordingly.