w thep18 - Debug It! - Find, Książki IT

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • lilyth.htw.pl
  • Podobne

     

    w thep18 - Debug It! - Find, Książki IT

    [ Pobierz całość w formacie PDF ]
    //-->Many of the designations used by manufacturers and sellers to distinguish their prod-ucts are claimed as trademarks. Where those designations appear in this book, and ThePragmatic Programmers, LLC was aware of a trademark claim, the designations havebeen printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, ThePragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linkinggdevice are trademarks of The Pragmatic Programmers, LLC.Every precaution was taken in the preparation of this book. However, the publisherassumes no responsibility for errors or omissions, or for damages that may result fromthe use of information (including program listings) contained herein.Our Pragmatic courses, workshops, and other products can help you and your teamcreate better software and have more fun. For more information, as well as the latestPragmatic titles, please visit us athttp://www.pragprog.comCopyright © 2009 Paul Butcher.All rights reserved.No part of this publication may be reproduced, stored in a retrieval system, or transmit-ted, in any form, or by any means, electronic, mechanical, photocopying, recording, orotherwise, without the prior consent of the publisher.Printed in the United States of America.ISBN-10: 1-934356-28-XISBN-13: 978-1-934356-28-9Printed on acid-free paper.B1.0 printing, June 17, 2009Version: 2009-6-16Chapter 3DiagnoseDiagnosis isthekey element of debugging. This is where the rubbermeets the road and you arrive at the understanding of the root causeof the behavior you’re seeing.In this chapter, we will cover:• The core diagnostic process.• Different types of experiment, and what makes a good experiment.• Useful stratagems.3.1 Stand Back—I’m Going to Try ScienceAlthough you’re going to be using various tools and techniques, andleveraging your software itself to help you, your primary asset is andalways will be your intellect. Diagnosis takes place within your mind,not within your computer.The mindset one needs to cultivate whendebugging is similar (because the problem isBalance creativity withsimilar) to that of a detective solving a crimerigoror a scientist investigating a new phenomenon.Open-minded at the same time as methodical, creative at the same timeas thorough—as with so many other aspects of software development,effective bug fixing is all about finding the appropriate balance betweenthese apparently contradictory demands.STANDBACK—I’MGOINGTOTRYSCIENCE50The scientific method can work in two different directions.1In onecase, we start with a hypothesis and attempt to create experiments,the results of which will either support or refute it. In the other, westart with an observation that doesn’t fit with our current theory andas a result modify that theory or possibly even replace it with somethingcompletely different.In debugging, we almost always start from the latter. Our theory (thatthe software behaves as we think it does) is disproved by an observa-tion (the bug) that demonstrates that we are mistaken. In the words ofThomas Huxley, “The great tragedy of Science—the slaying of a beauti-ful hypothesis by an ugly fact.”A Debugging MethodHaving discovered that things aren’t as you believed them to be, yourtask is to modify your understanding of the software until youdounderstand what’s really going on. To do that, you operate in the otherof the two possible directions—create a hypothesis that might providean explanation and then construct experiments to test it.So here’s our idealized process (see Figure3.1,on the next page):1. Examine what you know about the software’s behavior and con-struct a hypothesis about what might cause it.2. Design an experiment that will allow you to test its truth (or oth-erwise).3. If the experiment disproves your hypothesis, come up with a newone and start again.4. If it supports your hypothesis, keep coming up with experimentsuntil you have either disproved it, or reached a high enough levelof certainty to consider it proven.All well and good, but rather abstract. How do you translate this intoaction?Different Types of ExperimentYour starting point is the reproduction we discussed at length in thelast chapter. From that starting point, there are several different typesStudents of the History and Philosophy of Science will realize that I am skating overmany subtleties.1.CLICKHEREto purchase this book now.STANDBACK—I’MGOINGTOTRYSCIENCE51StartConstruct ahypothesisYesConstruct anexperimentHypothesisdisproved?YesNoNeed moreevidence?NoStopFigure 3.1: A Debugging MethodCLICKHEREto purchase this book now. [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • mement.xlx.pl
  • Designed by Finerdesign.com