What Is Clean Code? – In Quotes

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值