Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Data Structures CSCI 132, Spring 2014 Lecture 3 Programming Principles and Life Read Ch. 1.

Similar presentations


Presentation on theme: "1 Data Structures CSCI 132, Spring 2014 Lecture 3 Programming Principles and Life Read Ch. 1."— Presentation transcript:

1 1 Data Structures CSCI 132, Spring 2014 Lecture 3 Programming Principles and Life Read Ch. 1

2 2 CS Humor

3 3 Program Lifecycle Problem Specification Program Design Program Implementation Testing and Verification Maintenance

4 4 Problem Specification State precise goals of project. What is the input? What is the output? Divide the work into smaller problems (divide and conquer). Specify each smaller problem precisely. (Pre-conditions, Post-conditions). Keep dividing until small problems are easily solvable.

5 5 Program Design and Implementation Design: Carefully choose the data structures you will use (Lists, Stacks, Queues?) Decide how data is arranged, stored in memory, calculated, stored in files, etc. Choose an algorithm (We will learn how to analyze the behavior of algorithms to choose among them). Implementation: Implement using good programming techniques (data hiding, modularity, etc.)

6 6 Testing and Verification Test and re-test as you develop the program. Develop program in pieces and test each piece as it is finished. Think carefully about testing conditions. Test final program thoroughly.

7 7 Maintenance Maintenance is used to: Fix bugs found during program use. Add features as they become needed.

8 8 Programming Style Keep your code clear and simple. Use clear comments. Try to use meaningful variable names: input_file, number_courses, index Avoid cryptic variable names: indx, nmcs, x Use comments where needed to explain a block of code. Use white space and tabs to make your programs readable.

9 9 Program Refinement As you divide program into subproblems, think carefully about how to divide work into classes and functions. Rule of thumb: Classes are like nouns used to describe the problem (e.g. the Student class). Functions are like verbs: void AddCourse(string9 courseName)

10 10 Input and Output parameters Input parameters are used by the function but not changed by the function. They are usually pass-by- value. Output parameters contain the results of function execution. They are pass-by-reference. Input/Output parameters have an initial value used by the function and are modified by the function. They are pass-by-reference.

11 11 Local vs. Global variables Local Variables: Defined and used within a function. Exist only during function execution. Global variables: Defined outside function. Often exist throughout program execution. If a function modifies a global variable, it is called a side effect of the function. This is undesirable. Using global variables decreases the modularity of a function. Try to avoid using global variables.

12 12 Debugging Structured walkthrough Trace tools and snapshots Scaffolding Static analyzer

13 13 Program Testing The black box method. Test the following types of input: Easy values Typical values Extreme values Illegal values

14 14 Program Testing The glass box method. Trace all paths through a program: if ( x == 0) { a = 1; } else { a = 2; } Test values of x == 0 and x != 0. Good to do for modules. Not practical for large programs.

15 15 Program Testing The ticking box method. Don’t test. Tick…tick….tick…. Kaboom!!!

16 16 Rules of Life The neighbors of a given cell are the eight cells that touch it. Every cell is either living or dead. A living cell stays alive in the next generation if it has either 2 or 3 living neighbors; otherwise it dies (of loneliness or overcrowding) A dead cell becomes alive in the next generation if it has exactly 3 neighboring cells that are already alive. All births and deaths take place at exactly the same time for each generation.

17 17 Sample configurations There are lots of websites devoted to life. Check out: http://www.bitstorm.org/gameoflife/ http://www.ibiblio.org/lifepatterns/

18 18 Why is Life Interesting? John Conway developed Life rules in 1970. He tried lots of rules, but only these rules resulted in interesting complexity. Life is an example of a Cellular Automaton. Life exhibits Emergent Complexity. Life is a Turing Machine.

19 19 Specifications What do we want our program to do? (We will answer this question in class).


Download ppt "1 Data Structures CSCI 132, Spring 2014 Lecture 3 Programming Principles and Life Read Ch. 1."

Similar presentations


Ads by Google