The Pseudocode Programming Process

Slides:



Advertisements
Similar presentations
The Pseudocode Programming Process Chapter 9. Outline  Introduction  Design the routine.  Code the routine.  Check the code.  Clean up loose ends.
Advertisements

Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification.
1 Program Design Language (PDL) Slides by: Noppadon Kamolvilassatian Source: Code Complete by Steve McConnell, Chapter 4.
API Design CPSC 315 – Programming Studio Fall 2008 Follows Kernighan and Pike, The Practice of Programming and Joshua Bloch’s Library-Centric Software.
Software Engineering and Design Principles Chapter 1.
Computer Science 1620 Programming & Problem Solving.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Chapter 1 Principles of Programming and Software Engineering.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Shell Programming The activities of.
Software Construction. Implementation System Specification Requirements Analysis Architectural Design Detailed Design Coding & Debugging Unit Testing.
The Pseudocode Programming Process Chapter 9. Summary of Steps in Building Classes and Routines.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
1 Shawlands Academy Higher Computing Software Development Unit.
TESTING.
Comp 245 Data Structures Software Engineering. What is Software Engineering? Most students obtain the problem and immediately start coding the solution.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
The Software Development Process
Software Engineering 2004 Jyrki Nummenmaa 1 BACKGROUND There is no way to generally test programs exhaustively (that is, going through all execution.
Intermediate 2 Computing Unit 2 - Software Development.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
Chapter 1 Software Engineering Principles. Problem analysis Requirements elicitation Software specification High- and low-level design Implementation.
1 Introduction 1. Why Data Structures? 2. What AreData Structure? 3. Phases of Software Development 4. Precondition and Postcondition 5. Examples.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
1 ENERGY 211 / CME 211 Lecture 14 October 22, 2008.
Implementation Topics Describe –Characteristics of good implementations –Best practices to achieve them Understand role of comments Learn debugging techniques.
Principles of Programming & Software Engineering
Programming Logic and Design Seventh Edition
ALGORITHMS AND FLOWCHARTS
Defensive Programming
Topics Introduction to Repetition Structures
GC211Data Structure Lecture2 Sara Alhajjam.
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Principles of Programming and Software Engineering
Loop Structures.
Topic: Functions – Part 2
Teaching design techniques to design efficient solutions to problems
Chapter 5: Loops and Files.
Scripts & Functions Scripts and functions are contained in .m-files
Topics Introduction to Repetition Structures
Algorithm and Ambiguity
Stack Data Structure, Reverse Polish Notation, Homework 7
CS 240 – Lecture 11 Pseudocode.
Chapter 1 Program Development
Computer Programming.
ALGORITHMS AND FLOWCHARTS
Designing and Debugging Batch and Interactive COBOL Programs
Software Construction
Unit# 9: Computer Program Development
ALGORITHMS AND FLOWCHARTS
Topic 1: Problem Solving
Problem Solving Skill Area 305.1
Algorithm and Ambiguity
Program Design Language (PDL)
Software Development Process
Topics Introduction to Repetition Structures
Lecture 13 Teamwork Bryan Burlingame 1 May 2019.
Software Construction
CHAPTER 6 Testing and Debugging.
Introduction To Software Development Environment
Unit Testing.
Presentation transcript:

The Pseudocode Programming Process SCMP 391.00 Special Topic: Software Development Spring 2017 James Skon

Steps for Building Classes and Routines Class construction is an iterative process.

Steps in Creating a Class Create a general design for the class Construct each routine within the class Review and test the class as a whole

Steps in Creating a Class Create a general design for the class Define the class's specific responsibilities Define the classes hidden state (secrets) Define what abstraction the class interface will capture Will the class be derived from another class and with other classes be allowed to derive from it? Identify the class's key public methods What are the data members?

Steps in Creating a Class Create a general design for the class Construct each routine within the class Build the routines! Respond to issues by backtracking Review and test the class as a whole Class should be tested by itself, and then in context.

Steps in Building a Routine

Pseudocode Informal, English-like notation for describing how an algorithm, a routine, a class, or a program will work. Calculate Pay with Overtime Begin input hours, rate if hours ≤ 40 then pay = hours * rate else pay = 40 * rate + (hours – 40) * rate * 1.5 print pay End

Pseudocode Use English-like statements that precisely describe specific operations. Avoid syntactic elements from the target programming language. Write pseudocode at the level of intent.

Pseudocode increment resource number by 1 BAD! increment resource number by 1 allocate a dlg struct using malloc if malloc() returns NULL then return 1 invoke OSrsrc_init to initialize a resource for the operating system *hRsrcPtr = resource number return 0 Keep track of current number of resources in use If another resource is available Allocate a dialog box structure If a dialog box structure could be allocated Note that one more resource is in use Initialize the resource Store the resource number at the location provided by the caller Endif Return true if a new resource was created; else return false Good!

Why Pseudocode? Pseudocode makes reviews easier. Pseudocode supports the idea of iterative refinement. Pseudocode makes changes easier. Pseudocode minimizes commenting effort. Pseudocode is easier to maintain than other forms of design documentation.

Constructing Routines Design the routine. Code the routine. Check the code. Clean up loose ends. Repeat as needed.

Design the routine Create a specification: ReportErrorMessage() takes an error code as an input argument and outputs an error message corresponding to the code. It's responsible for handling invalid codes. If the program is operating interactively, ReportErrorMessage() displays the message to the user. If it's operating in command-line mode, ReportErrorMessage() logs the message to a message file. After outputting the message, ReportErrorMessage() returns a status value, indicating whether it succeeded or failed.

Design the routine Check the prerequisites Is the job well defined? Define the problem the routine will solve he information the routine will hide Inputs to the routine Outputs from the routine Preconditions guaranteed to be true before the routine is called Postconditions guarantees will be true after routine Name the routine

Design the routine Decide how to test the routine Research functionality available in the standard libraries Think about error handling Think about efficiency Research the algorithms and data types Write the pseudocode

Write the pseudocode Start with the general and work toward something more specific. Write a concise header statement ReportErrorMessage This routine outputs an error message based on an error code supplied by the calling routine. The way it outputs the message depends on the current processing state, which it retrieves on its own. It returns a value indicating success or failure.

Write the pseudocode ReportErrorMessage This routine outputs an error message based on an error code supplied by the calling routine. The way it outputs the message depends on the current processing state, which it retrieves on its own. It returns a value indicating success or failure. set the default status to "fail" look up the message based on the error code if the error code is valid if doing interactive processing, display the error message interactively and declare success if doing command line processing, log the error message to the command line and declare success if the error code isn't valid, notify the user that an internal error has been detected return status information

Write the pseudocode Think about the data – What are the data elements, how appropriate are they? Check the pseudocode Try a few ideas in pseudocode, and keep the best (iterate)

Code the Routine

Code the Routine - declaration /* This routine outputs an error message based on an error code supplied by the calling routine. The way it outputs the message depends on the current processing state, which it retrieves on its own. It returns a value indicating success or failure. */ <-- 1 Status ReportErrorMessage( ErrorCode errorToReport ) set the default status to "fail" look up the message based on the error code if the error code is valid if doing interactive processing, display the error message interactively and declare success if doing command line processing, log the error message to the command line and declare success if the error code isn't valid, notify the user that an internal error has been detected return status information Header comment interface statement

Code the Routine – first and last statement /* This routine outputs an error message based on an error code supplied by the calling routine. The way it outputs the message depends on the current processing state, which it retrieves on its own. It returns a value indicating success or failure. */ Status ReportErrorMessage( ErrorCode errorToReport ) { // set the default status to "fail" // look up the message based on the error code // if the error code is valid // if doing interactive processing, display the error message // interactively and declare success // if doing command line processing, log the error message to the // command line and declare success // if the error code isn't valid, notify the user that an // internal error has been detected // return status information } pseudocode statements from here down have been turned into C++ comments

Code the Routine – Fill in the code Programming Process /* This routine outputs an error message based on an error code supplied by the calling routine. The way it outputs the message depends on the current processing state, which it retrieves on its own. It returns a value indicating success or failure. */ Status ReportErrorMessage( ErrorCode errorToReport ) { // set the default status to "fail" Status errorMessageStatus = Status_Failure; // look up the message based on the error code Message errorMessage = LookupErrorMessage( errorToReport ); // if the error code is valid if ( errorMessage.ValidCode() ) { <-- 1 // determine the processing method ProcessingMethod errorProcessingMethod = CurrentProcessingMethod(); // if doing interactive processing, display the error message // interactively and declare success if ( errorProcessingMethod == ProcessingMethod_Interactive ) { DisplayInteractiveMessage( errorMessage.Text() ); errorMessageStatus = Status_Success; } The code for each comment has been filled in

Code the Routine – Fill in the code // if doing command line processing, log the error message to the // command line and declare success else if ( errorProcessingMethod == ProcessingMethod_CommandLine ) { CommandLine messageLog; if ( messageLog.Status() == CommandLineStatus_Ok ) { messageLog.AddToMessageQueue( errorMessage.Text() ); messageLog.FlushMessageQueue(); errorMessageStatus = Status_Success; } else { // can't do anything because the routine is already error processing // if the error code isn't valid, notify the user that an // internal error has been detected DisplayInteractiveMessage( "Internal Error: Invalid error code in ReportErrorMessage()" ); // return status information return errorMessageStatus; good candidate for being further decomposed

Code the Routine Check whether code should be further factored In some cases, you'll see an explosion of code below one of the initial lines of pseudocode. Factor the code below the comment into a new routine.

Check the Code After designing and implementing the routine, the third big step in constructing it is checking to be sure that what you've constructed is correct. Any errors you miss at this stage won't be found until later testing.

Compile the routine Set the compiler's warning level to the pickiest level possible. Use validators. (lint) Eliminate the causes of all error messages and warnings.

Test the code Test the code using the test cases you planned or created while you were developing the routine.

Clean Up Leftovers Check the routine's interface. Check for general design quality. Check the routine's variables. Check the routine's statements and logic. Check the routine's layout. Check the routine's documentation. Remove redundant comments.

Code the Routine

Code the Routine - Example /* This routine outputs an error message based on an error code supplied by the calling routine. The way it outputs the message depends on the current processing state, which it retrieves on its own. It returns a value indicating success or failure. */ Status ReportErrorMessage( ErrorCode errorToReport ) set the default status to "fail" look up the message based on the error code if the error code is valid if doing interactive processing, display the error message interactively and declare success if doing command line processing, log the error message to the command line and declare success if the error code isn't valid, notify the user that an internal error has been detected return status information Header comment turned into a c++ comment Interface statement

Code the Routine - Example Status ReportErrorMessage( ErrorCode errorToReport ) { // set the default status to "fail" Status errorMessageStatus = Status_Failure; // look up the message based on the error code Message errorMessage = LookupErrorMessage( errorToReport ); // if the error code is valid // if doing interactive processing, display the error message // interactively and declare success // if doing command line processing, log the error message to the // command line and declare success // if the error code isn't not valid, notify the user that an // internal error has been dtected // return status information Code filled in New variable for errorMessage

Check the Code After designing and implementing the routine, the third big step in constructing it is checking to be sure that what you've constructed is correct. Mentally check the routine for errors Understand “why” the routine works Compile the routine Let the compiler look for errors Step through the code with a debugger Test the program

CLEAN UP LEFTOVERS Check the routine's interface.. Check for general design quality. Check the routine's variables. Check the routine's statements and logic. Check the routine's layout. Check the routine's documentation. Remove redundant comments.