From Eiffel and Design by Contract to Trusted Components Bertrand - - PowerPoint PPT Presentation

from eiffel and design by contract to trusted components
SMART_READER_LITE
LIVE PREVIEW

From Eiffel and Design by Contract to Trusted Components Bertrand - - PowerPoint PPT Presentation

From Eiffel and Design by Contract to Trusted Components Bertrand Meyer ETH Zrich / Eiffel Software Budapest, December 2003 1 My background Since 1985: Founder (now Chief Architect) of Eiffel Software, in Santa Barbara. Produces


slide-1
SLIDE 1

1

From Eiffel and Design by Contract to Trusted Components

Bertrand Meyer ETH Zürich / Eiffel Software

Budapest, December 2003

slide-2
SLIDE 2

2

My background

Since 1985: Founder (now Chief Architect) of Eiffel

Software, in Santa Barbara. Produces advanced tools and services to improve software quality, based on Eiffel ideas

Since 2001: Professor of Software Engineering at ETH

Zürich

Also adjunct professor at Monash University in Australia

(since 1998)

slide-3
SLIDE 3

3

Software engineering

The collection of processes, methods, techniques, tools and languages for developing quality operational software.

slide-4
SLIDE 4

4

The challenge

What does it take to bring software engineering to the next

level?

slide-5
SLIDE 5

5

Today’s software is often good enough Overall:

Works most of the time Doesn’t kill too many people Negative effects, esp. financial, are diffuse

Significant improvements since early years:

Better languages Better tools Better practices (configuration management)

slide-6
SLIDE 6

6

Eiffel

Method, language and environment Fully object-oriented; not a hybrid with other approaches Focuses on quality, especially reliability, extendibility and

reusability

Emphasizes simplicity Used for many mission-critical projects in industry International standard in progress through ECMA

slide-7
SLIDE 7

7

Large Eiffel projects in industry

AXA Rosenberg Chicago Board of Trade Boeing Lockheed Martin AMP Investments EMC Hewlett Packard Cap Gemini Ernst & Young

Environmental Protection Agency

Northrop Grumman ENEA

Swedish National Health Board

slide-8
SLIDE 8

8

Environment: the two offerings from Eiffel Software

EiffelStudio (“Classic Eiffel”)

Windows, Unix, Linux, VMS, .NET ...

ENViSioN! for Visual Studio .NET

Projects are compatible

slide-9
SLIDE 9

9

EiffelStudio

Serialization EiffelStore

Executable system

C compilation Jitter Eiffel compilation Browsing, fast compiling (Melting Ice™), debugging, diagrams, metrics...

EiffelBuild

Multiplatform GUI library User classes

EiffelBase

GUI builder

Persistent

  • bjects

General library

EiffelVision WEL Ansi C

Win32 GUI

EiffelWeb

EiffelStudio

Web scripting

IL EiffelMath

Advanced numerics

Eiffel Runtime EiffelNet

Databases (Rel, OO)

Networking

External C/C++/Java .NET Assemblies EiffelCOM

slide-10
SLIDE 10

10

EiffelStudio: Melting Ice™ Technology

Fast recompilation: time depends on size of change, not

size of program

“Freeze” once in a while Optimized compilation: finalize.

slide-11
SLIDE 11

11

Melting Ice Technology

YOUR SYSTEM

MELTED FROZEN

Execution, browsing, debugging, documentation ...

MELTING FREEZING Machine code (from C code)

EIFFELSTUDIO

slide-12
SLIDE 12

12

Portability

Full source-code portability across:

Windows NT, 2000, XP Windows 98, Me Solaris, other commercial Unix variants Linux BSD (Berkeley System Distribution) VMS

slide-13
SLIDE 13

13

Portable graphics

EiffelVision 2 library:

Simple programming model Produce impressive GUI simply and quickly Easy to learn Completely portable across supported platforms Rich set of controls, matches users’ most demanding

needs

Adapts automatically to native look & feel

slide-14
SLIDE 14

14

EiffelVision layers

EiffelVision EiffelVision WEL GEL etc.

slide-15
SLIDE 15

15

Openness to other approaches

Extensive mechanisms to support C and C++ constructs Java interface On .NET, seamless integration with C#, Visual Basic etc.

slide-16
SLIDE 16

16

Special syntax for C/C++ support

class class RECT_STRUCT RECT_STRUCT feature feature --

  • - Access

Access x ( x (a_struct a_struct: POINTER): INTEGER : POINTER): INTEGER is is external external "C "C struct struct RECT access x use < RECT access x use <windows.h windows.h>" >" end end feature feature --

  • - Settings

Settings set_x set_x ( (a_struct a_struct: POINTER; : POINTER; a_x a_x: INTEGER) : INTEGER) is is external external "C "C struct struct RECT access x type RECT access x type int int use < use <windows.h windows.h>" >" end end end end

slide-17
SLIDE 17

17

Performance

Optimizations are automatic: Inlining, dead code

removal…

Garbage collection takes care of memory issues Performance matches the demand of the most critical

industry applications

slide-18
SLIDE 18

18

Eiffel mechanisms

Classes, objects, ... Single and multiple inheritance Inheritance facilities: redefinition, undefinition, renaming Genericity, constrained and unconstrained Safe covariance Disciplined exception handling, based on principles of Design by

Contract

Full GC Agents (power of functional programming in O-O!) Unrestricted streaming: files, databases, networks...

slide-19
SLIDE 19

19

Genericity

Since 1986 (First time genericity & inheritance combined) Unconstrained LIST [G] e.g. LIST [INTEGER], LIST [PROFESSOR] Constrained HASH_TABLE [G ―> HASHABLE] VECTOR [G ―> NUMERIC]

slide-20
SLIDE 20

20

Multiple inheritance

RESTAURANT_ CAR RESTAURANT TRAIN_CAR

slide-21
SLIDE 21

21

Development: the traditional model

Separate tools:

Programming environment Analysis & design tools, e.g. UML

Consequences:

Hard to keep model, implementation, documentation

consistent

Constantly reconciling views Inflexible, hard to maintain systems Hard to accommodate bouts of late wisdom Wastes efforts Damages quality

slide-22
SLIDE 22

22

Development: the Eiffel model

Seamless development:

Single set of notation, tools, concepts, principles throughout Eiffel is as much for analysis & design as for implementation

& maintenance

Continuous, incremental development Keep model, implementation and documentation consistent Reversibility: can go back and forth Saves money: invest in single set of tools Boosts quality

slide-23
SLIDE 23

23

Seamless development (1)

TRANSACTION, PLANE, CUSTOMER, ENGINE...

Specification Example classes

slide-24
SLIDE 24

24

Seamless development (2)

Design

Specification

TRANSACTION, PLANE, CUSTOMER, ENGINE... STATE, USER_COMMAND...

Example classes

slide-25
SLIDE 25

25

Seamless development (3)

Implementation

Design

Specification

TRANSACTION, PLANE, CUSTOMER, ENGINE... STATE, USER_COMMAND... HASH_TABLE, LINKED_LIST...

Example classes

slide-26
SLIDE 26

26

Seamless development (4)

Implementation

V & V

Design

Specification

TRANSACTION, PLANE, CUSTOMER, ENGINE... STATE, USER_COMMAND... HASH_TABLE, LINKED_LIST... TEST_DRIVER, ...

Example classes

slide-27
SLIDE 27

27

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, ...

slide-28
SLIDE 28

28

Eiffel for analysis

Precondition

  • - Specified only.
  • - not implemented.

Postcondition

deferred class VAT inherit TANK feature in_valve, out_valve: VALVE fill is

  • - Fill the vat.

require in_valve.open

  • ut_valve.closed

deferred ensure in_valve.closed

  • ut_valve.closed

is_full end empty, is_full, is_empty, gauge, maximum, ... [Other features] ... invariant is_full = (gauge >= 0.97 * maximum) and (gauge <= 1.03 * maximum) end

Class invariant

slide-29
SLIDE 29

29

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, ...

slide-30
SLIDE 30

30

Reversibility

S V D I S G

slide-31
SLIDE 31

31

Inheritance structure (in EiffelStudio)

slide-32
SLIDE 32

32

Design by Contract™

Get things right in the first place Automatic documentation Self-debugging, self-testing code Get inheritance right Give managers the right control tools

slide-33
SLIDE 33

33

Applications of contracts

  • Analysis, design, implementation:

Get the software right from the start

  • Testing, debugging, quality assurance
  • Management, maintenance/evolution
  • Inheritance
  • Documentation
slide-34
SLIDE 34

34

Design by Contract

A discipline of analysis, design, implementation,

management

slide-35
SLIDE 35

35

A view of software construction

Constructing systems as structured collections of

cooperating software elements — suppliers and clients — cooperating on the basis of clear definitions of obligations and benefits.

These definitions are the contracts.

slide-36
SLIDE 36

36

Design by Contract (cont’d)

  • Every software element is intended to satisfy a certain goal, for the

benefit of other software elements (and ultimately of human users).

  • This goal is the element’s contract.
  • The contract of any software element should be
  • Explicit.
  • Part of the software element itself.
slide-37
SLIDE 37

37

A human contract

Client Supplier

(Satisfy precondition:) Bring package before 4 p.m.; pay fee. (Satisfy postcondition:) Deliver package by 10 a.m. next day.

OBLIGATIONS

(From postcondition:) Get package delivered by 10 a.m. next day. (From precondition:) Not required to do anything if package delivered after 4 p.m.,

  • r fee not paid.

BENEFITS

deliver

slide-38
SLIDE 38

38

Properties of contracts

A contract:

  • Binds two parties (or more): supplier, client.
  • Is explicit (written).
  • Specifies mutual obligations and benefits.
  • Usually maps obligation for one of the parties into benefit for the
  • ther, and conversely.
  • Has no hidden clauses: obligations are those specified.
  • Often relies, implicitly or explicitly, on general rules applicable to all

contracts (laws, regulations, standard practices).

slide-39
SLIDE 39

39

A human contract

Client Supplier

(Satisfy precondition:) Bring package before 4 p.m.; pay fee. (Satisfy postcondition:) Deliver package by 10 a.m. next day.

OBLIGATIONS

(From postcondition:) Get package delivered by 10 a.m. next day. (From precondition:) Not required to do anything if package delivered after 4 p.m.,

  • r fee not paid.

BENEFITS

deliver

slide-40
SLIDE 40

40

A class without contracts

class ACCOUNT feature -- Access balance: INTEGER

  • - Balance

Minimum_balance: INTEGER is 1000

  • - Minimum balance

feature {NONE} -- Implementation of deposit and withdrawal add (sum: INTEGER) is

  • - Add sum to the balance (secret procedure).

do balance := balance + sum end

slide-41
SLIDE 41

41

Without contracts (cont’d)

feature -- Deposit and withdrawal operations deposit (sum: INTEGER) is

  • - Deposit sum into the account.

do add (sum) end withdraw (sum: INTEGER) is

  • - Withdraw sum from the account.

do add (– sum) end may_withdraw (sum: INTEGER): BOOLEAN is

  • - Is it permitted to withdraw sum from the account?

do Result := (balance - sum >= Minimum_balance) end end

slide-42
SLIDE 42

42

Introducing contracts

class ACCOUNT create make feature {NONE} -- Initialization make (initial_amount: INTEGER) is

  • - Set up account with initial_amount.

require large_enough: initial_amount >= Minimum_balance do balance := initial_amount ensure balance_set: balance = initial_amount end

slide-43
SLIDE 43

43

Introducing contracts (cont’d)

feature -- Access balance: INTEGER

  • - Balance

Minimum_balance: INTEGER is 1000

  • - Minimum balance

feature {NONE} -- Implementation of deposit and withdrawal add (sum: INTEGER) is

  • - Add sum to the balance (secret procedure).

do balance := balance + sum ensure increased: balance = old balance + sum end

slide-44
SLIDE 44

44

With contracts (cont’d)

feature -- Deposit and withdrawal operations deposit (sum: INTEGER) is

  • - Deposit sum into the account.

require not_too_small: sum >= 0 do add (sum) ensure increased: balance = old balance + sum end

slide-45
SLIDE 45

45

With contracts (cont’d)

withdraw (sum: INTEGER) is

  • - Withdraw sum from the account.

require not_too_small: sum >= 0 not_too_big: sum <= balance – Minimum_balance do add (– sum)

  • - i.e. balance := balance – sum

ensure decreased: balance = old balance - sum end

slide-46
SLIDE 46

46

The contract

Client Supplier

(Satisfy precondition:) Make sure sum is neither too small nor too big. (Satisfy postcondition:) Update account for withdrawal of sum.

OBLIGATIONS

(From postcondition:) Get account updated with sum withdrawn. (From precondition:) Simpler processing: may assume sum is within allowable bounds.

BENEFITS

withdraw

slide-47
SLIDE 47

47

The imperative and the applicative

do balance := balance - sum ensure balance = old balance - sum PRESCRIPTIVE DESCRIPTIVE How? Operational Implementation Command Instruction Imperative What? Denotational Specification Query Expression Applicative

slide-48
SLIDE 48

48

With contracts (end)

may_withdraw (sum: INTEGER): BOOLEAN is

  • - Is it permitted to withdraw sum from the
  • - account?

do Result := (balance - sum >= Minimum_balance) end invariant not_under_minimum: balance >= Minimum_balance end

slide-49
SLIDE 49

49

The class invariant

Consistency constraint applicable to all instances of a

class.

Must be satisfied:

  • After creation.
  • After execution of any feature by any client.

(Qualified calls only: a.f (...))

slide-50
SLIDE 50

50

Lists with cursors

before after count+1

Valid cursor positions

item 1 count

slide-51
SLIDE 51

51

From the invariant of class LIST

Valid cursor positions

slide-52
SLIDE 52

52

Applications of contracts

  • Analysis, design, implementation:

Get the software right from the start

  • Testing, debugging, quality assurance
  • Management, maintenance/evolution
  • Inheritance
  • Documentation
slide-53
SLIDE 53

53

Contracts and documentation

Rich documentation produced automatically from class text Available in text, HTML, Postscript, RTF, FrameMaker and

many other formats

Numerous views, textual and graphical

slide-54
SLIDE 54

54

Contracts as automatic documentation

Demo LINKED_LIST Documentation, generated by EiffelStudio

slide-55
SLIDE 55

55

Contracts for analysis

Precondition

  • - Specified only.
  • - not implemented.

Postcondition

deferred class VAT inherit TANK feature in_valve, out_valve: VALVE fill is

  • - Fill the vat.

require in_valve.open

  • ut_valve.closed

deferred ensure in_valve.closed

  • ut_valve.closed

is_full end empty, is_full, is_empty, gauge, maximum, ... [Other features] ... invariant is_full = (gauge >= 0.97 * maximum) and (gauge <= 1.03 * maximum) end

Class invariant

slide-56
SLIDE 56

56

Contracts for testing and debugging

Contracts express implicit assumptions behind code A bug is a discrepancy between intent and code Contracts state the intent! In EiffelStudio: select compilation option for run-time

contract monitoring. Can be set a system, cluster, class level.

May disable monitoring when releasing software A revolutionary form of quality assurance

slide-57
SLIDE 57

57

Contract monitoring

A contract violation always signals a bug:

Precondition violation: bug in client Postcondition violation: bug in routine

slide-58
SLIDE 58

58

Contracts and inheritance: invariants

Invariant Inheritance rule:

  • The invariant of a class automatically includes the invariant

clauses from all its parents, “and”-ed.

Accumulated result visible in flat and interface forms.

slide-59
SLIDE 59

59

Contracts and inheritance

r is require α ensure β C A a1: A a1.r (…) … D

Correct call: if a1.α then a1.r (...)

  • - Here a1.β holds.

end

B r is require γ ensure δ

slide-60
SLIDE 60

60

Assertion redeclaration rule

When redeclaring a routine:

  • Precondition may only be kept or weakened.
  • Postcondition may only be kept or strengthened.
slide-61
SLIDE 61

61

Assertion redeclaration rule in Eiffel

  • A simple language rule does the trick!
  • Redefined version may have nothing (assertions kept by default), or

require else new_pre ensure then new_post

  • Resulting assertions are:
  • original_precondition or new_pre
  • original_postcondition and new_post
slide-62
SLIDE 62

62

Principles in the Eiffel method

Design by Contract Abstraction Information hiding Seamlessness Reversibility Open-Closed principle Single choice principle Single model principle Uniform access principle Command-query separation principle Option-operand separation principle Style matters

slide-63
SLIDE 63

63

Single-model principle All the information about a system should be in the system‘s text

Automatic tools extract various views:

  • Interface
  • Implementation
  • Inheritance structure
  • Client-supplier structure
  • Operations (features)
  • etc.
slide-64
SLIDE 64

64

From Eiffel and Design by Contract...

... to Trusted Components

slide-65
SLIDE 65

65

Today’s software is often good enough Overall:

Works most of the time Doesn’t kill too many people Negative effects, esp. financial, are diffuse

Significant improvements since early years:

Better languages Better tools Better practices (configuration management)

slide-66
SLIDE 66

66

From “good enough” to good?

Beyond “good enough”, quality is economically bad He who perfects, dies

Actual Optimal Quality

1 2 3 4

Time

Release

slide-67
SLIDE 67

67

From “good enough” to good?

Beyond “good enough”, quality is economically bad He who perfects, dies

Actual Optimal Quality

1 2 3 4

Release

Time

slide-68
SLIDE 68

68

The economic argument

Stable system:

  • Sum of individual optima = Global optimum

Non-component-based development:

  • Individual optimum = “Good Enough Software”
  • Improvements: I am responsible!

Component-based development:

  • Interest of both consumer and producer: Better components
  • Improvements: Producer does the job
slide-69
SLIDE 69

69

Quality through reuse

The good news:

Reuse scales up everything

slide-70
SLIDE 70

70

Quality through reuse

The good news:

Reuse scales up everything

The bad news:

Reuse scales up everything

slide-71
SLIDE 71

71

Software design in the future Component-based for

  • Guaranteed quality
  • Faster time to market
  • Ease of maintenance
  • Standardization of software practices
  • Preservation of know-how
slide-72
SLIDE 72

72

Trusted components

Confluence of

  • Quality engineering
  • Reuse
slide-73
SLIDE 73

73

Hennessy (Stanford)

“Most of the improvement in the reliability of computer

systems has come from improvement in the basic components”

“You’ll see ever increasing portions of the effort devoted to

design and verification”

slide-74
SLIDE 74

74

Component quality: the inevitable issue The key issue

  • Bad-quality components are major risk

Deficiencies scale up, too

  • High-quality components could transform the state of the

software industry (if it wanted to — currently doesn’t)

slide-75
SLIDE 75

75

Where to focus effort?

Compilers, operating systems Basic components Applications Specialized components

slide-76
SLIDE 76

76

Perfectionism

Component design should be Formula-1 racing of

software “engineering”.

In component development, perfectionism is good.

slide-77
SLIDE 77

77

Our experience: Eiffelbase

Collection classes (“Knuthware”) Consistency principle Strict design principles: command-query separation,

  • perand-option separation, taxonomy, uniform access...

Strict interface and style rules

slide-78
SLIDE 78

78

Eiffelbase hierarchy

CONTAINER BOX FINITE INFINITE BOUNDED UNBOUNDED FIXED RESIZABLE COLLECTION

BAG SET TABLE ACTIVE SUBSET

DISPENSER INDEXABLE CURSOR_ STRUCTURE SEQUENCE TRAVERSABLE HIERAR_ CHICAL LINEAR BILINEAR

* * * * * * * * * * * * * * * * * * * * * *

COUNTABLE

*

slide-79
SLIDE 79

79

Trusted Components: how to get there

Low road:

  • Component Certification

Component Certification Center

  • Component Quality Model

High road:

  • Proofs of correctness
slide-80
SLIDE 80

80

A Component Certification Center

Principles Methods and processes Standards: Component Quality Model Services for component providers and component

consumers

slide-81
SLIDE 81

81

Component Quality Model

A: Acceptance B: Behavior C: Constraints D: Design E: Extension

slide-82
SLIDE 82

82

Component Quality Model

A: Acceptance B: Behavior C: Constraints D: Design E: Extension A.1 Some reuse attested A.2 Producer reputation A.3 Published evaluations

slide-83
SLIDE 83

83

Component Quality Model

A: Acceptance B: Behavior C: Constraints D: Design E: Extension B.1 Examples B.2 Usage documentation B.3 Preconditioned B.4 Some postconditions B.5 Full postconditions B.6 Observable invariants

slide-84
SLIDE 84

84

Component Quality Model

A: Acceptance B: Behavior C: Constraints D: Design E: Extension C.1 Platform spec C.2 Ease of use C.3 Response time C.4 Memory occupation C.5 Bandwidth C.6 Availability C.7 Security

slide-85
SLIDE 85

85

Contract levels

1.

Type

2.

Functional specification

3.

Performance specification

4.

Quality of Service (Source: Jézéquel, Mingins et al.)

slide-86
SLIDE 86

86

Component Quality Model

A: Acceptance B: Behavior C: Constraints D: Design E: Extension E.1 Portable across platforms E.2 Mechanisms for addition E.3 Mechanisms for redefinition E.4 User action pluggability

slide-87
SLIDE 87

87

Component Quality Model

A: Acceptance B: Behavior C: Constraints D: Design E: Extension D.1 Precise dependency doc D.2 Consistent API rules D.3 Strict design rules D.4 Extensive test cases D.5 Some proved properties D.6 Proofs of preconditions, postconditions & invariants

slide-88
SLIDE 88

88

Proof technology and formal methods

Constant advances in recent years Most applications: life-critical systems in transportation,

defense etc. Example: security system of Paris Metro METEOR line, using the B method

slide-89
SLIDE 89

89

Formal methods and reuse

Components should be good Proofs should be economical!

slide-90
SLIDE 90

90

“Proving classes”

EiffelBase libraries (fundamental data structures and algorithms):

Classes are equipped with contracts “Proving a class” means proving that the implementation

satisfies the contracts

slide-91
SLIDE 91

91

Scope of our work at ETH: basics

Help move software technology to the next level through

  • Trusted Components
  • Advanced O-O techniques
  • Teaching (including introductory)

Approaches of special interest

  • Eiffel
  • .NET
  • B
slide-92
SLIDE 92

92

Scope of our work at ETH: other

Journal of Object Technology JOT

www.jot.fm

Numerous workshops and conferences LASER (Laboratory for Applied Software Engineering

Research); summer school starting September 2004

slide-93
SLIDE 93

93

Teaching introductory programming today

  • Long, prestigious tradition of teaching programming at ETH
  • Ups and downs of high-tech economy
  • Widely diverse student motivations, skills
  • Some have considerable operational knowledge
  • New forms of development: “Google-and-Paste” programming
  • Short-term pressures (e.g. families), IT industry fads
  • The “Bologna process”
slide-94
SLIDE 94

94

The objectives

Educate students so that they will:

Understand today’s software engineering. Become competent professionals. Find work and have a successful career.

slide-95
SLIDE 95

95

“Outside-in”

The key skill that we should convey: abstraction Teach, don’t preach.

Start from libraries “Progressive opening of the black boxes”, “Inverted Curriculum” From programmer to producer Not bottom-up or top-down; outside-in.

Students are able, right from the start, to “program” impressive and significant applications.

slide-96
SLIDE 96

96

My first program

class TOUR inherit TRANSPORT feature explore is

  • - Prepare
  • - and animate
  • - route

do Paris.display Louvre.spotlight Line8.highlight Route1.animate end end

Text to input

slide-97
SLIDE 97

97

Summary

  • Bring every one of your developers to the level of your

best developers

  • Bring every one of your development days to the level of

your best days

  • Open, portable, reusable, flexible, efficient
slide-98
SLIDE 98

98

For info “Object-Oriented Software Construction”, 2nd edition Prentice Hall http://www.eiffel.com http://se.inf.ethz.ch http://www.inf.ethz.ch/~meyer