logo资料库

The Pragmatic Programmer: From Journeyman to Master.pdf

第1页 / 共324页
第2页 / 共324页
第3页 / 共324页
第4页 / 共324页
第5页 / 共324页
第6页 / 共324页
第7页 / 共324页
第8页 / 共324页
资料共324页,剩余部分请下载后查看
Pragmatic Programmer, The: From Journeyman to Master Andrew Hunt David Thomas Publisher: Addison Wesley First Edition October 13, 1999 ISBN: 0-201-61622-X, 352 pages Straight from the programming trenches, The Pragmatic Programmer cuts through the increasing specialization and technicalities of modern software development to examine the core process--taking a requirement and producing working, maintainable code that delights its users. It covers topics ranging from personal responsibility and career development to architectural techniques for keeping your code flexible and easy to adapt and reuse. Read this book, and you’ll learn how to: Fight software rot; Avoid the trap of duplicating knowledge; Write flexible, dynamic, and adaptable code; Avoid programming by coincidence; Bullet-proof your code with contracts, assertions, and exceptions; Capture real requirements; Test ruthlessly and effectively; Delight your users; Build teams of pragmatic programmers; and Make your developments more precise with automation. Written as a series of self-contained sections and filled with entertaining anecdotes, thoughtful examples, and interesting
analogies, The Pragmatic Programmer illustrates the best practices and major pitfalls of many different aspects of software development. Whether you’re a new coder, an experienced programmer, or a manager responsible for software projects, use these lessons daily, and you’ll quickly see improvements in personal productivity, accuracy, and job satisfaction. You’ll learn skills and develop habits and attitudes that form the foundation for long-term success in your career. You’ll become a Pragmatic Programmer.
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
分享到:
收藏