Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2....

22
1 Introduction to Programming – Lecture 26 1 Chair of Software Engineering Introduction to Programming Bertrand Meyer Last revised 3 February 2004 Introduction to Programming – Lecture 26 2 Chair of Software Engineering Lecture 26: From Programming to Software Engineering Introduction to Programming – Lecture 26 3 Chair of Software Engineering Software engineering (1) The processes, methods, techniques, tools and languages for developing quality operational software.

Transcript of Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2....

Page 1: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

1

Introduction to Programming – Lecture 26

1

Chair of Software Engineering

Introduction to Programming

Bertrand Meyer

Last revised 3 February 2004

Introduction to Programming – Lecture 26

2

Chair of Software Engineering

Lecture 26:

From Programmingto

Software Engineering

Introduction to Programming – Lecture 26

3

Chair of Software Engineering

Software engineering (1)

The processes, methods, techniques, tools and languages for developing qualityoperational software.

Page 2: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

2

Introduction to Programming – Lecture 26

4

Chair of Software Engineering

Software engineering (2)

The processes, methods, techniques, tools and languages for developing qualityoperational software that may need to

Be of large sizeBe developed and used over a long periodInvolve many developersUndergo many changes and revisions

Introduction to Programming – Lecture 26

5

Chair of Software Engineering

Operating systems: source lines

1990 1995 1998 20002

10

20

40

30

Lines of code (millions)

Windows 3.1: 3 MWindows NT: 4 M

Windows 95: 15 MWindows 98: 18 M

Windows 2000: 40 M

1992

Windows XP: > 45 M

Introduction to Programming – Lecture 26

6

Chair of Software Engineering

Not just Windows

19901992

1995 1998 2000

2

10

20

40

30

Lines of code (millions)

Windows 3.1: 3 MWindows NT: 4 M

Windows 95: 15 MWindows 98: 18 M

Windows 2000: 40 M

Red Hat 6.217 M

Red Hat 7.130 M

Linux: 10,000

Solaris 7: 12 Mio.

Unix V7:10,000

Windows XP: > 45 M

Page 3: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

3

Introduction to Programming – Lecture 26

7

Chair of Software Engineering

Not just operating systems

Introduction to Programming – Lecture 26

8

Chair of Software Engineering

The basic issue

Developing software systems that are

On time and within budgetOf high immediate qualityPossibly large and complexExtendible

Introduction to Programming – Lecture 26

9

Chair of Software Engineering

US Software industry, 1998

Standish Group: “Chaos” Report

250,000 Software projects, $275 billions

Project results:28% abandoned (1994: 31%)27% successful (1994: 16%)

The rest: “challenged”

Smaller projects have higher chances of success

Page 4: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

4

Introduction to Programming – Lecture 26

10

Chair of Software Engineering

NIST report on testing (May 2002)

Financial consequences, on developers and users, of “insufficient testing infrastructure”

$ 59.5 B.

(Finance $ 3.3 B, Car and aerospace $ 1.8 B. etc.)

Introduction to Programming – Lecture 26

11

Chair of Software Engineering

Software quality factors

External: of interest to customersExamples: Reliability, Extendibility

Internal: of interest to developersExamples: Modularity, Style

Introduction to Programming – Lecture 26

12

Chair of Software Engineering

Some internal factors

ModularityObservation of style rulesConsistencyStructure...

Page 5: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

5

Introduction to Programming – Lecture 26

13

Chair of Software Engineering

Some external factors

Product quality (immediate):ReliabilityEfficiencyEase of useEase of learning Process quality:

TimelinessCost-effectiveness

Product quality (long term):ExtendibilityReusabilityPortability

Introduction to Programming – Lecture 26

14

Chair of Software Engineering

External factors: reliability

Reliability = Correctness + Robustness + Integrity

Hostility

Integrity

Errors

Correctness

Specification

Correctness

Introduction to Programming – Lecture 26

15

Chair of Software Engineering

Reliability

CorrectnessThe system’s ability to perform its functions according to the specification, in cases covered by the specification

RobustnessThe system’s ability to handle erroneous cases safely

IntegrityThe system’s ability to protect its users, its data and itself against hostile uses

Hostility

Integrity

Errors

Robustness

Specification

Correctness

Page 6: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

6

Introduction to Programming – Lecture 26

16

Chair of Software Engineering

External factors

Product quality (immediate):ReliabilityEfficiencyEase of useEase of learning Process quality:

TimelinessCost-effectiveness

Product quality (long term):ExtendibilityReusabilityPortability

Introduction to Programming – Lecture 26

17

Chair of Software Engineering

Software tasks

Requirements analysisSpecificationDesignImplementationValidation & Verification (V&V)ManagementPlanning and estimatingMeasurement

Introduction to Programming – Lecture 26

18

Chair of Software Engineering

Requirements analysis

Understanding user needsUnderstanding constraints on the system

Internal constraints: class invariantsExternal constraints

Page 7: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

7

Introduction to Programming – Lecture 26

19

Chair of Software Engineering

Validation & Verification

Verification: checking that you have built the system right

(followed all rules)

Validation: checking that you have built the right system

(satisfied user needs)

Introduction to Programming – Lecture 26

20

Chair of Software Engineering

Software lifecycle models

Describe an overall distribution of the software construction into tasks, and the ordering of these tasks

They are models in two ways:Provide an abstracted version of reality

Describe an ideal scheme, not alwaysfollowed in practice

Introduction to Programming – Lecture 26

21

Chair of Software Engineering

The waterfall model (Royce, 1970)

FEASIBILITY STUDY

REQUIREMENTS ANALYSIS

SPECIFICATION

GLOBAL DESIGN

DETAILED DESIGN

IMPLEMENTATION

DISTRIBUTION

VALIDATION & VERIFICATION

PROJECT PROGRESS

Page 8: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

8

Introduction to Programming – Lecture 26

22

Chair of Software Engineering

Lifecycle: what not to achieve

As Management requested it As the Project Leader defined it As Systems designed it

As Programming developed it As Operations installed it What the user wanted(Pre-1970 cartoon; origin unknown)

Introduction to Programming – Lecture 26

23

Chair of Software Engineering

The waterfall model

FEASIBILITY STUDY

REQUIREMENTS ANALYSIS

SPECIFICATION

GLOBAL DESIGN

DETAILED DESIGN

IMPLEMENTATION

DISTRIBUTION

VALIDATION & VERIFICATION

PROJECT PROGRESS

Introduction to Programming – Lecture 26

24

Chair of Software Engineering

A more realistic version

FEASIBILITY STUDY

REQUIREMENTS ANALYSIS

GLOBAL DESIGN

DETAILED DESIGN

IMPLEMENTATION

ACCEPTANCETESTING

SYSTEM TESTING

UNIT TESTING

Page 9: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

9

Introduction to Programming – Lecture 26

25

Chair of Software Engineering

The spiral model

Apply a waterfall-like approach to successive prototypes

Iteration 1

Iteration 2

Iteration 3

Introduction to Programming – Lecture 26

26

Chair of Software Engineering

The problem with prototyping

Software development is hard because of the need to reconcile conflicting criteria, e.g. portability and efficiencyA prototype typically sacrifices some of these criteriaRisk of shipping the prototype

Introduction to Programming – Lecture 26

27

Chair of Software Engineering

Seamless, incremental development

The Eiffel view:

Single set of notation, tools, concepts, principles throughout Eiffel is as much for analysis & design as for implementation & maintenanceContinuous, incremental developmentKeep model, implementation and documentation consistentReversibility: can go back and forth

Page 10: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

10

Introduction to Programming – Lecture 26

28

Chair of Software Engineering

Seamless development (1)

TRANSACTION, PLANE, CUSTOMER, ENGINE...

Example classes

Specification

Introduction to Programming – Lecture 26

29

Chair of Software Engineering

Seamless development (2)

TRANSACTION, PLANE, CUSTOMER, ENGINE...

Example classes

Design

Specification

STATE, USER_COMMAND...

Introduction to Programming – Lecture 26

30

Chair of Software Engineering

Seamless development (3)

Implementation

TRANSACTION, PLANE, CUSTOMER, ENGINE...

Example classes

Design

Specification

STATE, USER_COMMAND...

HASH_TABLE,LINKED_LIST...

Page 11: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

11

Introduction to Programming – Lecture 26

31

Chair of Software Engineering

Seamless development (4)

Implementation

V & V

TRANSACTION, PLANE, CUSTOMER, ENGINE...

TEST_DRIVER, ...

Example classes

Design

Specification

STATE, USER_COMMAND...

HASH_TABLE,LINKED_LIST...

Introduction to Programming – Lecture 26

32

Chair of Software Engineering

Seamless development (5)

Implementation

V & V

TRANSACTION, PLANE, CUSTOMER, ENGINE...

TEST_DRIVER, ...

Example classes

Design

Specification

STATE, USER_COMMAND...

HASH_TABLE,LINKED_LIST...

Genera-lization

AIRCRAFT, ...

Introduction to Programming – Lecture 26

33

Chair of Software Engineering

Generalization

Prepare for reuseFor example:

Remove built-in limitsRemove dependencies on specifics of projectImprove documentation, contracts...Extract commonalities and revamp inheritance hierarchy

Few companies have the guts to provide the budget for this

Page 12: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

12

Introduction to Programming – Lecture 26

34

Chair of Software Engineering

Antoine de Saint-Exupéry

It seems that the sole purpose of the work of engineers, designers, and calculators in drawing offices and research institutes is to polish and smooth out, lighten this seam, balance that wing until it is no longer noticed, until it is no longer a wing attached to a fuselage, but a form fully unfolded, finally freed from the ore, a sort of mysteriously joined whole, and of the same quality as that of a poem. It seems that perfection is reached, not when there is nothing more to add, but when there is no longer anything to remove.

(Terre des Hommes, 1937)

Introduction to Programming – Lecture 26

35

Chair of Software Engineering

Seamless development

Implementation

V & V

TRANSACTION, PLANE, CUSTOMER, ENGINE...

TEST_DRIVER, ...

Example classes

Design

Specification

STATE, USER_COMMAND...

HASH_TABLE,LINKED_LIST...

Genera-lization

AIRCRAFT, ...

Introduction to Programming – Lecture 26

36

Chair of Software Engineering

Reversibility

S

V

DI

S

G

Page 13: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

13

Introduction to Programming – Lecture 26

37

Chair of Software Engineering

The cluster model

I

V

DS

GI

V

DS

G I

V

DS

G

I

V

DS

G

Cluster 1

Cluster 2

Cluster n

Introduction to Programming – Lecture 26

38

Chair of Software Engineering

Agile methods and extreme programming

De-emphasize process and reuse

Emphasize the role of tests to guide the development

Emphasize the role of refactoring

Introduction to Programming – Lecture 26

39

Chair of Software Engineering

Validation and Verification

Not just testing:

Static Analysis tools explore code forpossible deficiencies, e.g. uninitializedvariables

Should be performed throughout the process, not just at the end

Page 14: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

14

Introduction to Programming – Lecture 26

40

Chair of Software Engineering

Software engineering tools

Development environments (compiler, browser, debugger, …): “IDE”Documentation toolsRequirements gathering toolsAnalysis and design toolsConfiguration & version management (CVS, Source Safe…) (also “make” etc.)Formal development and proof toolsIntegrated CASE (Computer-Aided Software Engineering) environments

Introduction to Programming – Lecture 26

41

Chair of Software Engineering

Configuration management

Aim: make sure that versions used for the various components of a system are compatibleWhen poorly done, one of the biggest sources of software catastrophesGood tools exist today, e.g. CVS, Source Safe. Any project not using one of these tools is managed by a complete idiot

Introduction to Programming – Lecture 26

42

Chair of Software Engineering

Formal methods

Use mathematics as the basis for software developmentA software system is viewed as a mathematical theory, progressively refined until directly implementableEvery variant of the theory and every refinement step is provedProof supported by computerized toolsExample: Atelier B, security system of newest Paris Metro line

Page 15: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

15

Introduction to Programming – Lecture 26

43

Chair of Software Engineering

Metrics

Things to measure:Product attributes: lines of code, number of classes, complexity of control structure (“cyclomaticnumber”), complexity and depth of inheritance structure, presence of contracts...Project attributes: number of people, person-months, costs, time to completion, time of various activities (analysis, design, implementation, V&V etc.)

Taking good measurements helps take good measures

Introduction to Programming – Lecture 26

44

Chair of Software Engineering

Cost modelsAttempt to evaluate cost of software development ahead of project, based on estimate of parametersExample: COCOMO (Constructive Cost Model), Barry Boehm

TimeEffort (pm)Program type

2.5 ∗ pm ∗ 0.323.6 ∗ L ∗ 1.20System

2.5 ∗ pm ∗ 0.353.0 ∗ L ∗ 1.12Utility

2.5 ∗ pm ∗ 0.382.4 ∗ L ∗ 1.05Application

L: 1000 ∗ Delivered SourceInstructions (KDSI)

Introduction to Programming – Lecture 26

45

Chair of Software Engineering

Software reliability models

Estimate number of bugs fromCharacteristics of programNumber of bugs found so far

Variant: “Fault injection”

Page 16: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

16

Introduction to Programming – Lecture 26

46

Chair of Software Engineering

Project management

Team specialties: customer relations, analyst, designer, implementer, tester, manager, documenter...

What role for the manager: managerial only, or technical too?

“Chief Programmer teams”

Introduction to Programming – Lecture 26

47

Chair of Software Engineering

Software engineering

In the end it’s code

Don’t underestimate the role of tools, language and, more generally, technology

Bad management kills projectsGood technology makes projects succeed

Introduction to Programming – Lecture 26

48

Chair of Software Engineering

Programming languages

Not just for talking to your computer!

A programming language is a tool for thinking

Page 17: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

17

Introduction to Programming – Lecture 26

49

Chair of Software Engineering

A bit of history

“Plankalkül”, Konrad Zuse, 1940s

Fortran (FORmula TRANSlator), John Backus, IBM, 1954

Algol, 1958/1960

Introduction to Programming – Lecture 26

50

Chair of Software Engineering

Some FORTRAN code

100 IF (N) 150, 160, 170150 A(I) = A(I)**2

READ (“I6”) NGOTO 100

C THE NEXT ONE IS THE TOUGH CASE160 A(I)=A(I)+1

READ (“I6”) NGOTO 100

170 STOPEND

Introduction to Programming – Lecture 26

51

Chair of Software Engineering

Algol

International committee, Europeans and Americans; led to IFIP. Algol 58, Algol 60.

Influenced by (and reaction against) FORTRAN; also influenced by LISP (see next). Recursive procedures, dynamic arrays, block structure, dynamically allocated variables

New language description mechanism: BNF (for Algol 60).

Page 18: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

18

Introduction to Programming – Lecture 26

52

Chair of Software Engineering

Algol W and Pascal

Successors to Algol 60, designed by Niklaus Wirth from ETHAlgol W introduced record structuresPascal emphasized simplicity, data structures (records, pointers).Small language, widely adopted for teaching.Helped trigger the PC revolution through Turbo Pascal from Borland (Philippe Kahn)

Introduction to Programming – Lecture 26

53

Chair of Software Engineering

C

1968: Brian Kernighan and Dennis Richie, AT&T Bell Labs

Initially, closely connected with Unix

Emphasis on low-level machine access: pointers, address arithmetic, conversions

Frantically adopted by industry in the 80s and 90s

Introduction to Programming – Lecture 26

54

Chair of Software Engineering

Lisp and functional languages

LISt Processing, 1959, John McCarthy, MIT then Stanford

Fundamental mechanism is recursive function definition

Numerous successors, e.g. Scheme (MIT)

Functional languages: Haskell, Scheme

Page 19: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

19

Introduction to Programming – Lecture 26

55

Chair of Software Engineering

LISP “lists”

A list is of the form (x1 x2...) where each xi is eitherAn atom (number, identifier etc.)(Recursively) a list:

Examples:()(x1 x2)(x1 (x2 x3) x4 (x5 (x6 () x7)))

((x1 x2)) is not the same as (x1 (x2))

Introduction to Programming – Lecture 26

56

Chair of Software Engineering

LISP function application and definition

The application of function f to arguments a, b, c is written

(f a b c)

Example function definition (Scheme):

(define (factorial n)(if (eq? n 0)

1

(∗ n (factorial (− n 1)))))

Introduction to Programming – Lecture 26

57

Chair of Software Engineering

Basic functions

Let my_list = (A B C)

(CAR my_list) = A(CDR my_list) = (B C)

(CONS A (B C)) = ( A B C)

A B CCAR

CDR

Page 20: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

20

Introduction to Programming – Lecture 26

58

Chair of Software Engineering

Functions working on lists

(define double-all (list)(mapcar

'(lambda (x) (∗ 2 x)) list))

(define (mapcar function f)(if (null? ls) '()

(cons(function (car ls)) (mapcar function (cdr ls))) ) )

Introduction to Programming – Lecture 26

59

Chair of Software Engineering

Object-oriented programming

Simula 67: Algol 60 extensions for simulation, University of Oslo, 1967 (after Simula 1, 1964). Kristen Nygaard, Ole Johan Dahl

Grew into a full-fledged programming language

Smalltalk (Xerox PARC) added ideas from Lisp and innovative user interface ideas. Alan Kay, Adele Goldberg, Daniel Bobrow

Introduction to Programming – Lecture 26

60

Chair of Software Engineering

“Hybrid” languages

Objective-C, around 1984: Smalltalk layer on top of C

C++, around 1985: “C with classes”

Made O-O acceptable to mainstream industry

Key moment: first OOPSLA, 1986

Page 21: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

21

Introduction to Programming – Lecture 26

61

Chair of Software Engineering

Java and C#

C++ with enough restrictions to permit type safety and garbage collection

Java initially marketed for applets in connection with the explosion of the Internet, 1995

C# adds “delegates” (agent-like mechanism)

Introduction to Programming – Lecture 26

62

Chair of Software Engineering

Eiffel

First version goes back to mid-eighties, first demonstrated at OOPSLA 86

Emphasis on software engineering principles: information hiding, Design by Contract, static typing (through genericity), full application of O-O principles

Has found its main application area in mission-critical industrial applications

Introduction to Programming – Lecture 26

63

Chair of Software Engineering

Evaluation

Extremely encouraging resultsLecture videos appreciatedCompleted textbook will help…Advance slides will help…Better TRAFFIC will help…German-language lectures might help…

… but it won’t ever be the first time again!

Page 22: Introduction to Programmingse.inf.ethz.ch/.../ws2003/37-001/slides/26-Intro_en_3up.pdf · 2004. 2. 3. · 2 Introduction to Programming – Lecture 26 4 Chair of Software Engineering

22

Introduction to Programming – Lecture 26

64

Chair of Software Engineering

Thank you *very* much…

… to

StudentsAssistants (including Hilfsassistenten), esp. Michela & SusannePatrick Schoenbach for TRAFFICN.E.T.FILEP project (rectorate)all on mailing list

Introduction to Programming – Lecture 26

65

Chair of Software Engineering

End of lecture 26