what is clean code?

Dave Thomas关于整洁代码有段话:
Clean Code can be read, and enhanced by a developer other than its original author. It has unit and acceptance tests. It has meaningful names. It provides one way rather than many ways for doing one thing. It has minimal dependencies, which are explicitly defined, and provides a clear and minimal API. Code should be literate since depending on the language, not all necessary information can be expressed clearly in code alone.
   针对可理解性与可维护性做了阐述,可理解性对于普通程序员来说最重要的是友好,当然单元测试,后续的验收测试也必不可少,体现了敏捷开发,测试驱动的要素。
   函数或方法应该具有有意义的命名,每段代码块具有单一功能,减少与外部系统,环境,方法的依赖,API则尽可能少,前面我们做的项目实际上后来我感觉API设计的有冗余,提供了至少2个方法来获取同一引擎,首先当然是不好管理资源,其次犯此minimal API戒条,并且API意义也不明确,多义性很多,同时依赖于三个函数,失败!
   我想API实际上是系统暴露的使用契约,必须从命名到使用的场景,已经依赖上都有明确的意义,有歧义是不行的,某种意义上,具有”API的完备性“。

你可能感兴趣的:(重构,Dave Thomas)