Notes to Accompany Debugging Lecture. Jamie Blustein

Similar documents
BBC Learning English Face up to Phrasals Mark's Mistake

The Stack, Free Store, and Global Namespace

MITOCW watch?v=9h6muyzjms0

Slide 1 CS 170 Java Programming 1 Testing Karel

Manual Does Iphone 5 Apple Replace My Broken >>>CLICK HERE<<<

MITOCW watch?v=se4p7ivcune

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

Boot Camp. Dave Eckhardt Bruce Maggs

Promoting Component Architectures in a Dysfunctional Organization

Post Experiment Interview Questions

5 R1 The one green in the same place so either of these could be green.

Using Visual Studio.NET: IntelliSense and Debugging

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.

CSC 326H1F, Fall Programming Languages. What languages do you know? Instructor: Ali Juma. A survey of counted loops: FORTRAN

1 Getting used to Python

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

MITOCW ocw f99-lec07_300k

MITOCW watch?v=0jljzrnhwoi

CS3 Midterm 1 Fall 2006

Hi Bob, I got this from my colleagues near the end of last week and unfortunately lost track of it in my inbox to send you.

Remember, this question was mis-worded: you could also add quoted words and sentences in the blanks below. This allowed for a solution to [4] below.

Skill 1: Multiplying Polynomials

How Do I Lock My Iphone 4 Screen While On A Call

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;

mismatch between what is maybe possible today and what is going on in many of today's IDEs.

CS 170 Java Tools. Step 1: Got Java?

How to approach a computational problem

Slide 1 CS 170 Java Programming 1

MITOCW watch?v=zlohv4xq_ti

Instructor: Craig Duckett. Lecture 03: Tuesday, April 3, 2018 SQL Sorting, Aggregates and Joining Tables

The following content is provided under a Creative Commons license. Your support

Samsung Galaxy S3 Repair Video Calling Not Working

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3).

Chapter 8: User-Friendly Programming

It s possible to get your inbox to zero and keep it there, even if you get hundreds of s a day.

Instructor: Craig Duckett. Lecture 04: Thursday, April 5, Relationships

Spam. Time: five years from now Place: England

ESCAPE. A MINWOO PARK FILM Press Kit

(Refer Slide Time: 00:51)

How to Create a Killer Resources Page (That's Crazy Profitable)

B - Broken Track Page 1 of 8

Who am I? I m a python developer who has been working on OpenStack since I currently work for Aptira, who do OpenStack, SDN, and orchestration

Computer Security module

Slide 1 CS 170 Java Programming 1 Multidimensional Arrays Duration: 00:00:39 Advance mode: Auto

static CS106L Spring 2009 Handout #21 May 12, 2009 Introduction

SESSION 3 Programming Languages for Objects

CSE143 Notes for Monday, 4/25/11


15-122: Principles of Imperative Computation (Section G)

Errors. Lecture 6. Hartmut Kaiser hkaiser/fall_2011/csc1254.html

6.001 Notes: Section 6.1

Shared Variables and Interference

The following content is provided under a Creative Commons license. Your support

Basic Fiction Formatting for Smashwords in OpenOffice L. Leona Davis. Copyright 2012 L. Leona Davis All Rights Reserved

The following content is provided under a Creative Commons license. Your support

Chapter 5 Errors. Hyunyoung Lee. Based on slides by Bjarne Stroustrup.

WYBCS Android Programming (with AppInventor) Family fun day

Notes By: Shailesh Bdr. Pandey, TA, Computer Engineering Department, Nepal Engineering College

Laboratory 5: Implementing Loops and Loop Control Strategies

Contents. What's New. Upcoming new version. Newsletter #43 (Aug 6, 2017) A couple quick reminders:

Azon Master Class. By Ryan Stevenson Guidebook #5 WordPress Usage

(Refer Slide Time: 02.06)

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

CS Homework 10 p. 1. CS Homework 10

9.0 Help for End Users Release Notes Using Jive for Outlook...5

Windows 7 Will Not Install On My Computer Says I'm

The following content is provided under a Creative Commons license. Your support

Introduction to Object-Oriented Modelling and UML

Lecture 01 & 02 Computer Programming

Computer Science E-50a: Introduction to Computer Science Using Java, I Handout #7 part 2

mk-convert Contents 1 Converting to minikanren, quasimatically. 08 July 2014

Midterm Exam Solutions March 7, 2001 CS162 Operating Systems

CS 112 Project Basics

Using Jive for Outlook

MITOCW watch?v=sdw8_0rdzuw

Shared Variables and Interference

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5

Microsoft's latest OS is a lot better than its predecessor, but it still has some annoying quirks. We help you solve them.

Understanding C/C++ Strict Aliasing

How to Improve Your Campaign Conversion Rates

Lecture 1: Overview

How To Factory Reset Iphone 4 When Locked Out Without A Computer

How To Make 3-50 Times The Profits From Your Traffic

The SUMO Speaker Series for Undergraduates. The Art Gallery Problem

G52CPP C++ Programming Lecture 17

Lesson 4: Who Goes There?

This is an oral history interview conducted on. October 30, 2003, with IBM researcher Chieko Asakawa and IBM

Chapter 5 Errors. Bjarne Stroustrup

Lab 2: Conservation of Momentum

AHHHHHHH!!!! NOT TESTING! Anything but testing! Beat me, whip me, send me to Detroit, but don t make me write tests!

CSC148, Lab #4. General rules. Overview. Tracing recursion. Greatest Common Denominator GCD

MITOCW watch?v=flgjisf3l78

6.001 Notes: Section 15.1

APPENDIX B. Fortran Hints

Poulsen, Kevin Wednesday, November 07, :54 PM Singel, Ryan FW: [hush.com # ] Journalist's query

MITOCW watch?v=w_-sx4vr53m

Iphone 5 Headphones Buttons Not Working >>>CLICK HERE<<<

BCSWomen Android programming (with AppInventor) Family fun day World record attempt

Designing a Database -- Understanding Relational Design

Lab 1 Implementing a Simon Says Game

Transcription:

Notes to Accompany Debugging Lecture Jamie Blustein 28 April 2002

Introduction This lecture was originally written for Turbo Pascal, then updated for the rst ANSI C standard, then object-free C++. It does not address anything specic about object-oriented or real-time programming. I am condent that the general advice will apply well to those types of programming too. When you wrote your program you thought it would work, but now you've found that it doesn't. `What's wrong? How can you x it?' That's debugging. Debugging is not the same as xing syntax errors that prevent compilation. `The term originated with the rst tube computers': Talk about Grace Hopper and the moth (from 1947). [photo of moth] To Solve a Problem You Must Understand It Tracing the execution will help you to understand what is happening with your program. If you know which part is wrong then you can trace just that part. Clarity We call the written form of our program `code', as in dicult-to-understand. It must be written in a language that the computer can process but that does not mean that is has to be written so that we cannot understand it too. It is hard enough to read code when we think we know what we are instructing the computer to do. But especially when we know that the program doesn't work right then we need to have clear code and clear output. Always print to standard error Your output will appear `immediately' it won't get muddled up with some other output. If you use cout for debugging then you can be misled easily. Always print the function name See story about Bill (on page 4). 1

See also annotated example (on page 6). DEBUG levels Use larger numbers for more detail or for parts you think work now (but you don't want to remove the DEBUG code just in case you're wrong). Debuggers Debuggers can be mesmerizing. I've seen it happen. Programs will sometimes behave dierently in a debugger than in real-life. 2

There s never time... It sounds trite but it is true. Programmers will jump into writing a program or trying to x a broken one without thinking. You can save yourself much fruitless labour and frustration by planning ahead. The better your plan the less likely your program will be to fail and the more likely you'll be to x it if it does fail. 3

Trace Statements A true-life story My friend Bill didn't do this and spent 1 1 days debugging the wrong part of his 2 program. He was printing `Hi' or something to show when the ow-of-control had reached a statement. The problem was that he had two `Hi's in dierent parts of the program. He was seeing the second one { the rst was never reached. I found the problem in one minute by changing `Hi' to something more descriptive (`inner for loop' or something). Bill had to buy me lunch and I didn't even know the language he was programming in. If that technique can help a professional programmer save 1 1 days, think 2 how the power of debugging can help you. 4

An ounce of analysis... Another true-life tale I was in a computer lab working on a brutal assignment (a recursive BNF parser in Modula 2 don't ask, trust me it's not super easy) and the grader comes in every 2 or 3 hours to say that he's changing the assignment (again!). Never mind that is beyond his authority. Suce it to say that I was stressed and could not get my program to work right. By the way I was sitting beside a fellow who was also in the class. I'll call him Stu Dent (not his real name). Stu was a rower and had practice at 6 the next morning. Anyway, for some reason I noticed that the program was not due the next day but rather the day after that. It was late and I was tired. I printed a copy of my program took it with me and left. I slept. In the morning, I scribbled an outline of a correct program on a piece of paper, while I waited for my cereal to stop making noise. Then, on my printout I crossed o the lines that did not belong and added the ones that were missing. When I got back to school, Stu was at the same terminal he'd been there all night, and still didn't have a working program. I typed in my changes and it was perfect. Stu nished his a day later a 10% penalty and missed rowing practice. What's the moral of this true story? Not sleep whenever you have a problem but: work away from the computer screen it is too demanding and you can't see the whole program at once think about your program and what it should do get enough sleep sleep deprivation is a common torture technique (no joke)! Don't do it to yourself. It is very dicult to think clearly when you are so deprived. 5

int question(int left, int op, int right) { /* question() * PRE:... details omitted... * POST: The user has been prompted to enter... * RETURNS: 0 => they entered the wrong answer * 1 => they entered the right answer * -1 => something went wrong (bad op) * NOTES: Called by add(), divide(),... */ int answer; // the correct answer int guess; // what the user enters as the right answer if (DEBUG > 1) { cerr << "question(): called with left==" << left << "right==" << right << " op==" << op << endl; } switch(op) { case 1: answer = left + right; if (DEBUG) cerr << " question(): op says add " << endl; break; //... other cases omitted... // default: cerr << "ERROR In question(): impossible op " << "(op==" << op << ")" << endl; return -1; } // switch if (DEBUG) cerr << " question(): answer==" << answer << endl; //... code omitted... if (DEBUG > 1) cerr << endl << endl; return (guess == answer); } // question() 6