CSE 403 Lecture 17 Coding.

Slides:



Advertisements
Similar presentations
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Advertisements

Recitation By yzhuang, sseshadr. Agenda Debugging practices – GDB – Valgrind – Strace Errors and Wrappers – System call return values and wrappers – Uninitialization.
An Empirical Study of the Reliability in UNIX Utilities Barton Miller Lars Fredriksen Brysn So Presented by Liping Cai.
Debugging Mohammad Zikky, M.T. 2 Debugging Introduction (1 of 2)  Debugging is methodical process for removing mistakes in a program  So important,
1 Java Programming Basics SE-1011 Dr. Mark L. Hornick.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
Debugging CPSC 315 – Programming Studio Fall 2008.
. Compilation / Pointers Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
B-1 Lecture 2: Problems, Algorithms, and Programs © 2000 UW CSE University of Washington Computer Programming I.
Guidelines for working with Microsoft Visual Studio.Net.
Guidelines for working with Microsoft Visual Studio 6.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
. Memory Management. Memory Organization u During run time, variables can be stored in one of three “pools”  Stack  Static heap  Dynamic heap.
Program Input and the Software Design Process ROBERT REAVES.
Debugger Presented by 李明璋 2012/05/08. The Definition of Bug –Part of the code which would result in an error, fault or malfunctioning of the program.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
C Programming - Lecture 6 This lecture we will learn: –Error checking in C –What is a ‘wrappered function’? –What is a clean interface? –How to earn your.
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?
1 Debugging. 2 A Lot of Time is Spent Debugging Programs Debugging. Cyclic process of editing, compiling, and fixing errors. n Always a logical explanation.
1 Debugging: Catching Bugs ( II ) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
DEBUGGING. BUG A software bug is an error, flaw, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected.
Introduction to Exception Handling and Defensive Programming.
Exceptions and assertions CSE 331 University of Washington.
CacheLab Recitation 7 10/8/2012. Outline Memory organization Caching – Different types of locality – Cache organization Cachelab – Tips (warnings, getopt,
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
CSE1222: Lecture 6The Ohio State University1. Common Mistakes with Conditions (1)  Consider the following code: int age(26); if (age = 18) { cout
Debugging and Profiling With some help from Software Carpentry resources.
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
CSE 332: C++ Statements C++ Statements In C++ statements are basic units of execution –Each ends with ; (can use expressions to compute values) –Statements.
Today’s Topics O-Notation Testing/Debugging Data Structures Next Class: Writing correct programs:Column 4.
(c) University of Washington10-1 CSC 143 Java Errors and Exceptions Reading: Ch. 15.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
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.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
1 ENERGY 211 / CME 211 Lecture 14 October 22, 2008.
Software Engineering Algorithms, Compilers, & Lifecycle.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Lecture 3 – MapReduce: Implementation CSE 490h – Introduction to Distributed Computing, Spring 2009 Except as otherwise noted, the content of this presentation.
Chapter 13 Recursion Copyright © 2016 Pearson, Inc. All rights reserved.
CSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools
Testing and Debugging.
The Pseudocode Programming Process
CSE 403 Software Engineering
Kernel Tracing David Ferry, Chris Gill
gdb gdb is the GNU debugger on our CS machines.
The C “switch” Statement
CSE341: Programming Languages Section 1
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
CNG 140 C Programming (Lecture set 8)
CSE 403 Lecture 18 Debugging.
Debugging at Scale.
When your program crashes
Homework Any Questions?.
Robust Coding and Debugging
An Introduction to Debugging
COP 3330 Object-oriented Programming in C++
Robust Coding and Debugging
Chapter 13 Recursion Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
debugging, bug finding and bug avoidance Part 4
Chapter 15 Debugging.
Defensive Programming
Presentation transcript:

CSE 403 Lecture 17 Coding

Step through your code Maguire Knuth Step through new code in the debugger the first time it is used Add code, set break points, run debugger Add code, run tests, if failure, run debugger Knuth Developed tool to print out first two executions of every line of code

Candy machine interfaces Error prone return values or arguments Classic bad example, getchar() returns an int! Alternate approach bool fGetChar(char pch); Many bugs with malloc returning NULL char c; c = getchar(); If (c == EOF) …

Another coding quiz char tolower(char ch){ }

Handling out of range inputs Ignore Return error code Assert Redefine the function to do something reasonable Write functions that, given valid inputs, cannot fail

Code tuning Don't overestimate cost A true story A heated debate on whether to code a key function in Excel in assembly or C The difference was 12 cycles Eventually an engineer instrumented the three hour Excel torture test, and found that this function was called 76,000 times The net savings was . . .

Efficiency gains Algorithmic improvement Resource usage O(n log n) sorting vs. O(n2) sorting Resource usage File write vs. Memory write Inner loop of key routine [Knuth] 4% of code uses 50% of runtime

Efficiency Avoid recomputation Cache results int foo(int n){ if (n < 0 || n >= fooCache.Length) throw new Exception(“Foo err”); if (inCache[n]) return fooCache[n]; else { fooCache[n] = computerFoo(n); inCache[n] = true; } r1 = (-b + sqrt(b*b – 4*a*c) ) / (2*a); r2 = (-b - sqrt(b*b – 4*a*c) ) / (2*a); q = sqrt(b*b – 4*a*c); r1 = (-b + q) / (2*a); r2 = (-b – q) / (2*a);

Efficiency Reductions in strength if (sqrt(x) < sqrt(y))…

Efficiency Memory management Even in Java / C# Preallocating/reusing large objects Buffer pool

Efficiency vs. Clarity Almost always favor clarity over efficiency The human reader is more important Compilers and processors have improved significantly in the last four decades

Debugging What are the key steps in debugging a program?

Kernigan and Pike's debugging wisdom Look for common patterns Common bugs have distinct signatures int n; scanf("%d", n); Examine most recent change Don't make the same mistake twice Debug it now, not later Get a stack trace Read before typing

K & P, II Explain your code to someone else Make the bug reproducible Divide and conquer Find simplest failing case Display output to localize your search Debugging with printf() Write self checking code Keep records