Chapter 9: Building Bigger Programs

Similar documents
Selecting Features by Attributes in ArcGIS Using the Query Builder

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0

Python Loops and String Manipulation

For Introduction to Java Programming, 5E By Y. Daniel Liang

Chapter 13: Program Development and Programming Languages

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall

Introduction to Python

Hypercosm. Studio.

Tips and Tricks SAGE ACCPAC INTELLIGENCE

r-one Python Setup 1 Setup 2 Using IDLE 3 Using IDLE with your Robot ENGI 128: Introduction to Engineering Systems Fall, 2014

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

Simply Accounting Intelligence Tips and Tricks Booklet Vol. 1

Exercise 4 Learning Python language fundamentals

Testing Rails. by Josh Steiner. thoughtbot

How to test and debug an ASP.NET application

Advanced Programming with LEGO NXT MindStorms

Introduction to Python

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Python Documentation & Startup

Chapter 13: Program Development and Programming Languages

Hands-on Exercise 1: VBA Coding Basics

TESTING FRAMEWORKS. Gayatri Ghanakota

The first program: Little Crab

Before you can use the Duke Ambient environment to start working on your projects or

Visual Logic Instructions and Assignments

Kids College Computer Game Programming Exploring Small Basic and Procedural Programming

PHP Debugging. Draft: March 19, Christopher Vickery

2 The first program: Little Crab

Software Development. Topic 1 The Software Development Process

What is a workflow? Workflows are a series of actions that correspond to a work process

Creating Basic Excel Formulas

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

Creating a Simple Macro

Automatic promotion and versioning with Oracle Data Integrator 12c

Moving from CS 61A Scheme to CS 61B Java

10 Listing data and basic command syntax

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Chapter 1: Key Concepts of Programming and Software Engineering

Calc Guide Chapter 9 Data Analysis

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Chapter 2 Writing Simple Programs

Week 2 Practical Objects and Turtles

format or just checking for errors we recommend doing this process online using XLSform.

Line Tracking Basic Lesson

Course Title: Software Development

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

DesignBuilder EMS - Intro

Computer Programming In QBasic

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

Setting Up a Windows Virtual Machine for SANS FOR526

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Fireworks 3 Animation and Rollovers

Access 2010: Creating Queries Table of Contents INTRODUCTION TO QUERIES... 2 QUERY JOINS... 2 INNER JOINS... 3 OUTER JOINS...

What's New in ADP Reporting?

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Iteration CHAPTER 6. Topic Summary

Comparing RTOS to Infinite Loop Designs

The Center for Teaching, Learning, & Technology

Software Requirement Specification for Web Based Integrated Development Environment. DEVCLOUD Web Based Integrated Development Environment.

Downloading Audiobooks with Overdrive from the Marion Public Library

2 SQL in iseries Navigator

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Automating with ID Works SDK

Silect Software s MP Author

GCE. Computing. Mark Scheme for January Advanced Subsidiary GCE Unit F452: Programming Techniques and Logical Methods

6. Control Structures

MiVoice Integration for Salesforce

Athena Knowledge Base

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Whisler 1 A Graphical User Interface and Database Management System for Documenting Glacial Landmarks

Using SAS to Control and Automate a Multi SAS Program Process. Patrick Halpin November 2008

A. Grouping to Obtain Counts

Programming in Access VBA

Desktop, Web and Mobile Testing Tutorials

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Coveo Platform 7.0. Microsoft Dynamics CRM Connector Guide

VB.NET Programming Fundamentals

Compute Cluster Server Lab 3: Debugging the parallel MPI programs in Microsoft Visual Studio 2005

CS101 Lecture 24: Thinking in Python: Input and Output Variables and Arithmetic. Aaron Stevens 28 March Overview/Questions

Xcode User Default Reference. (Legacy)

Access Queries (Office 2003)

Using Karel with Eclipse

Personal Geodatabase 101

Company Setup 401k Tab

Eliminate Memory Errors and Improve Program Stability

APPROACHES TO SOFTWARE TESTING PROGRAM VERIFICATION AND VALIDATION

ESKITP5023 Software Development Level 3 Role

Getting Started with Command Prompts

REXX-like Macro Language for UNIX and Windows

mouse (or the option key on Macintosh) and move the mouse. You should see that you are able to zoom into and out of the scene.

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

3 Improving the Crab more sophisticated programming

Version Control with Subversion and Xcode

Computer Science 1 CSci 1100 Lecture 3 Python Functions

Computer Programming C++ Classes and Objects 15 th Lecture

Python Programming: An Introduction To Computer Science

Python Lists and Loops

Transcription:

Chapter 9: Building Bigger Programs

How to Design Larger Programs Building something larger requires good software engineering. Design Top- down: Start from requirements, then identify the pieces to write, then write the pieces. Bottom- up: Start building with the pieces you know, test them, combine them, and keep going until you have your program Coding and Debugging: figure out what doesn t work, why, and how to fix it. Done at the same time as you write the code. Testing: make sure the program does what it is supposed to do and does it well. Maintenance: add new features, solved newly discovered bugs goes on for as long as the program is in use.

Top- Down Design Start from a problem statement. What are you trying to do? Refine the problem statement. Use hierarchical decomposition to define subparts. Continue refining until you know how to write the functions. Use procedural abstraction so that higher- level functions are written in terms of lower- level. Procedural abstraction allows us to focus in the big picture instead of on the little details Write functions so they are reusable (e.g. use parameters)

Top- Down Design Top- level function 1 st level Sub- function 1 st level Sub- function 2 nd level Sub- function 2 nd level Sub- function 2 nd level Sub- function 2 nd level Sub- function 3rd level Sub- function 3rd level Sub- function

Example Top- Down Design: An Adventure Game Text- based game The player explores a house moving between rooms To move the player uses commands such as move north, move east, quit, etc.

Example Top- Down Design: An Adventure Game Top- level function: 1. Tell the user how to play the game. 2. Describe the room the user is currently in. 3. Get the player s command. 4. Figure out the next room the user goes to. 5. Return to Step 2, and repeat until the user Quits.

Some new func@ons printnow(): Takes a string as input, and prints it on the Command Area immediately. print() waits until the program is done before it prints. requeststring(prompt): Takes a prompt string as input, accepts a string from the user in a dialog window, then returns the user s input. Other input functions in JES: requestnumber(prompt) requestinteger(prompt) requestintegerinrange(prompt, min, max) Counter part in Python: raw_input(prompt) - for strings input(prompt) for numbers

Some new func@ons JES also provides some output functions: showerror (string) showwarning (string) showinformation (string) These functions display a dialog window with a message

An important new loop A while loop repeats a block of instructions until a test/condition becomes false. Format: while (condition) : instructions false condition true instructions

Beware of infinite loops All loops must eventually terminate Something inside the loop must eventually make the test condition false If a loop does not have a way of stopping, it is called an infinite loop An infinite loop continues to repeat until the program is interrupted Infinite loops occur when: the programmer forgets to write code inside the loop that makes the test condition false. The condition that controls the loop is malformed You should avoid writing infinite loops

Examples stars = 1 while ( stars <= 10) : print * stars = stars + 1 #this next loop is an infinite loop stars = 1 while ( stars <= 10) : print * #this is an infinite loop too stars = 1 while ( stars >= 1) : print * starts = starts + 1

Wri@ng the top level func@on Our top level function, playgame is a direct translation from our outline. Top- level function: 1. Tell the user how to play the game. 2. Describe the room the user is currently in. 3. Get the player s command. 4. Figure out the next room the user goes to. 5. Return to Step 2, and repeat until the user Quits Example: playgame()

Wri@ng the top level func@on This top- level function makes sense, even without knowing the lower level functions (showintroduction, showroom, pickroom) - - lower level function have not been written yet The lower- level functions are being described in terms of their inputs, outputs, and what they should do à Abstraction Once you have written the top- level function, start writing the next level of functions.

Top- Down Design then.. Makes it easier to maintain code Different parts of a program (e.g. different functions) can change without having to change the whole program Allows us to plan functions before we write them Allows us to split the work (the program) among different programmers (or teams) Follow the plan each programmer/team works on a function (or a group of functions)

Top- Down Design playgame() showintro() ShowRoom() pickroom() showkitchen() showporch() showlr() showentryway () showdr()

BoGom- Up Design Start with some idea of what we want to do (problem statement) Instead of refining the problem, focus on building the solution program Reuse code from other programs as much as possible Combine pieces of code from other programs Write new pieces of code/functions as needed Test the program very often

Debugging Debugging: figuring out what the program is doing, how that differs from what we want it to do, and how to fix it. Two kinds of errors: Syntax error: something is wrong with the code itself e.g. misspelled keyword, spacing errors, mismatched parentheses, a forgotten colon The program does not work (it does not run) Python will give you an error message This type of error is easier to fix Logic error: something is wrong with the logic of the program The program works/runs but it does not do what it s supposed to do Python will not give you an error message This kind of error is harder to fix

Tes@ng your program Two main approaches: Glass- box testing: consider how the program is written and test every possible path through the program Black- box testing: consider how the program is supposed to behave and how it responds to valid and invalid inputs Use a combination of these two approaches to test your programs

Tips on Tes@ng and Debugging Try both expected, and unexpected input. Learn to trace code Add print and printnow statements They can help you check the values of variables used in the program or check if you are entering the functions You can delete them later when no longer needed Don t be afraid to change the program Use comments to remove parts temporarily when testing. Use the programming environment debugging tools In JES: showvars() and the Watcher

Seeing the Variables: showvars() This function will show you all the variables and their values at the point when it s executed showvars can also be used in the command area to see the variables created there

Using the Watcher The Watcher allows you to see which lines of code are being executed as they execute Open the Watcher from the main menu in JES then use the command area as normal.

Using the Watcher With the watcher you can: Pause execution of the program Step through the program from a given point Stop execution Speed up / slow down execution Track variables and the values they take

Improving the Adventure Game When testing, we discover: It s hard to tell which room was which when playing the game. Add a printnow in the showroom function to separate or space out one room description form another We can t figure out what we typed where. Add a printnow in the playgame function to display back what the user typed. The user can give an invalid input Add an error message in pickroom and return the user to the room where he/she is currently

Running programs outside of JES Once you make a larger program, you may want to run it in Jython directly. To use the JES libraries in other Jython interpreters, follow these steps in the command line (of the Jython interpreter): 1. >>> import sys 2. Insert the JES sources into your sys.path >>>sys.path.insert(0, r C:\Program Files (x86)\jes 4.3\Sources ) 3. >>> from media import * In a Mac you would follow these steps in the command line (of the Jython interpreter): >>> import sys >>> sys.path.insert(0, /Applications/jes-4-3.app/Contents/Resources/Java/ ) >>> from media import *