CSC/ECE 517 Fall 2011/ch6 6a pc: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 6: Line 6:
A major concern in software design is Reliability, which depends on two factors: 1) Correctness - system's ability to perform its job according to the specification and 2) Robustness - handling abnormal conditions. Reliability is especially important in Object oriented software because of the additional complexity imposed by Reusability. Some of the common problems encountered when writing software include:  
A major concern in software design is Reliability, which depends on two factors: 1) Correctness - system's ability to perform its job according to the specification and 2) Robustness - handling abnormal conditions. Reliability is especially important in Object oriented software because of the additional complexity imposed by Reusability. Some of the common problems encountered when writing software include:  
* System failure - CPU crash, Disk/Memory access errors, Network errors
* System failure - CPU crash, Disk/Memory access errors, Network errors
* Invalid input data - Out of range data, Bad file name,etc
* Invalid input data - Out of range data, Bad file name,etc.
* Programming errors - Memory leaks, Buffer overruns, etc.   
* Programming errors - Memory leaks, Buffer overruns, etc.   


The last two are the issues addressed by "Programming by contract" paradigm.  
There are many programming language features that help tackle these issues. For instance, Static typing, for example, is a major help for catching inconsistencies before they have had time to become bugs. Similarly Garbage collection helps to remove the specter of devious memory management errors.  Various software design methodologies also come handy when dealing with complex software. For instance, reusability itself can help eliminate lots of bugs, if we are reusing existing code that has already been thoroughly tested and deployed. Polymorphism also helps in handling issues related to maintainability by reducing the size of the code and making it more elegant. But in a large and complex software involving multiple developers, we need a systematic approach of specifying and implementing object-oriented software elements and their interactions. This is exactly what  "Programming by contract" promises to do.  
 
=== Programming by contract ===
=== Programming by contract ===
=== Contract and Inheritance ===
=== Contract and Inheritance ===

Revision as of 19:15, 15 November 2011

6a (was 5c). Lecture 18, Programming by contract. My notes for Lecture 18 are largely taken from 20-year-old articles by Bertrand Meyer. The principles are timeless, but there are undoubtedly new embellishments that would provide better background to the topics discussed in the lecture. Write a narrative, generally following the lecture organization, that explains programming by contract in more detail.

Introduction

Software Reliability

A major concern in software design is Reliability, which depends on two factors: 1) Correctness - system's ability to perform its job according to the specification and 2) Robustness - handling abnormal conditions. Reliability is especially important in Object oriented software because of the additional complexity imposed by Reusability. Some of the common problems encountered when writing software include:

  • System failure - CPU crash, Disk/Memory access errors, Network errors
  • Invalid input data - Out of range data, Bad file name,etc.
  • Programming errors - Memory leaks, Buffer overruns, etc.

There are many programming language features that help tackle these issues. For instance, Static typing, for example, is a major help for catching inconsistencies before they have had time to become bugs. Similarly Garbage collection helps to remove the specter of devious memory management errors. Various software design methodologies also come handy when dealing with complex software. For instance, reusability itself can help eliminate lots of bugs, if we are reusing existing code that has already been thoroughly tested and deployed. Polymorphism also helps in handling issues related to maintainability by reducing the size of the code and making it more elegant. But in a large and complex software involving multiple developers, we need a systematic approach of specifying and implementing object-oriented software elements and their interactions. This is exactly what "Programming by contract" promises to do.

Programming by contract

Contract and Inheritance

Terminology

Preconditions

Postconditions

Invariants

Assertions

Comparison with Defensive Programming

Languages with Native Support

Runtime Checking

Static Checking