1 Defensive Programming and Debugging (Chapters 8 and 23 of Code Complete) Tori Bowman CSSE 375, Rose-Hulman September 21, 2007.

Slides:



Advertisements
Similar presentations
Automating Software Module Testing for FAA Certification Usha Santhanam The Boeing Company.
Advertisements

Compilation and Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
© The McGraw-Hill Companies, 2006 Chapter 15. © The McGraw-Hill Companies, 2006 Exceptions an exception is an event that occurs during the life of a program.
Software Construction 1 ( ) First Semester Dr. Samer Odeh Hanna (PhD) Office: IT 327.
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
© The McGraw-Hill Companies, 2006 Chapter 9 Software quality.
Debugging CPSC 315 – Programming Studio Fall 2008.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
COMP205 Comparative Programming Languages Part 1: Introduction to programming languages Lecture 3: Managing and reducing complexity, program processing.
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
Computer Science 340 Software Design & Testing Design By Contract.
Exceptions COMPSCI 105 S Principles of Computer Science.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Software Construction and Evolution - CSSE 375 Defensive Programming & Error Handling Shawn & Steve Above – As you see behind me on the shelf, there are.
What is Sure BDCs? BDC stands for Batch Data Communication and is also known as Batch Input. It is a technique for mass input of data into SAP by simulating.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
Windows Vista Inside Out Chapter 22 - Monitoring System Activities with Event Viewer Last modified am.
Errors And How to Handle Them. GIGO There is a saying in computer science: “Garbage in, garbage out.” Is this true, or is it just an excuse for bad programming?
How to Design Error Steady Code Ivaylo Bratoev Telerik Corporation
1 Software Construction and Evolution - CSSE 375 Exception Handling - Principles Steve Chenoweth, RHIT Above – Exception handling on the ENIAC. From
Introduction to Exception Handling and Defensive Programming.
Defensive Programming, Assertions and Exceptions Designing Fault-Resistant Code SoftUni Team Technical Trainers Software University
Computer Programming I Hour 2 - Writing Your First C Program.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/6/2006 Lecture 24 – Profilers.
Making Good Code AKA: So, You Wrote Some Code. Now What? Ray Haggerty July 23, 2015.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
The basics of the programming process The development of programming languages to improve software development Programming languages that the average user.
1 SEEM3460 Tutorial Compiling and Debugging C programs.
Defensive Programming, Assertions and Exceptions Designing Error Steady Code SoftUni Team Technical Trainers Software University
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
Intermediate 2 Computing Unit 2 - Software Development.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved. Chapter 4 Slide #1.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
Error Handling Tonga Institute of Higher Education.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Testing and Debugging. Testing Fundamentals  Test as you develop Easier to find bugs early rather than later Prototyping helps identify problems early.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
Outline Announcements: –HW I key online this afternoon –HW II due Friday –Sign up to discuss projects Debugging Testging for correctness.
C language + The Preprocessor. + Introduction The preprocessor is a program that processes that source code before it passes through the compiler. It.
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
Defensive Programming. Good programming practices that protect you from your own programming mistakes, as well as those of others – Assertions – Parameter.
1 Software Testing. 2 What is Software Testing ? Testing is a verification and validation activity that is performed by executing program code.
CS 5150 Software Engineering Lecture 21 Reliability 2.
Chapter 6 CS 3370 – C++ Functions.
Logger, Assert and Invariants
Defensive Programming
Testing and Debugging.
Coding Defensively Coding Defensively
Simple Steps to Resolve the QuickBooks Error Code 1317 Comprehensive solution, QuickBooks is known as one of the best accounting software available in.
Software Construction
Chapter 15 Debugging.
1. Open Visual Studio 2008.
Tonga Institute of Higher Education
Chapter 15 Debugging.
Error Handling.
Computer Science 340 Software Design & Testing
Conditional Compilation
Software Construction
Chapter 9: Implementation
Defensive Programming
Presentation transcript:

1 Defensive Programming and Debugging (Chapters 8 and 23 of Code Complete) Tori Bowman CSSE 375, Rose-Hulman September 21, 2007

What’s coming up?  What’s due  Defensive Programming and Debugging (this)  Project work 2

What’s due?  HW3 due 11:55 PM Monday  Please have read the following by Tuesday:     Come to class prepared to discuss your opinion on how open source software does or does not impact intellectual property. You will be expected to back up your opinion with examples/references from the above 3 articles. 3

4 Defensive Programming

5 What is Defensive Programming?  Like defensive driving  Main goal – protect yourself from bad data or other factors you cannot control  How can it be used in detailed design and implementation?

What to do with garbage?  “Garbage in, garbage out” (inappropriate for production code)  Check the values of all data from external sources  Check the values of all routine input parameters  Decide how to handle bad inputs 6

7 Defensive Programming Techniques  Assertions  Error handling  Code insertion for finding bad data  Note: These techniques can also be used elsewhere besides defensive programming

8 Assertions  Definition: code that’s used during development – usually a routine or macro – that allows a program to check itself as it runs  Assertions are intended to always be silent – only use for conditions that should never occur  Avoid putting executable code into assertions  Use to document/verify pre-/post-conditions

Error handling  Return a neutral value  Substitute the next valid data  Return previously valid data  Substitute closest “legal” value  Log a warning  Return an error code  Call an error-processing routine/object  Display an error message  Whatever is logical  Shutdown 9 **For errors you do expect to occur

10 Code insertion  Use this during development only Can be as simple as an output statement to a file or screen Advantage: independent of programming environment Preprocessing in C++ can help with this #define DEBUG. #if defined (DEBUG) // debugging code #endif

11 Defensive Programming and Production Code  Leave in code that Checks for important errors Helps the program crash gracefully  Remove code that Checks for trivial errors Hard crashes as a “signal” to testers  Log errors for technical support  Make error messages user-friendly

12 Defensive Programming Checklist  Pages of Code Complete  Sections General  Example: Protected from bad input data? Exceptions  Example: Did you avoid exceptions in constructors/destructors? Security Issues  Example: Do error messages avoid providing valuable info that can be used to break the system?

13 Debugging

Comic of the Day 14

15 Definition Debugging is the process of finding and fixing an error in code that was found through testing. *testing here is meant to include all forms

16 Benefits of Debugging  Debugging helps in: understanding the program understanding the types of errors you make (you can form a checklist to help find these errors earlier) in assessing readability and understandability of code

17 Debugging Process 1.Stabilize the error 2.Locate the source of an error 3.Fix the error 4.Test the fix 5.Look for similar errors 6. *Regression testing

18 Common Debugging Problems  Reading your own code can lead to you making assumptions about the code that you shouldn’t  Sometimes a fix is attempted without looking at the overall effect (regression testing helps here)  Sometimes a fix is attempted as a guess or without determining why the problem really occurred

19 Debugging Tools  GCC – must include debug options when compiling  Visual Studio 2005 Debugging Info  Note how debugging tools vary widely from application to application  However, debugging techniques do not change