What others in the trenches say about The Pragmatic Programmer... “The cool thingabout this book is that it’s great for keeping the programming process fresh. [Thebook] helps you to continue to grow and clearly comes from people who have been there.” KentBeck, author of ExtremeProgramming Explained: Embrace Change “I found this book to be a great mix of solid advice and wonderful analogies!” MartinFowler, author of Refactoring and UMLDistilled “I would buy a copy, read it twice, then tell all my colleagues to run out and graba copy. This isa book Iwould never loan because Iwould worryabout it being lost.” KevinRuland, Management Science, MSG-Logistics “The wisdom and practical experience of the authors is obvious. The topics presented are relevant and useful... . By far its greatest strengthfor me has been the outstanding analogies—tracer bullets, broken windows, and the fabulous helicopter-based explanation of the need for orthogonality, especially in a crisis situation. I have little doubt that this book will eventually become an excellent source of useful informationfor journeymen programmers and expert mentors alike.” JohnLakos, author of Large-Scale C++Software Design “This is the sort of book I will buy a dozen copies of when it comes out so I can give it to my clients.” EricVought, Software Engineer “Most modern books on software development fail to cover the basics of what makes a great softwaredeveloper, instead spending their time on syntax or technology where in realitythe greatest leverage possible for any software team is in having talented developers who really know their craft well. An excellent book.” PeteMcBreen, Independent Consultant “Since reading this book, I have implemented many of the practical suggestions and tipsit contains. Across theboard, they have saved my company time and money while helping me get my job done quicker! This should be a desktop referencefor everyone who works with code for a living.” JaredRichardson, Senior SoftwareDeveloper, iRenaissance, Inc. “I would like to see this issued to every new employee at my company... .” ChrisCleeland, Senior SoftwareEngineer, Object Computing, Inc. The Pragmatic Programmer This page intentionally left blank The Pragmatic Programmer From Journeyman to Master Andrew Hunt David Thomas ADDISON–WESLEY Animprintof AddisonWesley Longman, Inc. Reading,Massachusetts Harlow,England MenloPark,California Berkeley,California DonMills,Ontario Sydney Bonn Amsterdam Tokyo MexicoCity Manyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirproducts areclaimedastrademarks.Wherethosedesignationsappearinthisbook,andAddison– Wesley was aware of a trademark claim, the designations have been printed in initial capitallettersorinallcapitals. Lyricsfromthesong“TheBoxer”onpage157areCopyright c1968PaulSimon.Usedby permissionofthePublisher:PaulSimonMusic.Lyricsfromthesong“Alice’sRestaurant” onpage220arebyArloGuthrie, c1966,1967(renewed)by APPLESEEDMUSICINC.All RightsReserved.UsedbyPermission. The authors and publisher have taken care in the preparation of this book, but make no express or implied warranty of any kind and assume no responsibility for errors or omissions.Noliabilityisassumedforincidentalorconsequentialdamagesinconnection withorarisingoutoftheuseoftheinformationorprogramscontainedherein. The publisheroffers discountson this book whenordered inquantityfor specialsales. Formoreinformation,pleasecontact: AWLDirectSales AddisonWesleyLongman,Inc. OneJacobWay Reading,Massachusetts01867 (781)944-3700 VisitAWLontheWeb:www.awl.com/cseng LibraryofCongressCataloging-in-PublicationData Hunt,Andrew,1964– ThePragmaticProgrammer/AndrewHunt, DavidThomas. p. cm. Includesbibliographicalreferences. ISBN0-201-61622-X 1.Computerprogramming. I.Thomas,David,1956– . II.Title. QA76.6.H8571999 005.1--dc21 99–43581 CIP Copyright c 2000byAddisonWesleyLongman,Inc. Allrights reserved.No part of this publicationmay be reproduced, stored ina retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photo- copying,recording, or otherwise, without the prior written permission of the publisher. PrintedintheUnitedStatesofAmerica.PublishedsimultaneouslyinCanada. ISBN 0-201-61622-X Text printed in the United States on recycled paper at Courier Stoughton in Stoughton, Massachusetts. 25th Printing February 2010 ForEllieandJuliet, ElizabethandZachary, StuartandHenry This page intentionally left blank Contents FOREWORD xiii PREFACE xvii 1 A PRAGMATIC PHILOSOPHY 1 1. The Cat Ate My Source Code . . . . . . . . . . . . . . . . . 2 2. SoftwareEntropy. . . . . . . . . . . . . . . . . . . . . . . . 4 3. Stone Soup and Boiled Frogs. . . . . . . . . . . . . . . . . 7 4. Good-Enough Software . . . . . . . . . . . . . . . . . . . . 9 5. Your Knowledge Portfolio . . . . . . . . . . . . . . . . . . . 12 6. Communicate! . . . . . . . . . . . . . . . . . . . . . . . . . 18 2 A PRAGMATIC APPROACH 25 7. The Evils of Duplication . . . . . . . . . . . . . . . . . . . . 26 8. Orthogonality . . . . . . . . . . . . . . . . . . . . . . . . . . 34 9. Reversibility. . . . . . . . . . . . . . . . . . . . . . . . . . . 44 10. Tracer Bullets . . . . . . . . . . . . . . . . . . . . . . . . . 48 11. Prototypes and Post-it Notes . . . . . . . . . . . . . . . . . 53 12. Domain Languages . . . . . . . . . . . . . . . . . . . . . . 57 13. Estimating . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 3 THE BASIC TOOLS 71 14. The Power of Plain Text . . . . . . . . . . . . . . . . . . . . 73 15. Shell Games . . . . . . . . . . . . . . . . . . . . . . . . . . 77 16. Power Editing . . . . . . . . . . . . . . . . . . . . . . . . . . 82 17. Source Code Control. . . . . . . . . . . . . . . . . . . . . . 86 18. Debugging. . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 19. Text Manipulation . . . . . . . . . . . . . . . . . . . . . . . 99 20. Code Generators . . . . . . . . . . . . . . . . . . . . . . . . 102 ix