代碼整潔之道英文版

代碼整潔之道英文版

《代碼整潔之道英文版》是2013年人民郵電出版社出版的圖書。

基本介紹

  • 書名:代碼整潔之道英文版
  • 作者:[美]羅伯特·C.馬丁
  • 類別:程式設計
  • 出版社:人民郵電出版社
  • 出版時間:2021年3月
  • 開本:128 開
  • 裝幀:平裝
  • ISBN:9787115557582
內容簡介,圖書目錄,作者簡介,

內容簡介

軟體質量,不但依賴架構和項目管理,而且與代碼質量緊密相關。這一點,無論是敏捷開發流派還是傳統開發流派,都不得不承認。
本書提出一種觀點:代碼質量與其整潔度成正比。乾淨的代碼,既在質量上較為可靠,也為後期維護、升級奠定了良好基礎。作為編程領域的佼佼者,本書作者給出了一系列行之有效的整潔代碼操作實踐。這些實踐在本書中體現為一條條規則(或稱“啟示”),並輔以來自實際項目的正、反兩面的範例。只要遵循這些規則,就能編寫出乾淨的代碼,從而有效提升代碼質量。
本書閱讀對象為有志於改善代碼質量的程式設計師和技術經理。書中介紹的規則均來自作者多年的實踐經驗,涵蓋從命名到重構的多個編程方面,雖為一家之言,然誠有可資借鑑的價值。
顯示部分信息

圖書目錄

Chapter 1: Clean Code / 整潔代碼 1
There Will Be Code / 要有代碼 2
Bad Code / 糟糕的代碼 3
The Total Cost of Owning a Mess / 混亂的代價 4
Schools of Thought / 思想流派 12
We Are Authors / 我們是作者 13
The Boy Scout Rule / 童子軍軍規 14
Prequel and Principles / 前傳與原則 15
Conclusion / 小結 15
Bibliography / 文獻 15
Chapter 2: Meaningful Names / 有意義的命名 17
Introduction / 介紹 17
Use Intention-Revealing Names / 名副其實 18
Avoid Disinformation / 避免誤導 19
Make Meaningful Distinctions / 做有意義的區分 20
Use Pronounceable Names / 使用讀得出來的名稱 21
Use Searchable Names / 使用可搜尋的名稱 22
Avoid Encodings / 避免使用編碼 23
Avoid Mental Mapping / 避免思維映射 25
Class Names / 類名 25
Method Names / 方法名 25
Don’t Be Cute / 別抖機靈 26
Pick One Word per Concept / 每個概念對應一個詞 26
Don’t Pun / 別用雙關語 26
Use Solution Domain Names / 使用解決方案領域名稱 27
Use Problem Domain Names / 使用源自所涉問題領域的名稱 27
Add Meaningful Context / 添加有意義的語境 27
Don’t Add Gratuitous Context / 不要添加沒用的語境 29
Final Words / 後的話 30
Chapter 3: Functions / 函式 31
Small! / 短小 34
Do One Thing 只做一件事 35
One Level of Abstraction per Function / 每個函式一個抽象層級 36
Switch Statements / switch 語句 37
Use Descriptive Names / 使用具有描述性的名稱 39
Function Arguments / 函式參數 40
Have No Side Effects / 無副作用 44
Command Query Separation / 分隔指令與詢問 45
Prefer Exceptions to Returning Error Codes / 使用異常替代返回錯誤碼 46
Don’t Repeat Yourself / 別重複自己 48
Structured Programming / 結構化編程 48
How Do You Write Functions Like This / 如何寫出這樣的函式 49
Conclusion / 小結 49
SetupTeardownIncluder / SetupTeardownIncluder 程式 50
Bibliography / 文獻 52
Chapter 4: Comments / 注釋 53
Comments Do Not Make Up for Bad Code /注釋不能美化糟糕的代碼 55
Explain Yourself in Code / 用代碼來闡述 55
Good Comments / 好注釋 55
Bad Comments / 壞注釋 59
Bibliography / 文獻 74
Chapter 5: Formatting/ 75
The Purpose of Formatting / 格式的目的 76
Vertical Formatting / 垂直格式 76
Horizontal Formatting / 橫向格式 85
Team Rules / 團隊規則 90
Uncle Bob’s Formatting Rules / “鮑勃大叔”的格式規則 90
Chapter 6: Objects and Data Structures / 對象和數據結構 93
Data Abstraction / 數據抽象 93
Data/Object Anti-Symmetry / 數據、對象的反對稱性 95
The Law of Demeter / 得墨忒耳律 97
Data Transfer Objects / 數據傳送對象 100
Conclusion / 小結 101
Bibliography / 文獻 101
Chapter 7: Error Handling / 錯誤處理 103
Use Exceptions Rather Than Return Codes / 使用異常而非返回碼 104
Write Your Try-Catch-Finally Statement First /
先寫try-catch-finally 語句 105
Use Unchecked Exceptions / 使用未檢異常 106
Provide Context with Exceptions / 給出異常發生的環境說明 107
Define Exception Classes in Terms of a Caller’s Needs /
依調用者需要定義異常類 107
Define the Normal Flow / 定義常規流程 109
Don’t Return Null / 別返回null 值 110
Don’t Pass Null / 別傳遞null 值 111
Conclusion / 小結 112
Bibliography / 文獻 112
Chapter 8: Boundaries / 邊界 113
Using Third-Party Code / 使用第三方代碼 114
Exploring and Learning Boundaries / 瀏覽和學習邊界 116
Learning log4j / 學習log4j 116
Learning Tests Are Better Than Free /
學習性測試的好處不只是免費 118
Using Code That Does Not Yet Exist / 使用尚不存在的代碼 118
Clean Boundaries / 整潔的邊界 120
Bibliography / 文獻 120
Chapter 9: Unit Tests / 單元測試 121
The Three Laws of TDD / TDD 三定律 122
Keeping Tests Clean / 保持測試整潔 123
Clean Tests / 整潔的測試 124
One Assert per Test / 每個測試一個斷言 130
F.I.R.S.T. 132
Conclusion / 小結 133
Bibliography / 文獻 133
Chapter 10: Classes / 類 135
Class Organization / 類的組織 136
Classes Should Be Small! / 類應該短小 136
Organizing for Change / 為了修改而組織 147
Bibliography / 文獻 151
Chapter 11: Systems / 系統 153
How Would You Build a City / 如何建造一個城市 154
Separate Constructing a System from Using It /
將系統的構造與使用分開 154
Scaling Up / 擴容 157
Java Proxies / Java 代理 161
Pure Java AOP Frameworks / 純Java AOP 框架 163
AspectJ Aspects / AspectJ 的方面 166
Test Drive the System Architecture / 測試驅動系統架構 166
Optimize Decision Making / 最佳化決策 167
Use Standards Wisely, When They Add Demonstrable Value /
明智使用添加了可論證價值的標準 168
Systems Need Domain-Specific Languages /
系統需要領域特定語言 168
Conclusion / 小結 169
Bibliography / 文獻 169
Chapter 12: Emergence / 迭進 171
Getting Clean via Emergent Design / 通過迭進設計達到整潔目的 171
Simple Design Rule 1: Runs All the Tests /
簡單設計規則1:運行所有測試 172
Simple Design Rules 2?C4: Refactoring / 簡單設計規則2~4:重構 172
No Duplication / 不可重複 173
Expressive / 表達力 175
Minimal Classes and Methods / 儘可能少的類和方法 176
Conclusion / 小結 176
Bibliography / 文獻 176
Chapter 13: Concurrency / 並發編程 177
Why Concurrency / 為什麼要並發 178
Challenges / 挑戰 180
Concurrency Defense Principles / 並發防禦原則 180
Know Your Library / 了解Java 庫 182
Know Your Execution Models / 了解執行模型 183
Beware Dependencies Between Synchronized Methods /
警惕同步方法之間的依賴 185
Keep Synchronized Sections Small / 保持同步區域微小 185
Writing Correct Shut-Down Code Is Hard /
很難編寫正確的關閉代碼 186
Testing Threaded Code / 測試執行緒代碼 186
Conclusion / 小結 190
Bibliography / 文獻 191
Chapter 14: Successive Refinement / 逐步改進 193
Args Implementation / Args 的實現 194
Args: The Rough Draft / Args:草稿 201
String Arguments / 字元串類型參數 214
Conclusion / 小結 250
Chapter 15: JUnit Internals / JUnit 內幕 251
The JUnit Framework / JUnit 框架 252
Conclusion / 小結 265
Chapter 16: Refactoring SerialDate / 重構SerialDate 267
First, Make It Work / 首先,讓它能工作 268
Then Make It Right / 讓它做對 270
Conclusion / 小結 284
Bibliography / 文獻 284
Chapter 17: Smells and Heuristics / 味道與啟發 285
Comments / 注釋 286
Environment / 環境 287
Functions / 函式 288
General / 一般性問題 288
Java 307
Names / 名稱 309
Tests / 測試 313
Conclusion / 小結 314
Bibliography / 文獻 315
Appendix A: Concurrency II / 並發編程II 317
Appendix B: org.jfree.date.SerialDate 349
Appendix C: Cross References of Heuristics / 啟發式交叉參考 409
Epilogue / 結束語 411
顯示部分信息

作者簡介

[美] 羅伯特·C. 馬丁(Robert C. Martin):軟體開發大師,設計模式和敏捷開發先驅,敏捷聯盟首任主席,C++ Report前主編,被後輩程式設計師尊稱為“Bob大叔”。20世紀70年代初成為職業程式設計師,後創辦Object Mentor公司並任總裁。Martin還是一名多產的作家,至今已發表數百篇文章、論文和部落格文章。除本書外,還著有《代碼整潔之道:程式設計師的職業素養》《敏捷軟體開發:原則、模式和實踐》《UML:Java程式設計師指南》等。

相關詞條

熱門詞條

聯絡我們