IEEE Published by the IEEE Computer Society IEEE SOFTWARE  design Editor Mar     IEEE Published by the IEEE Computer Society IEEE SOFTWARE  design Editor Mar

IEEE Published by the IEEE Computer Society IEEE SOFTWARE design Editor Mar - PDF document

yoshiko-marsland . @yoshiko-marsland
Uploaded On 2014-10-06

IEEE Published by the IEEE Computer Society IEEE SOFTWARE design Editor Mar - PPT Presentation

00 57513 2004 IEEE Published by the IEEE Computer Society IEEE SOFTWARE 21 design Editor Martin Fowler ThoughtWorks 57345 fowleracmorg he most annoying aspect of software de velopment for me is debugging ID: 2952

57513 2004 IEEE Published




Download Presentation from below link

Download Pdf The PPT/PDF document " IEEE Published by the IEEE Computer ..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

Presentation Transcript

IEEE SOFTWARE ThoughtWorks velopment, for me, is debugging. I donÕthate are the ter hours of successful operation, underunusual circumstances, or whose stack tracesFortunately, thereÕs a simple technique thatwill dramatically reduce the number of thesebugs in your software. It wonÕt re-least not at first, but itÕll makemost defects much easier to find. The technique is to build yoursoftware to Òfail fast.ÓSome people recommend mak-ing your software robust by work-ing around problems automatically.This results in the software Òfailing slowly.Óerror but fails in strange ways later on. posite: when a problem occurs, it fails imme-diately and visibly. Failing fast is a nonintuitivefragile, but it actually makes it more robust.Bugs are easier to find and fix, so fewer go intoa property from a configuration file. Whatshould happen when the property isnÕt pre-sent? A common approach is to return string property = if (property == null) {return property.toInt();In contrast, a program that fails fast willstring property = if (property == null) {(maxConnections property not return property.toInt();Imagine this method is part of a Web-basedsystem thatÕs undergoing a minor upgrade. In thisrelease, letÕs say the developer accidentally intro-duces a typo in the configuration file, triggeringthe error-handling code. For the code that returns null reference exception occurs, how can I maketell us where the problem is. For example, Javacases, the exceptionÕs stack trace will lead us tothe source of the problem, as in this example: Here, tracing backwards through the stack2). The answerÕs not always obvious, but afew minutes of digging will find it.which doesnÕt help at all (see Figure 3). The realItÕs this latter case that I want to prevent. Ineed the program to give me enough informa-tion to find bugs easily. So for my code, IÕve in-donÕt do anything special about null references(see Figure 4a). However, when I assign a pa-wonÕt fail fast without my help, so I assert thatThis rule of thumb could be helpful foryour programs, too, but the main point here isthe thought process I went through. Whenadding assertions to your code, follow a lineence exceptions. Think about what kinds ofdefects are possible and how they occur. Placeyour assertions so that the software fails ear-IEEE SOFTWARE Figure 3. A stack trace that leads to a dead end (C#) 1public class Example3public static void Main()5FancyConsole out = new FancyConsole();6out.WriteTitle(textŽ);10public class FancyConsole()11{12private const screenWidth = 80;13private string _titleBorder;15public FancyConsole()16{17_titleBorder = getProperty(titleBorderŽ);18}20public void WriteTitle(string text)21{22int borderSize = (screenWidth … text.Length) /(_titleBorder.Length * 2);23 string border = Ž;24for (int i = 0; i )25{26border += _titleBorder;27}28Console.WriteLine(border + text + border);29}30} rule of thumb: (a) no assertion necessary and (b) assertion needed. public string toString(Object parameter) {public class Foo {private Object _instanceVariable; global exception handler to gracefully handleunexpected exceptions, such as assertions, andbring them to the developersÕ attention. For ex-ample, a GUI-based program might displayin an error dialog and provide an option toemail tech support. A batch-processing systemtinue with the next transaction (see Figure 5 forIf you use a global exception handler, avoidcatch-all exception handlers in the rest of yourapplication. TheyÕll prevent exceptions fromreaching your global handler. Also, when youuse resources that have to be closed (such asblocks or statements (in C#) to clean them up. This way,if an exception occurs, the application will bereturned to a fresh, working state.buggingÕs cost, and pain, significantly. Furthermore, itÕs a technique you can startusing right away. Be sure to implement aglobal error handler so your overall stabilitydoesnÕt suffer. Search your existing code formore and more errors will fail fast, andyouÕll see the cost of debugging decrease andthe quality of your system improve.Jim Shoreis the founder of Titanium I.T., a Portland, Ore., consultancyspecializing in helping software teams work more effectively. Contact him at IEEE SOFTWARE INDUSTRY STANDARDS www.computer.org/standards/ HELP SHAPE FUTURE TECHNOLOGIES  JOIN AN IEEE COMPUTER SOCIETY STANDARDS WORKING GROUP AT IEEEComputer Society members work together to define standards like IEEE 802, 1003, 1394, 1284, and many more.802.11FireWiretoken ringswireless networksenhanced parallel ports