The Practice of Programming 由Kernighan和Pike编著,成书于上个世纪(1999年)。年代看似有些久远,但该书讨论的是一些很难过时的话题,就像我们今天还在讨论2000多年前“孔孟之道”和“孙子兵法”一样,12年后的今天,我们再次读起The Practice of Programming ,仍没有感觉到一丝腐朽的气味。从内容上看,该书几乎囊括了程序员深有感触的各种问题,对于很多彷徨的程序员来说,这绝对是一贴切中要害的良药。全书主要采用C++/Java作为范例语言,但丝毫不影响其他语言的爱好者以此作为升级读本。《程序设计实践(评注版)》力邀国内资深专家执笔,在英文原著基础上增加中文点评与注释。
The Practice of Programming针对程序设计过程中的风格、算法与数据结构、设计与实现、界面、除错、测试、性能、可移植性、记法等各个方面,系统地讨论了一些常见问题和实用技巧。通过对Brian W. Kernighan、Rob Pike所著的《程序设计实践(评注版)》的学习,读者可以快速掌握程序设计的技巧及思想。
《程序设计实践(评注版)》力邀国内资深专家执笔,在英文原著基础上增加中文点评与注释,旨在融合二者之长,既保留经典的原创文字与味道,又以先行者的学研心得与实践感悟,对读者阅读与学习加以点拨、指明捷径。
前言(新增批注共1条) xii
Chapter 1: Style(新增批注共46条) 1
1.1 Names 3
1.2 Expressions and Statements 7
1.3 Consistency and Idioms 13
1.4 Function Macros 21
1.5 Magic Numbers 23
1.6 Comments 28
1.7 Why Bother? 35
Chapter 2: Algorithms and Data Structures(新增批注共29条) 37
2.1 Searching 38
2.2 Sorting 41
2.3 Libraries 44
2.4 A Java Quicksort 48
2.5 O-Notation 52
2.6 Growing Arrays 54
2.7 Lists 57
2.8 Trees 64
2.9 Hash Tables 70
2.10 Summary 74
Chapter 3: Design and Implementation(新增批注共12条) 76
3.1 The Markov Chain Algorithm 77
3.2 Data Structure Alternatives 79
3.3 Building the Data Structure in C 81
3.4 Generating Output 85
3.5 Java 89
3.6 C++ 93
3.7 Awk andPerl 97
3.8 Performance 99
3.9 Lessons 101
Chapter 4: Interfaces(新增批注共20条) 104
4.1 Comma-Separated Values 105
4.2 A Prototype Library 107
4.3 A Library for Others 111
4.4 A C++ Implementation 121
4.5 Interface Principles 126
4.6 Resource Management 130
4.7 Abort, Retry, Fail? 135
4.8 User Interfaces 140
Chapter 5: Debugging(新增批注共28条) 144
5.1 Debuggers 146
5.2 Good Clues, Easy Bugs 148
5.3 No Clues, Hard Bugs 153
5.4 Last Resorts 160
5.5 Non-reproducible Bugs 164
5.6 Debugging Tools 166
5.7 Other People’s Bugs 169
5.8 Summary 171
Chapter 6: Testing(新增批注共28条) 173
6.1 Test as You Write the Code 174
6.2 Systematic Testing 181
6.3 Test Automation 186
6.4 Test Scaffolds 189
6.5 Stress Tests 193
6.6 Tips for Testing 197
6.7 Who Does the Testing? 199
6.8 Testing the Markov Program 200
6.9 Summary 202
Chapter 7: Performance(新增批注共30条) 204
7.1 A Bottleneck 205
7.4 Tuning the Code 221
7.5 Space Efficiency 228
7.6 Estimation 231
7.7 Summary 234
Chapter 8: Portability(新增批注共30条) 236
8.1 Language 237
8.2 Headers and Libraries 245
8.3 Program Organization 247
8.4 Isolation 252
8.5 Data Exchange 254
8.6 Byte Order 256
8.7 Portability and Upgrade 259
8.8 Internationalization 262
8.9 Summary 266
Chapter 9: Notation(新增批注共13条) 269
9.1 Formatting Data 270
9.2 Regular Expressions 278
9.3 Programmable Tools 286
9.4 Interpreters, Compilers, and Virtual Machines 289
9.5 Programs that Write Programs 296
9.6 Using Macros to Generate Code 300
9.7 Compiling on the Fly 301
Epilogue 308
Appendix: Collected Rules 311
Index 315