Title: Planning a Program
1Planning a Program
- HI5100 Data Structures for BioInformatics
- Lesson 3
2OBJECTIVES
- In this lesson you will learn
- Steps that programmers use to plan a program
before they write code. - How to use the Input-Process-Output model to
understand parts of programs.
3Lesson 3 Sections
- 1.1 Why Plan?
- 1.2 Stages of Program Planning
- 1.3 Features of User-Friendly Apps
- 1.4 Logic Structures Used in Programs
- 1.5 Summary
4What is a Computer Program?
- Step-by-step instructions that tell the computer
what to do - There can be no ambiguity in the statements
- Thus, strict syntax rules exist for every
programming language - Programs are read one character at a time
- White space (space, tab, return) separates
words - Words are compared to the rules of the language
and interpreted (translated into machine language)
5Simple Sequential Instruction Set
- Click on the Start button in the lower right hand
corner of the screen - Click on Enterprise Manager icon in the left
panel to start up Enterprise Manager
6Sometimes A More Complex Structure of
Instructions is Needed
Where is Enterprise Manager? I dont see it. What
do I do now?
7More Complex Instruction Set Structure
- Click on the Start button in the lower right hand
corner of the screen - Do you see an Enterprise Manager icon in the left
panel? - If you answered yes, then click on the icon to
start up Enterprise Manger - If you answered no, then
8Program Complexity
- Modern programs often accomplish very complex
tasks - Programs that accomplish complex tasks are very
complex - Thus, the process of creating a program often
requires significant planning prior to writing
9Development Stages
- Analyze
- Write specifications
- Design
- Implement/Debug/Implement
- Test/Debug/Modify/Test/Debug
- Deploy and Maintain
10Analyze the Problem
- Analyze the problem to be solved
- Break it down into smaller tasks
- What input is required?
- What will be the output?
- Your goal is to understand the problem from the
users perspective
11Write Specifications
- Describe what the program will do
- At this stage, you are not planning how it will
do things - Specify inputs
- Specify outputs
- Specify how inputs relate to outputs
12Design the Program
- Define subtasks and inputs and outputs for each
- Design flow of data and processing through the
subtasks - Develop the logic of the program
- Develop algorithms to perform tasks
13Implement
- Translate the design into code
- Use software to compile the program
- With Python we will use the Python interpreter to
translate the program line-by-line rather than
create a compiled version - Find syntax errors
14Typos and syntax errors often occur when
translating a design into code
15Syntax Errors
- Every programming language requires that programs
follow a set of rules for syntax - Compilers identify errors made in syntax
- Some IDEs identify some errors made in syntax as
you type before the code ever gets compiled
16Can You Spot An Error in Syntax?
- Preheat the oven to 350 F.
- Put the cake mix into a bowl.
- Add 2 slightly beaten eggs, ¼ c. vegetable oil
and 1 ½ c. water. - Mix for 3 minutes using medium speed of an
electric mixer. - For 33 minutes pour batter into greased pan and
bake. - Remove from oven and let cool.
17Can You Spot an Error that is most likely a Typo?
- Preheat the oven to 350 F.
- Put the cake mix into a bowl.
- Add 2 slightly beaten eggs, ¼ c. vegetable oil
and 1 ½ c. water. - Mix for 30 minutes using medium speed of an
electric mixer. - Pour batter into greased pan and bake for 33
minutes. - Remove from oven and let cool.
18Implement
- Once translated into code and compiled, the
syntax errors and typos are gone - The program will not execute if there are syntax
errors and typos - Input into the computer for testing
- The apps we create can only run on a program that
has the Python interpreter installed - If we compiled them down to .exe form, then they
could run on any computer with the appropriate OS
19Test and Debug
- Testing and debugging of complex programs should
be integrated with implementation - During coding, you are testing for typos and
syntax errors - After typos and syntax errors are gone, there
still can be errors
20Errors in Logic
- The program runs, but the output is not correct
with respect to the problem the program is
supposed to solve
21No Syntax Errors, No Typos, No Logical Design
- Mix for 3 minutes using medium speed of an
electric mixer. - Preheat the oven to 350 F.
- Pour batter into greased pan and bake for 33
minutes. - Put the cake mix into a bowl.
- Remove from oven and let cool.
- Add 2 slightly beaten eggs, ¼ c. vegetable oil
and 1 ½ c. water.
22Deploy and Maintain
- When the program is thoroughly tested and revised
based on testing, it is ready to be employed by
users to accomplish tasks - Often new programs are deployed to a small pilot
group of typical users - Pilot users provide feedback
- Suggestions for improvement
- Bugs not found during testing
- Provide all users with patches and updates
23User-Friendly Programs
- Modern applications employ a GUI (graphical user
interface) - At this point, we will not begin investigating
how to create GUIs - If the user cannot use the program without
extensive instruction, the program is not
user-friendly
24Features for User-Friendliness
- Print an introduction that tells the user what
task the program completes - Print any instructions the user needs
- Try to avoid creating a program that can only be
used after reading a lengthy set of instructions
25Three Basic Logic Structures for Programming
- A programming structure is a unit of programming
logic - Three basic structures
- Sequence
- Selection ? Decision
- Loop ? Iteration ? Repetition
- Computer scientists have shown that you can solve
any problem of logic using only these three
structures
26Sequence
- Line by line execution
- Execute line 1, followed by line 2, followed by
line 3,
27Sequence
- Graphical representation
- Flowchart elements
-
- Terminator (oval)
-
- Process (rectangle)
28Selection ? Decision
- The terms selection and decision are synonyms
with respect to programming - Ask a question
- Two courses of action can be taken, depending on
the answer to the question
29Selection ? Decision
30Selection ? Decision
-
- Decision (diamond)
- In code, a basic decision structure often
involves the key words if then - else
31Loop ? Iteration ? Repetition
- Repeat a block of code over and over until a
condition is met - Code
- Decision no
- Same code
- Decision no
- Same code
- Decision yes
- Continue with something else
32Loop ? Iteration ? Repetition
- The process is performed only if the decision is
true - It continues to be performed until the decision
is false
33Additional Logic Structures for Programming
- While computer scientists have shown that you can
solve any problem of logic using only the three
structures of sequence, decision, and loop, - Most modern programming languages allow three
more structures (for each of programming) - Case
- Do While
- Do Until
34Case
- There is a decision variable
- Case 1 is executed when the decision variable has
a certain value - Case 2 is executed when the decision variable has
another value - Case 3 is executed when the decision variable has
a third value
35Case
36Do While and Do - Until
- With the basic loop structure, the decision is
made before the code block is executed - Thus the code block may not be executed at all if
the decision is FALSE originally - With do while and do until loops the decision
is made after the code block is executed at least
once
37Do While and Do Until
- The process is performed and then the decision
question is evaluated - Based on the evaluation result the process is
repeated or not
38Summary
- You are now familiar with some basic ideas about
how to plan a program and the logic structures
that are often used in this process - Each logic structure has an interpretation in the
programming language of choice, in our case,
Python - We will look at Python syntax for the basic logic
structures in the next lesson
39End of Slides for Lesson 3
- HI5100 Data Structures for BioInformatics
- Lesson 2