chapter 12: computer programming 1 computer programming chapter 12

51
Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Upload: easter-fowler

Post on 18-Jan-2016

288 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

1

Computer Programming

Chapter 12

Page 2: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

2

Programming Basics

• Computer Programming and Software Engineering

• Programming Languages and Paradigms

• Program Planning

• Program Coding

• Program Testing and Documentation

• Programming Tools

Page 3: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

3

Computer Programming and Software Engineering

• The instructions that make up a computer program are sometimes referred to as code

• Programs can have millions of lines of code

Page 4: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

4

Computer Programming and Software Engineering

Page 5: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

5

Programming Languages and Paradigms

• Programming languages are made up of keywords and grammar rules designed for creating computer instructions

• Low-level languages

• High-level languages

Page 6: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

6

Programming Languages and Paradigms

• First-generation languages

• Second-generation languages

• Third-generation languages

Page 7: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

7

Programming Languages and Paradigms

• Fourth-generation languages

• Fifth-generation languages

• The Programming Paradigm

Page 8: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

8

Programming Languages and Paradigms

Page 9: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

9

Program Planning

• The problem statement defines certain elements that must be manipulated to achieve a result or goal

• You accept assumptions as true to proceed with program planning

• Known information helps the computer to solve a problem

• Variables vs. constants

Page 10: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

10

Program Planning

• Problem statement:

Assuming that there are two pizzas to compare, that both pizzas contain the same toppings, and that the pizzas could be round or square, and given the prices, shapes, and sizes of the two pizzas, the computer will print a message indicating which pizza has the lower price per square inch

Page 11: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

11

Program Coding

A text editor such asNotepad allows programmersto enter lines of code using a familiar word processing interface.

Page 12: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

12

Program Coding

• VDE (visual development environment)

– Form design grid– Control– Properties– Event– Event-

handling code

Page 13: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

13

Program Coding

Controls, such as theBest Deal button, can beselected by a programmerfrom a properties list. Here a programmer is selecting the background color for the Best Deal button.

Page 14: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

14

Program Coding

Page 15: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

15

Program Testing and Documentation

• A computer program must be tested • Program errors include

– Syntax errors

– Runtime errors

– Logic errors

• Debugger

Page 16: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

16

Program Testing and Documentation

• Remarks/Comments

Page 17: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

17

Programming Tools

• SDK (software development kit)

• IDE (integrated development environment)

Page 18: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

18

Programming Tools

• Component

• API

• C and C++ are the most popular programming languages

Page 19: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

19

Procedural Programming

• Algorithms

• Expressing an Algorithm

• Sequence, Selection, and Repetition Controls

• Procedural Languages and Applications

Page 20: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

20

Algorithms

• What is an algorithm?

• Record steps to solve the problem

• Specify how to manipulate information

• Specify a solution

Page 21: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

21

Algorithms

Page 22: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

22

Expressing an Algorithm

• Pseudocode

Page 23: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

23

Expressing an Algorithm

• Flowchart

The pizza program flowchartillustrates how the computershould proceed through theinstructions in the final program.

Page 24: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

24

Expressing an Algorithm

• Perform a walkthrough to make sure your algorithm works

Page 25: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

25

Sequence, Selection, and Repetition Controls

• Sequence control structure

Executing a GOTO commanddirects the computer to a differentpart of the program.

Page 26: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

26

Sequence, Selection, and Repetition Controls

• Subroutines, procedures, and functions

Page 27: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

27

Sequence, Selection, and Repetition Controls

• Selection control structure

The computer executes a decisionindicated on the flowchart by the question in the diamond shape.

Page 28: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

28

Sequence, Selection, and Repetition Controls

• Repetition control structure

To execute a loop, the computerrepeats one or more commands until some condition indicates that the looping should stop.

Page 29: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

29

Procedural Languages and Applications

• Popular procedural languages include FORTRAN, COBOL, FORTH, APL, ALGOL, PL/1, Pascal, C, Ada, and BASIC

• The procedural approach is best used for problems that can be solved by following a step-by-step algorithm

• Produces programs that run quickly and efficiently

Page 30: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

30

Object-Oriented Programming

• Objects and Classes

• Inheritance

• Methods and Messages

• Object-oriented Program Structure

• Object-oriented Languages and Applications

Page 31: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

31

Objects and Classes

• Object

• Class

Page 32: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

32

Inheritance

• What is inheritance?

– Superclass– Subclass– Class hierarchy

Page 33: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

33

Methods and Messages

• Method– Collect input, perform calculations, etc.– A method is activated by a message– Can be defined along with the class they

affect

• Polymorphism

Page 34: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

34

Object-Oriented Program Structure

Page 35: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

35

Object-Oriented Program Structure

Page 36: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

36

Object-Oriented Program Structure

When the pizza programruns, on-screen promptsask for the shape, size, andprice of each pizza; thenthe program displays amessage that indicateswhich pizza is the bestdeal.

Page 37: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

37

Object-Oriented Languages and Applications

• SIMULA was believed to be the first object-oriented computer language

• The Dynabook project was the second major development in object-oriented languages

• Popular object-oriented languages today are Ada95, C++, Visual Basic, C#, and Java

• The O-O paradigm results in decreased runtime efficiency, but allows encapsulation, which hides the internal details of objects and their methods

Page 38: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

38

Declarative Programming

• The Declarative Paradigm

• Prolog Facts

• Prolog Rules

• Input Capabilities

• Declarative Languages and Applications

Page 39: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

39

The Declarative Paradigm

• Attempts to describe a problem without specifying exactly how to arrive at a solution

Page 40: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

40

Secure Programming

• Black Hat Exploits

• Secure Software Development

• Mitigation

Page 41: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

41

Black Hat Exploits

• Today’s operating systems, utilities, and application software are full of defects that create security holes, which are exploited by black hats

• Buffer overflow

Page 42: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

42

Black Hat Exploits

Page 43: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

43

Black Hat Exploits

• Verbose error messages can also present attackers with information about the directory location of programs or files, the structure of a database, or the layout of the program in memory

Page 44: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

44

Secure Software Development

• Most software security problems can be traced back to defects that programmers unintentionally introduce in software during design and development

• Formal methods help programmers apply rigorous logical and mathematical models to software design, coding, testing, and verification

• Threat modeling (risk analysis) – used by security designer to determine (1) what are important issues the designer cares about and (2) a description of a set of security aspects (possible attacks to consider)

Page 45: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

45

Secure Software Development

Page 46: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

46

Secure Software Development

• An attack tree is a hierarchical diagram of potential attacks against a system

Page 47: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

47

Secure Software Development• Defensive programming (AKA secure

programming)

– Source code walkthroughs– Simplification– Filtering input

Page 48: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

48

Secure Software Development

• Signed code

Page 49: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

49

Mitigation• Despite defensive programming and other

tactics to produce secure software, some defects inevitably remain undiscovered in products that end up in the consumers’ hands. When bugs are discovered, the programmer’s remaining line of defense is to produce a bug fix, or patch

Page 50: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

50

Mitigation

• Take the following steps to avoid security problems that stem from software defects– Select applications from software publishers

with a good security track record– Watch for patches and apply them– Consider using open source software, which

has been extensively reviewed by the programming community

– Keep your firewall and antivirus software deployed and up-to-date

Page 51: Chapter 12: Computer Programming 1 Computer Programming Chapter 12

Chapter 12: Computer Programming

51

Chapter 12 Complete

Computer Programming