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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章