实例介绍
【实例截图】
【核心代码】
Preface.......................................................................................................12 Who Should Read This Book?...............................................................12 What Makes a Pragmatic Programmer?..............................................13 Individual Pragmatists, Large Teams..................................................14 It's a Continuous Process......................................................................15 How the Book Is Organized ..................................................................15 What's in a Name? ................................................................................15 Source Code and Other Resources ....................................................16 Send Us Feedback..............................................................................16 Acknowledgments..............................................................................16 What's in a Name? ................................................................................18 Source Code and Other Resources ....................................................18 Send Us Feedback..............................................................................18 Acknowledgments..............................................................................19 The Cat Ate My Source Code................................................................19 Take Responsibility ...........................................................................20 Related sections include:................................................................21 Challenges ......................................................................................21 Software Entropy ..................................................................................21 Putting Out Fires...............................................................................22 Related sections include: ...................................................................23 Challenges..........................................................................................23 Stone Soup and Boiled Frogs................................................................23 The Villagers' Side.............................................................................24 Related sections include:................................................................25 Challenges ......................................................................................25 Good-Enough Software .........................................................................25 Involve Your Users in the Trade-Off ................................................26 Know When to Stop ...........................................................................26 Related sections include:................................................................27 Challenges ......................................................................................27 Your Knowledge Portfolio .....................................................................27 Your Knowledge Portfolio..................................................................28 Building Your Portfolio......................................................................28 Goals...................................................................................................29 Opportunities for Learning ...............................................................30 Critical Thinking ...............................................................................30 Care and Cultivation of Gurus.................................................................30 Challenges ......................................................................................31 Communicate!........................................................................................31 Know What You Want to Say............................................................32 Know Your Audience .........................................................................32 Figure 1.1. The wisdom acrostic—understanding an audience ...32 Choose Your Moment.........................................................................33 Choose a Style....................................................................................33 Make It Look Good ............................................................................33 Involve Your Audience.......................................................................34 Be a Listener......................................................................................34 Get Back to People.............................................................................34 E-Mail Communication.............................................................................34 Summary ...............................................................................................35 Related sections include: ...................................................................35 Challenges..........................................................................................35 Chapter 2. A Pragmatic Approach ...........................................................37 The Evils of Duplication........................................................................37 How Does Duplication Arise?............................................................38 Imposed Duplication..........................................................................39 Inadvertent Duplication ....................................................................40 Impatient Duplication .......................................................................42 Interdeveloper Duplication ...............................................................42 Related sections include:................................................................43 Orthogonality ........................................................................................43 What Is Orthogonality? .....................................................................43 A Nonorthogonal System ...............................................................44 Benefits of Orthogonality ..................................................................44 Gain Productivity...........................................................................45 Reduce Risk ....................................................................................45 Project Teams ....................................................................................45 Design.................................................................................................46 Figure 2.1. Typical layer diagram .................................................46 Toolkits and Libraries .......................................................................47 Coding ................................................................................................48 Testing................................................................................................49 Documentation...................................................................................49 Living with Orthogonality.................................................................49 Related sections include:................................................................50 Challenges ......................................................................................50 Exercises ............................................................................................50 Reversibility ..........................................................................................51 Reversibility.......................................................................................51 Flexible Architecture .........................................................................52 Related sections include:................................................................53 Challenges ......................................................................................53 Tracer Bullets........................................................................................53 Code That Glows in the Dark............................................................54 Tracer Bullets Don't Always Hit Their Target.................................56 Tracer Code versus Prototyping........................................................56 Related sections include:................................................................57 Prototypes and Post-it Notes ................................................................57 Things to Prototype ...........................................................................58 How to Use Prototypes ......................................................................58 Prototyping Architecture...................................................................59 How Not to Use Prototypes ...............................................................59 Related sections include:................................................................60 Exercises ............................................................................................60 Domain Languages................................................................................60 Domain-Specific Errors ............................................................................62 Implementing a Mini-Language .......................................................62 Data Languages and Imperative Languages................................63 Figure 2.2. Windows .rc file ...........................................................63 Stand-Alone and Embedded Languages .......................................65 Easy Development or Easy Maintenance?....................................65 Related sections include:................................................................65 Challenges ......................................................................................65 Exercises ............................................................................................66 Estimating .............................................................................................66 How Accurate Is Accurate Enough?..................................................67 Where Do Estimates Come From? ....................................................68 Understand What's Being Asked ..................................................68 Build a Model of the System..........................................................68 Break the Model into Components................................................68 Give Each Parameter a Value .......................................................69 Calculate the Answers ...................................................................69 Keep Track of Your Estimating Prowess ......................................69 Estimating Project Schedules ...........................................................70 What to Say When Asked for an Estimate .......................................70 Related sections include:................................................................70 Challenges ......................................................................................70 Exercises ............................................................................................71 Chapter 3. The Basic Tools.......................................................................72 The Power of Plain Text........................................................................73 What Is Plain Text?...........................................................................73 Drawbacks..........................................................................................74 The Power of Text..............................................................................74 Insurance Against Obsolescence ...................................................74 Leverage .........................................................................................75 The Unix Philosophy.................................................................................75 Easier Testing ................................................................................76 Lowest Common Denominator..........................................................76 Related sections include:................................................................76 Challenges ......................................................................................76 Shell Games...........................................................................................77 Shell Utilities and Windows Systems...............................................79 Using Unix Tools Under Windows...........................................................79 Related sections include:................................................................80 Challenges ......................................................................................80 Power Editing........................................................................................80 One Editor..........................................................................................80 Editor Features..................................................................................81 Productivity........................................................................................82 Figure 3.1. Sorting lines in an editor ............................................82 Where to Go from Here......................................................................82 What Editors Are Available?.............................................................83 Challenges ......................................................................................83 Source Code Control..............................................................................83 Source Code Control and Builds .......................................................85 But My Team Isn't Using Source Code Control...................................85 Source Code Control Products ..............................................................85 Related sections include: ...................................................................85 Challenges..........................................................................................85 Debugging..............................................................................................86 Psychology of Debugging...................................................................86 A Debugging Mindset ........................................................................87 Where to Start ...................................................................................87 Debugging Strategies ........................................................................88 Bug Reproduction .....................................................................................88 Visualize Your Data.......................................................................88 Figure 3.2. Sample debugger diagram of a circular linked list. The arrows represent pointers to nodes. ..............................................89 Tracing............................................................................................89 Corrupt Variables? Check Their Neighborhood ......................................90 Rubber Ducking .............................................................................90 Process of Elimination ...................................................................90 The Element of Surprise ...................................................................91 Debugging Checklist..........................................................................92 Related sections include:................................................................92 Challenges ......................................................................................92 Text Manipulation.................................................................................93 Related sections include: ...................................................................95 Exercises................................................................................................95 Code Generators....................................................................................95 Passive Code Generators...................................................................96 Active Code Generators.....................................................................97 Figure 3.3. Active code generator creates code from a database schema ............................................................................................97 Figure 3.4. Generating code from a language-neutral representation. In the input file, lines starting with 'M' flag the start of a message definition, 'F' lines define fields, and 'E' is the end of the message. ........................................................................98 Code Generators Needn't Be Complex..............................................98 Code Generators Needn't Generate Code .........................................98 Related sections include:................................................................98 Exercises ............................................................................................99 Chapter 4. Pragmatic Paranoia..............................................................100 Design by Contract..............................................................................101 DBC ..................................................................................................101 DBC and Constant Parameters..............................................................102 Implementing DBC..........................................................................104 Assertions .....................................................................................104 Language Support........................................................................105 DBC and Crashing Early ................................................................105 Who's responsible?..................................................................................105 Other Uses of Invariants.................................................................106 Loop Invariants............................................................................106 Semantic Invariants.....................................................................107 Dynamic Contracts and Agents ......................................................108 Related sections include:..............................................................108 Challenges ....................................................................................108 Exercises ..........................................................................................108 Dead Programs Tell No Lies...............................................................110 Crash, Don't Trash ..........................................................................110 Related sections include:..............................................................111 Assertive Programming ......................................................................111 Leave Assertions Turned On...........................................................113 Assertion and Side Effects......................................................................113 Related sections include:..............................................................114 Exercises ..........................................................................................114 When to Use Exceptions .....................................................................114 What Is Exceptional?.......................................................................115 Error Handlers Are an Alternative.................................................116 Related sections include:..............................................................117 Challenges ....................................................................................117 Exercises ..........................................................................................117 How to Balance Resources ..................................................................117 Nest Allocations...............................................................................120 Objects and Exceptions .......................................................................120 Balancing and Exceptions...................................................................121 Balancing Resources with C Exceptions ....................................121 Balancing Resources in Java...........................................................122 When You Can't Balance Resources...................................................123 Checking the Balance..........................................................................123 Related sections include: .................................................................124 Challenges........................................................................................124 Exercises..............................................................................................124 Chapter 5. Bend or Break.......................................................................125 Decoupling and the Law of Demeter ..................................................125 Minimize Coupling ..........................................................................126 The Law of Demeter for Functions .................................................127 Figure 5.1. Law of Demeter for functions ...................................127 Does It Really Make a Difference?..................................................128 Physical Decoupling................................................................................128 Related sections include:..............................................................129 Challenges ....................................................................................129 Exercises ..........................................................................................129 Metaprogramming...............................................................................130 Dynamic Configuration ...................................................................130 Metadata-Driven Applications........................................................131 Business Logic..............................................................................132 When to Configure ..................................................................................132 An Example: Enterprise Java Beans..............................................133 Cooperative Configuration...........................................................133 Don't Write Dodo-Code....................................................................134 Related sections include:..............................................................134 Challenges ....................................................................................134 Exercises ..........................................................................................134 Temporal Coupling..............................................................................134 Workflow ..........................................................................................135 Figure 5.2. UML activity diagram: making a piña colada .........136 Architecture .....................................................................................137 Figure 5.3. OLTP architecture overview.....................................137 Design for Concurrency ...................................................................138 Cleaner Interfaces........................................................................138 Deployment ......................................................................................140 Related sections include:..............................................................140 Challenges ....................................................................................140 It's Just a View....................................................................................140 Publish/Subscribe ............................................................................141 Figure 5.4. Publish/subscribe protocol ........................................141 Model-View-Controller ....................................................................142 The CORBA Event Service.....................................................................142 Java Tree View.............................................................................143 Beyond GUIs....................................................................................144 Figure 5.5. Baseball reporting, Viewers subscribe to models. ...145 Still Coupled (After All These Years) .............................................146 Related sections include:..............................................................146 Exercises ..........................................................................................146 Blackboards .........................................................................................146 Figure 5.6. Someone found a connection between Humpty's gambling debts and the phone logs. Perhaps he was getting threatening phone calls. ..............................................................147 Blackboard Implementations..........................................................148 Organizing Your Blackboard..................................................................148 Application Example .......................................................................149 Related sections include:..............................................................150 Challenges ....................................................................................150 Exercises ..........................................................................................150 Chapter 6. While You Are Coding..........................................................151 Programming by Coincidence .............................................................151 How to Program by Coincidence .....................................................152 Accidents of Implementation.......................................................152 Accidents of Context.....................................................................153 Implicit Assumptions...................................................................153 How to Program Deliberately..........................................................154 Related sections include:..............................................................154 Exercises ..........................................................................................155 Algorithm Speed..................................................................................155 What Do We Mean by Estimating Algorithms? .............................155 The O() Notation..............................................................................156 Figure 6.1. Runtimes of various algorithms ...............................156 Common Sense Estimation .............................................................157 Algorithm Speed in Practice............................................................158 Best Isn't Always Best .................................................................159 Related sections include:..............................................................159 Challenges ....................................................................................160 Exercises ..........................................................................................160 Refactoring ..........................................................................................160 When Should You Refactor?............................................................161 Real-World Complications ...........................................................162 How Do You Refactor?.....................................................................162 Automatic Refactoring............................................................................163 Related sections include:..............................................................163 Exercises ..........................................................................................164 Code That's Easy to Test.....................................................................165 Unit Testing.....................................................................................165 Testing Against Contract ................................................................166 Writing Unit Tests...........................................................................167 Using Test Harnesses......................................................................169 Ad Hoc Testing........................................................................................169 Build a Test Window .......................................................................170 A Culture of Testing ........................................................................171 Related sections include:..............................................................171 Exercises ..........................................................................................172 Evil Wizards ........................................................................................172 Related sections include: .................................................................173 Challenges........................................................................................173 Chapter 7. Before the Project .................................................................174 The Requirements Pit .........................................................................174 Digging for Requirements ...............................................................175 Documenting Requirements............................................................176 Sometimes the Interface Is the System .................................................176 Figure 7.1. Cockburn's use case template...................................177 Figure 7.2. A sample use case......................................................178 Use Case Diagrams......................................................................179 Figure 7.3. UML use cases—so simple a child could do it!.........180 Overspecifying .................................................................................180 Seeing Further.................................................................................180 Just One More Wafer-Thin Mint….................................................181 Maintain a Glossary ........................................................................181 Get the Word Out ............................................................................182 Related sections include:..............................................................182 Challenges ....................................................................................182 Exercises ..........................................................................................182 Solving Impossible Puzzles.................................................................183 Degrees of Freedom .........................................................................183 There Must Be an Easier Way!.......................................................184 Challenges........................................................................................185 Not Until You're Ready.......................................................................185 Good Judgment or Procrastination? ...............................................186 Challenges ....................................................................................186 The Specification Trap ........................................................................187 Related sections include: .................................................................188 Challenges........................................................................................189 Circles and Arrows..............................................................................189 Do Methods Pay Off? .......................................................................190 Should We Use Formal Methods?...................................................190 Related sections include:..............................................................191 Challenges ....................................................................................191 Chapter 8. Pragmatic Projects ...............................................................192 Pragmatic Teams ................................................................................192 No Broken Windows ........................................................................193 Boiled Frogs .....................................................................................193 Communicate ...................................................................................193 Don't Repeat Yourself......................................................................194 Orthogonality...................................................................................194 Automation ......................................................................................196 Know When to Stop Adding Paint ..................................................196 Related sections include:..............................................................196 Challenges ....................................................................................196 Ubiquitous Automation.......................................................................197 All on Automatic..............................................................................197 Compiling the Project ......................................................................198 Generating Code...........................................................................198 Regression Tests...........................................................................199 Recursive make.......................................................................................199 Build Automation ............................................................................199 Final Builds..................................................................................200 Automatic Administrivia.................................................................200 Web Site Generation ....................................................................200 Approval Procedures....................................................................201 The Cobbler's Children....................................................................201 Related sections include:..............................................................201 Challenges ....................................................................................202 Ruthless Testing..................................................................................202 What to Test.....................................................................................203 Unit Testing .................................................................................203 Integration Testing ......................................................................204 Validation and Verification .........................................................204 Resource Exhaustion, Errors, and Recovery...............................204 Performance Testing....................................................................205 Usability Testing..........................................................................205 Look at usability in terms of human factors. Were there any miIt's All Writing.................................................................................................205 Comments in Code...........................................................................206 Executable Documents ....................................................................208 What if My Document Isn't Plain Text? ................................................208 Technical Writers ............................................................................209 Print It or Weave It .........................................................................209 Markup Languages..........................................................................210 Related sections include:..............................................................210 Challenges ....................................................................................211 How to Test ......................................................................................211 Design/Methodology Testing ..................................................................211 Regression Testing.......................................................................212 Test Data ......................................................................................212 Exercising GUI Systems ..............................................................213 Testing the Tests..........................................................................213 Testing Thoroughly......................................................................214 When to Test....................................................................................214 Tightening the Net ..........................................................................215 Related sections include:..............................................................215 Challenges ....................................................................................215 Great Expectations..............................................................................216 Communicating Expectations .........................................................216 The Extra Mile.................................................................................217 Related sections include:..............................................................217 Challenges ....................................................................................218 Pride and Prejudice.............................................................................218 Appendix A. Resources ...........................................................................220 Professional Societies..........................................................................220 Building a Library...............................................................................221 Periodicals........................................................................................221 Weekly Trade Papers.......................................................................221 Books ................................................................................................221 Analysis and Design ........................................................................222 Teams and Projects..........................................................................222 Specific Environments.....................................................................222 The Web ...........................................................................................223 Internet Resources ..............................................................................223 Editors..............................................................................................223 Emacs ...............................................................................................223 [URL l] The Emacs Editor ...........................................................223 [URL 2] The XEmacs Editor........................................................224 vi.......................................................................................................224 [URL 3] The Vim Editor...............................................................224 [URL 4] The elvis Editor..............................................................224 [URL 5] Emacs Viper Mode .........................................................224 Compilers, Languages, and Development Tools ............................224 [URL 6] The GNU C/C Compiler.............................................224 [URL 7] The Java Language from Sun .......................................224 [URL 8] Perl Language Home Page ............................................225 [URL 9] The Python Language....................................................225 [URL 10] SmallEiffel....................................................................225 [URL 11] ISE Eiffel......................................................................225 [URL 12] Sather ...........................................................................225 [URL 13] VisualWorks.................................................................225 [URL 14] The Squeak Language Environment ..........................225 [URL 15] The TOM Programming Language .............................226 [URL 16] The Beowulf Project.....................................................226 [URL 17] iContract—Design by Contract Tool for Java.............226 [URL 18] Nana—Logging and Assertions for C and C ...........226 [URL 19] DDD–Data Display Debugger .....................................226 [URL 20] John Brant's Refactoring Browser ..............................226 [URL 21 ] DOC Documentation Generator.............................226 [URL 22] xUnit–Unit Testing Framework..................................227 [URL 23] The Tcl Language ........................................................227 [URL 24] Expect—Automate Interaction with Programs ..........227 [URL 25] T Spaces........................................................................227 [URL 26] javaCC—Java Compiler-Compiler ..............................227 [URL 27] The bison Parser Generator ........................................227 [URL 28] SWIG—Simplified Wrapper and Interface Generator228 [URL 29] The Object Management Group, Inc...........................228 Unix Tools Under DOS....................................................................228 [URL 30] The UWIN Development Tools....................................228 [URL 31 ] The Cygnus Cygwin Tools ..........................................228 [URL 32] Perl Power Tools ..........................................................228 Source Code Control Tools ..............................................................229 [URL 33] RCS—Revision Control System...................................229 [URL 34] CVS—Concurrent Version System..............................229 [URL 35] Aegis Transaction-Based Configuration Management ......................................................................................................229 [URL 36] ClearCase .....................................................................229 [URL 37] MKS Source Integrity..................................................229 [URL 38] PVCS Configuration Management..............................229 [URL 39] Visual SourceSafe ........................................................229 [URL 40] Perforce.........................................................................229 Other Tools.......................................................................................230 [URL 41] WinZip—Archive Utility for Windows ........................230 [URL 42] The Z Shell ...................................................................230 [URL 43] A Free SMB Client for Unix Systems .........................230 Papers and Publications..................................................................230 [URL 44] The comp.object FAQ...................................................230 [URL 45] eXtreme Programming ................................................230 [URL 46] Alistair Cockburn's Home Page...................................231 [URL 47] Martin Fowler's Home Page........................................231 [URL 48] Robert C. Martin's Home Page....................................231 [URL 49] Aspect-Oriented Programming....................................231 [URL 50] JavaSpaces Specification.............................................231 [URL 51] Netscape Source Code..................................................231 [URL 52] The Jargon File............................................................231 [URL 53] Eric S. Raymond's Papers............................................232 [URL 54] The K Desktop Environment.......................................232 [URL 55] The GNU Image Manipulation Program ....................232 [URL 56] The Demeter Project ....................................................232 Miscellaneous...................................................................................232 [URL 57] The GNU Project..........................................................232 [URL 58] Web Server Information ..............................................232 Bibliography ........................................................................................234 Appendix B. Answers to Exercises.........................................................237
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论