Scientific Debugging. Errors in Software Errors are unexpected behaviors or outputs in programs As long as software is developed by humans, it will contain.

Slides:



Advertisements
Similar presentations
Formal Methods and Testing Goal: software reliability Use software engineering methodologies to develop the code. Use formal methods during code development.
Advertisements

What is Science?.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
Programming Types of Testing.
The Scientific Method.
Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the five essential properties of an algorithm.
Chapter 10 Algorithmic Thinking. Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Learning Objectives List the five essential.
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
Expert System Human expert level performance Limited application area Large component of task specific knowledge Knowledge based system Task specific knowledge.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
Exit A key to the successful Science Fair Project A key to the successful Science Fair Project Goal The Researcher’s Strategy Results Method Hypothesis.
1 Data Structures A program solves a problem. A program solves a problem. A solution consists of: A solution consists of:  a way to organize the data.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Critical Thinking Skills and Doing Science Elements of the scientific method: 1.Observe patterns 2. Ask questions 3. Formulate hypotheses that make specific.
CODING Research Data Management. Research Data Management Coding When writing software or analytical code it is important that others and your future.
Dr. Pedro Mejia Alvarez Software Testing Slide 1 Software Testing: Building Test Cases.
How can you find a supported answer to an investigative question?
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
1 Shawlands Academy Higher Computing Software Development Unit.
University of Palestine software engineering department Testing of Software Systems Fundamentals of testing instructor: Tasneem Darwish.
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.
1.3: Scientific Thinking & Processes Key concept: Science is a way of thinking, questioning, and gathering evidence.
Invitation to Computer Science, Java Version, Second Edition.
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
SCIENTIFIC METHOD THE STEPS.
Big Idea 1: The Practice of Science Description A: Scientific inquiry is a multifaceted activity; the processes of science include the formulation of scientifically.
Chapter 2 Section 1. Objectives Be able to define: science, scientific method, system, research, hypothesis, experiment, analysis, model, theory, variable,
Scientific Inquiry & Skills
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
1 Science as a Process Chapter 1 Section 2. 2 Objectives  Explain how science is different from other forms of human endeavor.  Identify the steps that.
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.
Science Fair How To Get Started… (
Debugging Strategies from Software Carpentry. Agan's Rules Many people make debugging harder than it needs to be by: Using inadequate tools Not going.
CMPT 880/890 The Scientific Method. MOTD The scientific method is a valuable tool The SM is not the only way of doing science The SM fits into a larger.
Biological Science.
11/8/2015 Nature of Science. 11/8/2015 Nature of Science 1. What is science? 2. What is an observation? 3. What is a fact? 4. Define theory. 5. Define.
Science is a process. It is a systematic process. The goal of the process is to gain understanding of how nature and the physical world work.
Lesson Overview Lesson Overview What Is Science? Lesson Overview 1.1 What Is Science?
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
The Software Development Process
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Scientific Methods and Terminology. Scientific methods are The most reliable means to ensure that experiments produce reliable information in response.
Review of the Scientific Method Chapter 1. Scientific Method – –Organized, logical approach to scientific research. Not a list of rules, but a general.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
Lesson Overview Lesson Overview What Is Science? Lesson Overview 1.1 What Is Science?
Concurrency Properties. Correctness In sequential programs, rerunning a program with the same input will always give the same result, so it makes sense.
The Scientific Method: How to solve just about anything.
Software Quality Assurance and Testing Fazal Rehman Shamil.
Methods of Scientific Inquiry Ch 1.3 Course Overview.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
1.3: Scientific Thinking & Processes Key concept: Science is a way of thinking, questioning, and gathering evidence.
Chapter 1 What is Biology? 1.1 Science and the Natural World.
Testing and Debugging. Testing Fundamentals  Test as you develop Easier to find bugs early rather than later Prototyping helps identify problems early.
Hypothesis, Theory, or Law. All-Write-Consensus 1.Read the information on your piece of paper. 2.On a separate sheet of paper, answer the question on.
Steps of The Scientific Method 1.Purpose/Question (Why we are doing the experiment) 2.Background Information (What do we already know that will help us)
Research Methods in Psychology Introduction to Psychology.
What is Research?. Intro.  Research- “Any honest attempt to study a problem systematically or to add to man’s knowledge of a problem may be regarded.
Scientific Method. Steps in the Scientific Method  Observation  Hypothesis  Experiment  Data Collection  Conclusion  Retest.
CHAPTER 3 - THE SCIENTIFIC PROCESS 3.1 Inquiry & The Scientific Method pp
Recursion Topic 5.
Testing and Debugging PPT By :Dr. R. Mall.
Scientific Method: Science is ultimately based on observation (perceiving objects or events using one of the five senses) Observations often lead to questions.
Computer Programming.
Problem Solving Techniques
Mr. Morris Physical Science
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
The Research Process & Surveys, Samples, and Populations
Presentation transcript:

Scientific Debugging

Errors in Software Errors are unexpected behaviors or outputs in programs As long as software is developed by humans, it will contain potential errors

Typical methods of debugging Typically our approach to debugging is very scattered, and we learn primarily from experience. The more bugs we encounter, the more quickly we can debug. For most programmers, sourcing and systematically solving problems is challenging Debugging intuition is not easy for many developers, and can’t be relied on

Our approach to errors We can choose to see errors as independent frustrations We can assume everyone has the same intuition regarding debugging, but this proves unrealistic A smarter technique is approaching all errors from a scientific perspective Scientists approach problems with the scientific method Programmers are capable of approaching errors with a similar approach To do this we have to consider errors a natural phenomena

Scientific Debugging method - simplified approach 1. Observe a failure 2. Create a hypothesis for cause of failure based on observations 3. Use hypothesis to make predictions 4. If the experiment satisfies the predictions, refine or limit the hypothesis 5. If the experiment does not satisfy predictions, create a new hypothesis 6. Repeat 3,4,5 as needed until further refining is not possible Eventually we will arrive at a cause for the software failure

What is a theory? In informal speech, the word theory is sometimes confused with a “good guess” In a scientific context, a theory is a rigorously tested hypothesis attempts to explain past observations makes testable claims about future observations In scientific debugging, theories are proven causes of software failure

Shell Sort revisited

Shell Sort debugging example - 1 For shell sort, we will note the following: Hypothesis - The Sample program works Prediction - Attempting to sort the collection “11 14” will result in “11 14” Experiment - Run sample on given input Observation - the rejected output is “0 11” Conclusion - rejected hypothesis

Shell Sort debugging example - 2 For our new hypothesis, let’s try restricting to a simpler case. Hypothesis - our array start index, a[0] will stay 0 Prediction - If we insert a breakpoint in our debugger at 37, a[0] is 0. Experiment - Run sample with a[0] as 0 Observation - the correct output is 0 Conclusion - supported hypothesis Continuing down this trend, we can observe more stringent hypotheses and reach our final theory Maintaining this approach of systematic checking will ensure consistent debugging

Explicit Debugging Scientific Debugging tests hypotheses which are explicitly stated Explicit in this case means problems are well defined and documented When debugging, developers often keep error notes in their mind of the problems This is an enormous mistake because we are human, and humans are forgetful much harder to see patterns emerge coworkers can’t help you nearly well enough Organizing thoughts in and of itself is useful It becomes vital once we have multi-layered issues “Writing bugs” only useful when organized

Explicit Debugging One solution: keep a logbook Useful because: we avoid relying on own memory there is a permanent record of bug solutions, in case similar bugs occur in other software it’s easier finding related errors (multiple errors with a single fix)

Algorithmic Debugging Try to automate the process of debugging Walk through execution of a program Observe current state and values Follow valid input until it “breaks” Stop when we transition from valid -> invalid Can be thought of as a “tree” of execution states

Insertion Sort Example - Algorithmic

Example: Algorithmic Debugging Sort([2,1,3]) == [3,1,2]? no → first check left execution path

Example: Algorithmic Debugging Sort([3]) == [3] ? yes → mark OK, check other path

Example: Algorithmic Debugging Insert(1,[3]) != [3,1] → algorithmic debugger marks invalid

Scientific Debugging - Pros and Cons Scientific Debugging is very helpful when: the software is designed as small modular parts for easier separate testing our program performs a linear procedure of instructions it is easy to tell the difference between “unfinished” and “bad” answers our output is easy to parse and test mission critical software needs testing Not as helpful when: “unfinished” and “bad” output are very similar, and confuse our debugging method we have very convoluted data structures we perform several datatype conversions which break many types of testing we combine multiple languages in a single piece of software

Obtaining a Hypothesis - Understanding the Problem In order to use scientific debugging, we have to arrive at meaningful hypotheses There are a handful of tools to do this to help narrow our effective results There are several key ingredients of debugging:

Hypothesis Formation - Problem Description A problem you cannot clearly describe is a problem you cannot clearly solve “Shell sort doesn’t work on input [2,1,3]” is not a useful description Observing that shell sort fails once we call insert() is useful Problem reports and problem tracking are vital to narrowing problem scope

Hypothesis Formation - Program Code It is intuitive that programmers should know their code in order to debug it However this becomes very difficult for large projects reliant on others’ work Important to keep in mind when relying on libraries and external projects as well For our shell sort example, would have been impossible to see insert() problem

Hypothesis Formation - Earlier Hypotheses One other crucial rule to keep in mind is hypothesis refinement When we update a hypothesis: Include earlier hypotheses that passed Exclude earlier hypotheses that failed Future hypotheses must also keep track of prior observations

Reasoning about Programs - using Deduction Deduction is reasoning that moves from the general to the particular These take the form of mathematical proofs If these abstractions of our program are true, so are properties we can deduce This technique is useful because it doesn’t require running the program If we don’t run the program, it is static analysis If we use deduction but also test against execution, it is a dynamic analysis In general static attempts to predict the future dynamic holds onto values from the past It’s also difficult because abstracting our program can be challenging

Reasoning about Programs - using Observation Observation is a dynamic method dynamic: requires execution of program for testing take in facts from execution majority of these methods also look at program code so they usually include deduction There are multiple different kinds of observational methods including: Inductive methods Experimental methods Deductive methods (if using dynamic deduction) All use information about the past to use for debugging solutions

Reasoning about Programs: using Induction Reasoning from particular to general (unlike deduction) Attempt to summarize multiple runs through formal inductive proof 1. Start with base case for program input (for shell sort, sort a single element) 2. Attempt to show that if it works for n inputs, 3. It will also work for n+1 inputs This requires multiple executions to test, so induction is also dynamic All inductive methods are also observational because they are dependent on observing output of multiple runs

Reasoning about Programs - using Experimentation Searching for a failure through experiments constantly refining and updating a hypothesis this reduces our hypotheses to a theory Based on multiple program runs, so also dynamic each run is guided by a specific experiment to narrow the hypotheses In general, experimentation techniques are so named if: they generate findings from multiple runs these runs are controlled by some hypothesis or test