Structured programming 4 Day 34 LING 681.02 Computational Linguistics Harry Howard Tulane University.

Slides:



Advertisements
Similar presentations
VCE SD Theory Slideshows By Mark Kelly Vceit.com Debugging Techniques.
Advertisements

Introduction to Recursion and Recursive Algorithms
Programming Types of Testing.
CS50 SECTION: WEEK 3 Kenny Yu. Announcements  Watch Problem Set 3’s walkthrough online if you are having trouble.  Problem Set 1’s feedback have been.
Debugging Introduction to Computing Science and Programming I.
General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009.
Debugging CPSC 315 – Programming Studio Fall 2008.
How to Debug VB .NET Code.
Quicksort
Computer Science 1620 Programming & Problem Solving.
Searching/Sorting Introduction to Computing Science and Programming I.
Programming Fundamentals (750113) Ch1. Problem Solving
Python quick start guide
Real World Programming BBrewer Fall Programming - Bellwork 1.Log on 2.Go to edmodo 3.Open & Save Vocabulary Graphic Organizer and Analaysis Document.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
COMPUTATION WITH STRINGS 4 DAY 5 - 9/05/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Introduction to Python
Programming. What is a Program ? Sets of instructions that get the computer to do something Instructions are translated, eventually, to machine language.
Chapter 13 Recursion. Topics Simple Recursion Recursion with a Return Value Recursion with Two Base Cases Binary Search Revisited Animation Using Recursion.
DEBUGGING CHAPTER Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
General Programming Introduction to Computing Science and Programming I.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
Testing CSE 140 University of Washington 1. Testing Programming to analyze data is powerful It’s useless if the results are not correct Correctness is.
1 ENERGY 211 / CME 211 Lecture 13 October 20, 2008.
Designing and Debugging Batch and Interactive COBOL Programs Chapter 5.
Text classification Day 35 LING Computational Linguistics Harry Howard Tulane University.
Python From the book “Think Python”
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
9/20/6Lecture 3 - Instruction Set - Al1 Program Design.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
CSIS 123A Lecture 9 Recursion Glenn Stevenson CSIS 113A MSJC.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
IB Computer Science Unit 5 – Advanced Topics Recursion.
Chapter 5 Files and Exceptions I. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. What is a file? A.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Week 14 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Software Development. Software Development Loop Design  Programmers need a solid foundation before they start coding anything  Understand the task.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
ALGORITHMS.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
CS 177 Week 10 Recitation Slides 1 1 Debugging. Announcements 2 2.
CompSci 100E 18.1 Testing and Debugging Robert A Wagner.
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
Flow of Control: Loops Module 4. Objectives Design a loop Use while, do, and for in a program Use the for-each with enumerations Use assertion checks.
Bugs CS100 how to prevent them, how to find them and how to terminate them.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
INTRO2CS Tirgul 8 1. Searching and Sorting  Tips for debugging  Binary search  Sorting algorithms:  Bogo sort  Bubble sort  Quick sort and maybe.
Today… Functions, Cont.: –Designing functions. –Functional Decomposition –Importing our own module –A demo: Functional solution to assignment 2. Winter.
Searching/Sorting. Searching Searching is the problem of Looking up a specific item within a collection of items. Searching is the problem of Looking.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion (Continued) Prof. Katherine Gibson Prof. Jeremy Dixon Based on slides from UPenn’s.
Introduction to Computing Science and Programming I
CMSC201 Computer Science I for Majors Lecture 20 – Recursion (Continued) Prof. Katherine Gibson Based on slides from UPenn’s CIS 110, and from previous.
14 Compilers, Interpreters and Debuggers
OBJECT ORIENTED PROGRAMMING II LECTURE 23 GEORGE KOUTSOGIANNAKIS
Testing and Debugging.
Quicksort
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
Tonga Institute of Higher Education
Coding Concepts (Basics)
Debugging at Scale.
Debugging Taken from notes by Dr. Neil Moore
Debugging Taken from notes by Dr. Neil Moore
Control 1 Day /30/16 LING 3820 & 6820 Natural Language Processing
Presentation transcript:

Structured programming 4 Day 34 LING Computational Linguistics Harry Howard Tulane University

16-Nov-2009LING , Prof. Howard, Tulane University2 Course organization 

Structured programming NLPP §4

16-Nov-2009LING , Prof. Howard, Tulane University4 Today's topics  Defensive programming  Debugging  Algorithm design

16-Nov-2009LING , Prof. Howard, Tulane University5 Defensive programming  Brainstorm with pseudo-code  Careful naming conventions  Bottom-up construction  Functional decomposition  Comment, comment, comment  Regression testing

16-Nov-2009LING , Prof. Howard, Tulane University6 Brainstorm with pseudo- code  Before you write the first line of Python code, write what your program does as pseudocode.  That is to say, before writing a program that NLTK understands, write it in a way that people understand.

16-Nov-2009LING , Prof. Howard, Tulane University7 An example of pseudo- code  SPOT, move forward about 10 inches, turn left 90 degrees, and start moving forward, then start looking for a black object with your ultrasonic sensor, because I want you to stop when you find a black object, then turn right 90 degrees, and move backward 2 feet, OK?  What is good or bad about this example

16-Nov-2009LING , Prof. Howard, Tulane University8 A different phrasing of the example  SPOT, move forward about 10 inches and stop.  Now turn left 90 degrees.  Start moving forward, and turn on your ultrasonic sensor.  Stop when you find a black object.  Turn right 90 degrees and stop.  Move backward 2 feet and stop.  What is good or bad about this example?

16-Nov-2009LING , Prof. Howard, Tulane University9 Pseudo and real code  The main advantage of the second phrasing is that we can match up the commands in each line to elements in the programming language.

16-Nov-2009LING , Prof. Howard, Tulane University10 Careful naming conditions  Choose meaningful variable and function names.

16-Nov-2009LING , Prof. Howard, Tulane University11 Bottom-up construction  Instead of writing a 20-line program and then testing it,  build and test smaller units,  and then combine them.  In general, these smaller units should be functions.

16-Nov-2009LING , Prof. Howard, Tulane University12 NLP pipeline Fig. 3.1

16-Nov-2009LING , Prof. Howard, Tulane University13 Commenting  Add comments to every line,  unless what a line is does is so obvious that a comment would get in the way.  Your pseudo-code could become the comments on your real code.

16-Nov-2009LING , Prof. Howard, Tulane University14 Regressive testing  Keep a suite of test cases.  As your program gets bigger, it should still work on previous test cases.  If it stops working, it has 'regressed'.  A change in code has the (unintended) side effect of breaking something that used to work.  doctest module does testing  It runs a program as if it were in interactive mode.  See doctest documentation.

16-Nov-2009LING , Prof. Howard, Tulane University15 Debugging topics  Check your assumptions  Exception > stack trace  Interactive debugging  Python's debugger  Prediction

16-Nov-2009LING , Prof. Howard, Tulane University16 Debugging  "Most code errors result from the programmer making incorrect assumptions". (NLPP:158)  When you find an error, first check your assumptions.  Add print statements to show  values of variables and  how far the program progresses.  Reduce input to smallest amount needed to cause the error.

16-Nov-2009LING , Prof. Howard, Tulane University17 Stack trace  A runtime error (Python exception) gives a stack trace that pinpoints the location of program execution at the time of the error.  But the error may actually be upstream.

16-Nov-2009LING , Prof. Howard, Tulane University18 Python's debugger  Invoke it:  import pdb  pdb.run('mymodule')  It lets you  monitor execution of program,  specify line numbers where program should stop (breakpoints), and  step through the sections of code inspecting values of variables.

16-Nov-2009LING , Prof. Howard, Tulane University19 Prediction  Try to predict the effect of a potential bugfix before re-running the program.  "If the bug isn't fixed, don't fall into the trap of blindly changing the code in the hope that it will magically start working again." (NLPP:159)  For each change, try to articulate what is wrong and how the change will fix the problem.  Undo the change if it doesn't work.  "Programs don't magically work; they magically don't work." (Robert Goldman)

Algorithm design NLPP 4.7

16-Nov-2009LING , Prof. Howard, Tulane University21 Algorithms  Divide and conquer  Start with something that works  Iteration  Recursion

16-Nov-2009LING , Prof. Howard, Tulane University22 Divide and conquer  Divide a problem of size n into two problems of size n/2.  Binary search - dictionary example.

16-Nov-2009LING , Prof. Howard, Tulane University23 Start with known  Transform task into something that already works.  To find duplicates in a list,  first sort the list,  then check for identity of adjacent pairs.

16-Nov-2009LING , Prof. Howard, Tulane University24 Iteration vs. recursion  For some function ƒ…  Iteration  Repeat ƒ some number of times.  Calling ƒ in a for loop.  Recursion  ƒ calls itself some number of times:  NP → the N PP.  PP → P NP.

Next time Start NLPP §6 Learning to classify text