什么样的代码才是真正好的、整洁的代码?来看看大牛们怎么说。

Bjarne Stroustrup,C++之父:

引用

我喜欢优雅、高效的代码:

● 逻辑应该是清晰的,bug难以隐藏;

●依赖最少,易于维护;

●错误处理完全根据一个明确的策略;

●性能接近最佳化,避免代码混乱和无原则的优化;

●整洁的代码只做一件事。

Grady Booch,《面向对象分析与设计》作者:

引用

●整洁的代码是简单、直接的;

●整洁的代码,读起来像是一篇写得很好的散文;

●整洁的代码永远不会掩盖设计者的意图,而是具有少量的抽象和清晰的控制行。

Dave Thomas,OTI公司创始人,Eclipse战略教父:

引用

●整洁的代码可以被除了原作者之外的其他开发者阅读和改善;

●具备单元测试和验收测试;

●有一个有意义的名字;

●使用一种方式来做一件事情;

●最少的依赖,并明确定义;

●提供了一个清晰的、最小的API;

●应该根据语言特性,在代码中单独显示必要的信息,而不是所有的信息。

Michael Feathers,《修改代码的艺术》作者:

引用

●整洁的代码看起来总是像很在乎代码质量的人写的;

●没有明显的需要改善的地方;

●代码的作者似乎考虑到了所有的事情。

Ward Cunningham,Wiki和Fit创始人,极限编程联合创始人,Smalltalk和面向对象的思想领袖:

引用

●当你读代码时,你发现每个程序都如你期待的那样

●你可以称之为漂亮的代码

●代码完美展现了该编程语言的设计目的

总之,整洁的代码的特点:

●容易与其他人协作(简单、意图明确、良好的抽象、不出意料、合适的名称)

●针对现实世界,比如,有一个清晰的错误处理策略

●代码作者显然很关心软件和其他开发者(针对双方的可读性和可维护性)

●最小化(做一件事,最小的依赖)

●以最合适的方式解决问题

The Agile Zone is presented by ThoughtWorks Studios. Take advantage of their agile experts Jez Humble and Martin Fowler. Learn more about their FREE Continuous Delivery toolchain.

What is actually good, clean code? Why does it matter?

Marry Poppendieck has, in her excellent talk Deliberate Practice in Software Development (slides), quoted a couple of leading figures of our industry on what is clean code.

(Emphasis is mine.)

Bjarne Stroustrup, inventor of C++:

I like my code to be elegant and efficient. The logic should be straightforward and make it hard for bugs to hide, the dependencies minimal to ease maintenance, error handling complete according to an articulated strategy, and performance close to optimal so as not to tempt people to make the code messy with unprincipled optimizations. Clean code does one thing well.

Grady Booch, author of Object-Oriented Analysis and Design with Applications:

Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designers’ intent but rather is full of crisp abstractions and straightforward lines of control.

“Big” Dave Thomas, founder of OTI and godfather of the Eclipse strategy:

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.

Michael Feathers, author of Working Effectively with Legacy Code:

I could list all of the qualities that I notice in clean code, but there is one overarching quality that leads to all of them. Clean code always looks like it was written by someone who cares. There is nothing obvious that you can do to make it better. All of those things were thought about by the code’s author, and if you try to imagine improvements, you are led back to where you are, sitting in appreciation of the code someone left for you—code written by someone who cared deeply about the craft.

Ward Cunningham, inventor of Wiki and Fit, co-inventor of Extreme Programming. The force behind Design Patterns. Smalltalk and OO thought leader. The godfather of all those who care about code.

You know you are working with clean code when each routine you read turns out to be pretty much what you expected. You can call it beautiful code when the code also makes it look like the language was made for the problem.

Summary

Clean code is

Easily accessible to others (straightforward, clear intent, good abstractions, no surprises, good names) – this is absolutely the most mentioned point
Is made for the real-world, i.e. has a clear error-handling strategy (my current project has been burnt a lot by the lack of this so my emphasis is little subjective  )
The author clearly cares for the software and other developers (which implies both readability and maintainability)
Is minimal (does one thing, has minimal dependencies)
Is good at what it does

英文原文:What Is Clean Code?,编译:iteye – wangguo

What Is Clean Code? – In Quotes相关推荐

  1. 《代码整洁之道》(Clean Code)- 读书笔记

    一.关于Bob大叔的Clean Code <代码整洁之道>主要讲述了一系列行之有效的整洁代码操作实践.软件质量,不但依赖于架构及项目管理,而且与代码质量紧密相关.这一点,无论是敏捷开发流派 ...

  2. 聊聊clean code

    clean code,顾名思义就是整洁的代码,或者说清晰.漂亮的代码,相信大多数工程师都希望自己能写出这样的代码. 也许这是个千人千面的话题,每个工程师都有自己的理解.比如我,从一个天天被骂代码写得烂 ...

  3. 如何写一个好的方法-读Clean Code 有感

    针对方法,文中提到了几个规则,我认为比较有价值的几个列在下面. 1.      短小.好的方法是只做一件事情. 那么如何判断一个方法是做了一件事情呢?根据Clean Code的描述,是指的方法所作的事 ...

  4. 用重构指导Clean Code(二):依恋情结和switch语句

    书接上回,我们继续聊如何用重构指导Clean Code. 在Clean Code的3.4节中有这样一段代码(代码清单3-4).(第3章主要讲的是函数,而3.4节讨论的是switch语句.) publi ...

  5. 代码整洁之道(Clean Code)- 读书笔记

    Sorry, 许久未更新文章了,主要因为刚刚换了一家新公司,忙于组建团队(建设.招聘.流程.框架等)与熟悉公司业务,还有领导给的其他工作等等,实在是没有时间更新了.最近在和团队分享Bob大叔的< ...

  6. PHP 代码简洁之道 ( PHP Clean Code)(第二部分)

    PHP 代码简洁之道 ( PHP Clean Code)(第一部分)​ 使用默认参数而不是使用短路运算或者是条件判断 不好的做法: 这是不太好的因为 $breweryName 可以是 NULL. fu ...

  7. Clean Code 笔记

    Why clean code matters 糟糕的代码现在看起来也许没什么要紧,但是过个两三年,就回发现,改起来困难重重. 维护一份干净的代码不仅仅是为了现在,也是为你的职业着想,想想要是在糟糕的代 ...

  8. 《Clean Code》代码的整洁之道(一)

    <代码整洁之道>:细节之中自有天地,整洁成就卓越代码 概述 软件质量,不但依赖于架构及项目管理,而且与代码质量紧密相关.这一点,无论是敏捷开发流派还是传统开发流派,都不得不承认.<代 ...

  9. 代码整洁之道(clean code)序

    代码整洁之道(clean code)序 为什么要写出一手整洁的代码 我可以说是对自己coding水平要求比较高的那种类型,不是说代码能跑起来就ok了,总是希望自己的代码就像诗一样的优美,让人读起来赏心 ...

最新文章

  1. 38. Leetcode 101. 对称二叉树 (二叉树-二叉树性质)
  2. helm部署hadoop并指定namespace和名称的命令
  3. “约见”面试官系列之常见面试题之第一百零五篇之v-if与v-show(建议收藏)
  4. js 为表格增加行 动态
  5. MyBatis 动态 SQL 底层原理分析
  6. linux was8.5 无法启动wct.sh,WebSphere(was8.5) 在linux集群安装及部署.docx
  7. python结果保存到变量_python中import this 编程之禅的结果我想用一个变量保存,如何做...
  8. 小甲鱼 C语言 24课 指针和二维数组
  9. adb与java端口冲突,如何解决adb devices 端口被占用的问题zz
  10. html文档放到phpstudy,phpstudy使用详解
  11. hive 常用函数操作
  12. 微信聊天内容制作生成器微信小程序源码/支持多种制作生成
  13. iOS获取UUID,并使用keychain存储,可用于封设备
  14. phpmywind 解决多语言版本 导航调取问题-5.6之前版本
  15. 【Python办公自动化】快速将excel按照某列不同的值批量拆分
  16. 基于Java解惑(站长百科)阅读笔记
  17. 日本图书馆有哪些地方
  18. 常用前端JS代码与JS方法
  19. 浙江工业大学 计算机考研难吗,浙江工业大学考研难吗
  20. 【强化学习PPO算法】

热门文章

  1. 如何制作GIF图片 使用Ulead GIF Animator 5
  2. C++ 获取物理Mac地址
  3. (六)华为ModelArts 半自动标注 锥桶数据集yolov5s 打标签不用这么辛苦啦
  4. 关于夜神模拟器,你该了解这些
  5. Pre-built binaries not installable for grpc@1.10.1 and node@8.4.0 (node-v57 ABI, glibc) (falling bac
  6. Spark内存管理原理(上)
  7. 波兰式,逆波兰式,中缀表达式相互转换
  8. Spring框架漏洞总结
  9. 什么是计算机的管家,他管理着计算机的运行,电脑的管家——“有效管理我的计算机”教学设计...
  10. 关于LR12录制脚本时浏览器反馈无法连接网络的问题及解决