Вы находитесь на странице: 1из 13

Introduction to Programming

Computer Science
What is a program?
Noun: A set of steps for the computer to
follow to accomplish a task.
Verb: To create a program.

How do you program?
Programming is a planning activity
Plan what your program will do
Plan how your program will do it
Programming typically follows 5 steps:
1. Specification
2. Design
3. Coding
4. Testing and debugging
5. Delivery
1. Specification
Means asking what will my program need
to do?
Activities involved in specification:
Read the requirements carefully
Ask questions
Search for the answers in the requirements
If necessary, ask the customer
Dont assume!
Specification Example
Calculate the area of a circle using the formula
pr
2
.
What kind of questions might you ask?
How precise does pi need to be?
Is the radius r read in from a file, entered by hand, or
included in the program?
Do you want the result output to the screen or written to
a file?
What if r is clearly wrong? E.g. Negative, not a
number, etc.
2. Design
Ask how will my program do what it needs
to?
What type of statements will I use?
What order will it do things in?
Later on in the course: How can I break it down
into smaller problems?
3. Coding
Writing the program
Actually the least difficult of the five steps
If you have done the first two correctly
Testing and Debugging
Testing Verifying that your program works as
you want it to
Debugging Discovering the source of a problem
you found and fixing it.
Term invented by Grace Hopper, a navy computer
scientist.
Dates back to the days when bugs would actually fly
into large computers and short the vacuum tubes
The key for testing
TRUST NOTHING!!!
Assume your program doesnt work until it
is tested.
Assume any given feature of your program
doesnt work until it is tested.
Assume any given test case doesnt work
until it is tested.
The hardest part of testing: Making sure you
have enough test cases.
Testing Example: Add a series of
numbers and output the sum
No numbers
One number
Two numbers
A bunch of numbers
One is not a number
One is a negative number

The Key to Debugging
BE SYSTEMATIC!!!
The right way
Slowly track the problem down.
Dont try to fix the problem until you know what is
wrong.
The wrong way
Change something and see if that fixes the problem
Usually youve introduced a new problem
When you finally fix the old problem you wont know
it, because the change you made caused it to be worse
Delivery
Your program is finished. But it is no good
unless it gets to the customer.
Want to make sure it gets there properly.
Want to make sure the customer knows what
he/she had
Want to make sure the customer understands
how to use it.
In this class, means looking over what you are
handing in to make sure I get everything I need.
Summary Five Programming
Steps
1. Specification Ask questions, find the
answers in the requirements.
2. Design How will you build it.
3. Coding
4. Testing TRUST NOTHING
Debugging Be systematic
5. Delivery Youve come so far, dont
mess it up now.

Вам также может понравиться