碼農(nóng)修行:編寫優(yōu)雅代碼的32條法則
定 價:99 元
- 作者:林文 著
- 出版時間:2020/8/1
- ISBN:9787111660392
- 出 版 社:機械工業(yè)出版社
- 中圖法分類:TP311.52
- 頁碼:280
- 紙張:
- 版次:
- 開本:16開
如何打造精品軟件一直是軟件行業(yè)討論的熱點話題。初入職場的軟件開發(fā)人員,多數(shù)都只是在學會了某種編程語言后就直接進行編程工作。但由于他們并未掌握編程中的一些有效方法,導致其開發(fā)的軟件問題累累且工作效率不高。碼農(nóng)修行 編寫優(yōu)雅代碼的32條法則針對這類人群提出了一些改善編程方法的建議,涉及具體編程工作的諸多方面,偏重于實踐。書中大部分示例都是筆者實際編程工作中碰到過的真實案例,具有較高的參考價值。碼農(nóng)修行 編寫優(yōu)雅代碼的32條法則從代碼的可讀性、可靠性、效率、可維護性、可擴展性5個方面,提出了編寫代碼的32 條法則。此外還公開了筆者自主編寫的一款Android 小游戲源代碼,希望能對讀者有所幫助。
碼農(nóng)修行 編寫優(yōu)雅代碼的32條法則適用于有一定編程基礎(chǔ)、且想進一步提升個人編程能力的讀者閱讀,也可作為大中專院校計算機專業(yè)師生的教學參考用書。
自序
前言
引子 ···································································································· 1
第1 章:可讀性 ························································································· 4
法則01:準確命名 ·············································································· 6
法則02:設(shè)置縮進 ············································································ 12
法則03:保留個性 ············································································ 16
法則04:語法潛臺詞 ········································································ 21
法則05:補充注釋 ············································································ 26
第2 章:可靠性 ······················································································· 37
法則06:增強健壯性 ········································································ 39
法則07:避免過度防御 ···································································· 43
法則08:防止不確定性 ···································································· 48
法則09:善始善終 ············································································ 51
法則10:異常處理 ············································································ 59
法則11:留意編譯告警 ···································································· 65
法則12:盡早暴露問題 ···································································· 67
法則13:規(guī)避短板 ············································································ 70
第3 章:效率 ··························································································· 75
法則14:關(guān)注性能熱點 ···································································· 77
法則15:留意非熱點代碼 ································································· 84
法則16:采用緩存 ············································································ 90
法則17:引入并發(fā) ············································································ 99
第4 章:可維護性 ················································································· 102
法則18:記錄日志 ·········································································· 104
法則19:明確錯誤提示 ·································································· 109
法則20:代碼看護 ·········································································· 112
法則21:消除冗余代碼 ·································································· 117
法則22:掌握邏輯運算 ·································································· 123
法則23:控制函數(shù)規(guī)模 ·································································· 128
法則24:控制文件規(guī)模 ·································································· 140
第5 章:可擴展性 ················································································· 143
法則25:正確理解面向?qū)ο笤O(shè)計 ···················································· 145
法則26:控制接口規(guī)模 ·································································· 155
法則27:寫可重用的模塊 ······························································· 160
法則28:寫可重入的函數(shù) ······························································· 164
法則29:避免循環(huán)依賴 ·································································· 169
法則30:保障平穩(wěn)升級 ·································································· 176
法則31:靈活注入對象 ·································································· 182
法則32:正確運用依賴注入 ··························································· 194
第6 章:代碼資源 ················································································· 200
日志框架 ························································································· 201
進程委托調(diào)用框架··········································································· 208
花樣泡泡龍 ····················································································· 215
尾聲 ······································································································· 267