Building bug-free O-O software: An introduction to Design by Contract Eiffel Software Presented by Bert Bruce.

Slides:



Advertisements
Similar presentations
Where Agile Meets Formal Methods
Advertisements

Construction process lasts until coding and testing is completed consists of design and implementation reasons for this phase –analysis model is not sufficiently.
Configuration management
Design by Contract.
Ceg860(Prasad)L10DC1 Design by Contract Invariants Pre-post conditions : Rights and Obligations Exceptions : Contract Violations.
Building Bug-Free O-O Software: An Introduction to Design By Contract A presentation about Design By Contract and the Eiffel software development tool.
Carlos D. Rivera February 28, 2007 Design-by-Contract.
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Design by Contract. Design by contract is the process of developing software based on the notion of contracts between objects, which are expressed as.
ISBN Chapter 3 Describing Syntax and Semantics.
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
Design by Contract ™. 2 Design by Contract A discipline of analysis, design, implementation, management.
Feb 2003 R McFadyen1 Contracts (Ch 13) Used to help understand requirements more completely based on assertions; assertions are applicable to any.
Software Engineering and Design Principles Chapter 1.
Chair of Software Engineering ATOT - Lecture 10, 5 May Advanced Topics in Object Technology Bertrand Meyer.
Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;
-5- Exception handling What is an exception? “An abnormal event” Not a very precise definition Informally: something that you don’t want to happen.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Software Testing and Quality Assurance
CS 501: Software Engineering Fall 2000 Lecture 16 System Architecture III Distributed Objects.
Static and Dynamic Contract Verifiers For Java Hongming Liu.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
Karlstad University Computer Science Design Contracts and Error Management Design Contracts and Errors A Software Development Strategy (anpassad för PUMA)
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 6: Object Creation.
1 Introduction to: Design by Contract Fall 2005 OOPD John Anthony.
Describing Syntax and Semantics
Eiffel Language and Design by Contract Contract –An agreement between the client and the supplier Characteristics –Expects some benefits and is prepared.
Adding Contracts to Ada Ehud Lamm Adding Design By Contract to Ada.
1 © Wolfgang Pelz Design by Contract Design by Contract™ Based on material drawn from: Bertrand.
Configuration Management
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
Abstract data types What does ‘ abstract ’ mean? From Latin: to ‘ pull out ’— the essentials –To defer or hide the details –Abstraction emphasizes essentials.
Computer Science 340 Software Design & Testing Design By Contract.
Ranga Rodrigo. Class is central to object oriented programming.
PRAGMATIC PARANOIA Steven Hadfield & Anthony Rice.
Testing. Definition From the dictionary- the means by which the presence, quality, or genuineness of anything is determined; a means of trial. For software.
Design by contract. A software system is viewed as a set of communicating components whose interaction is based on precisely defined specifications of.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
Tammy Dahlgren with Tom Epperly, Scott Kohn, and Gary Kumfert Center for Applied Scientific Computing Common Component Architecture Working Group October.
Design by Contract in Java Concept and Comparison.
SWE 619 © Paul Ammann Procedural Abstraction and Design by Contract Paul Ammann Information & Software Engineering SWE 619 Software Construction cs.gmu.edu/~pammann/
Chapter 25 Formal Methods Formal methods Specify program using math Develop program using math Prove program matches specification using.
Chapter 18 Object Database Management Systems. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Motivation for object.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
1 Devon M. Simmonds, Computer Science Department Design by Contract Devon M. Simmonds Computer Science Department University of North Carolina, Wilmington.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
L13: Design by Contract Definition Reliability Correctness Pre- and post-condition Asserts and Exceptions Weak & Strong Conditions Class invariants Conditions.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Copyright © 2004, Keith D Swenson, All Rights Reserved. OASIS Asynchronous Service Access Protocol (ASAP) Tutorial Overview, OASIS ASAP TC May 4, 2004.
DBC NOTES. Design By Contract l A contract carries mutual obligations and benefits. l The client should only call a routine when the routine’s pre-condition.
1 Exceptions When the Contract is Broken. 2 Definitions A routine call succeeds if it terminates its execution in a state satisfying its contract A routine.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Design by Contract. The Goal Ensure the correctness of our software (correctness) Recover when it is not correct anyway (robustness) Correctness: Assertions.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
CSC 108H: Introduction to Computer Programming
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
Component Based Software Engineering
Arab Open University 2nd Semester, M301 Unit 5
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Computer Science 340 Software Design & Testing
Presentation transcript:

Building bug-free O-O software: An introduction to Design by Contract Eiffel Software Presented by Bert Bruce

Software Quality In an early paper we learned that most S/W companies consider time- to-market so important that Quality concerns get little attention But reliable software means much lower support costs and better long- term productivity Many small companies fail because they don’t plan for their success by building in the requisite Quality

Software Quality Reliability is a major component Correctness Does what it is supposed to Robustness Handles abnormal conditions Reliable code can be produced using Static typing Automatic garbage collection Lots of re-use But we can do more….

Design by Contract The term “Design by Contract is trademarked by Eiffel Software Presumably one can use the term in lower case without violating their trademark Design by Contract is a software development methodology Eiffel is a language that embodies DbC But can be used in other languages as well

Design by Contract Software - set of communicating components Interaction should be based on precise and complete set of mutual obligations E.g. contracts Actually all software is design by contract The issue - is the contract Verbal? Informal or formal? Implied or explicit? Complete? Binding?

A Good Example of a Bad Example Data base system for queries on multi-terabyte databases Ran on massively parallel SIMD machine (up to processors) Execute complex queries in minutes rather than hours Competing with Teradata Wonderful Computer Science Based on founder’s PhD thesis Horrible Software Engineering

A Good Example of a Bad Example SQL Parser Parallelizer Code Generator Runtime Environment Informal Contracts I don’t remember seeing anything in writing Query

A Good Example of a Bad Example Could never work on more than simplest cases Took entire team to find and fix every bug No ability to test harness components Many bugs were of the “Oh, I thought you were going to…” type (informal, unwritten, implied contracts) Ultimately burned a lot of VC money and died

Specifications DbC is based on specifications As precise as possible As complete as possible What software will do What software won’t do Very difficult to do completely But even a small amount can reap big rewards Having no spec => little chance code will do what is wanted

Specifications DbC says every software element should have a specification Embed the spec in the code Insures they are coupled Only one representation – no translation or loss of sync Can be used for efficient implementation Seamless – throughout the software lifecycle Only one document Provides basis for testing

Contract An agreement between a supplier and a client Each has obligations and benefits Example – a dictionary write procedure Client assures preconditions – table is not full and key is not empty string Client benefits from postconditions – table has been updated with proper key Supplier must insure postcondition – table has been updated Supplier may assume precondition – no need to do anything if table full or empty key

Contract Sample code: put (x: ELEMENT; key: STRING) is -- Insert x so that it will be retrievable through key. require count <= capacity not key.empty do... Some insertion algorithm... ensure has (x) Item (key) = x count = old count + 1 end Preconditions Postconditions

Implementation Eiffel has these keywords built into the language Other languages can support this by extensions Use keywords in formatted comments Use preprocessor to process these comments Commercial products available for C, C++, C#, Java, PHP, Perl and others

Contract as a Design Tool Use the notation to design modules before implementation Code can be added directly later No need to translate from a specification document Allows system to be modeled before implementation Implementation does not need to (and should not) check the contract

Design Example Chemical plant Objects in model: Tank, pipe, valve, control room,…. Method to fill tank might be: fill is -- Fill tank with liquid require in_valve.open out_valve.closed deferred -- i.e., no implementation ensure in_valve.closed out_valve.closed Is_full end

Invariants Class variable property True in all instances of the class Provide legal range or characteristics for a variable Independent of method code Examples 0 <= count// limits range count <= maxVal// of count getsOvertime = (status == nonExempt) and (hours > 40)

Invariants Invariants characterize the class Not just value at the moment, but always Part of contract Independent of code Relieve the implementation code of the responsibility to check for legal values

Documentation Single source file makes it easy to document the code Class code without the implementation code is the contract i.e. Module names, parameters, requires, ensures, invariants Provides a communication tool for non-programmers E.g. managers, PMs, customers, etc.

Testing Preconditions and postconditions are like asserts Selectively compile code into module to test the conditions Possible options: Preconditions only Pre and postconditions Invariants All assertions

Testing The compiled-in code will find run- time design and implementation flaws during QA cycle The testing instrumentation can be used just for testing and not compiled in for shipping product

Inheritance Subclasses inherit the parent class contract Principle of Subcontracting: a subclass may weaken the precondition but not strengthen it and strengthen a postcondition but not weaken it To “weaken” means allowing a larger set of conditions This principle ensures compatible semantics for subclasses

Exception Handling An exception represents the failure of a module to fulfill a contract Hardware problem Called routine failed Bug in implementation Exception Options Retry Organized Panic Clean up and exit Treat as False Alarm

Exception Handling In Eiffel, an exception invokes a “rescue” clause At first blush, like a “catch”, but more powerful Rescue clause can include a “retry” invocation to re-execute the code body of the module Local variables not re-initialized on retry, so code can keep state information like a retry count

Future Work Extensions for concurrent programming and distributed objects Extended specification language constructs for a richer set of assertions Possible examples – side effect constraints or performance constraints

Summary In the real world, good contracts, treaties, etc. that are met make things flow smoothly Bad or unmet contracts cause chaos Modeling software development on what works in the real world makes a lot of sense I wish I had known about DbC many years ago