“Discipline is the refining fire by which talent becomes ability.” – Roy L. Smith Thought for the Day.

Slides:



Advertisements
Similar presentations
Design by Contract.
Advertisements

1. Define the concept of assertions. 1 Explain the use of assertions. 2 Create Java program using assertions. 3 Run Java program using assertions. 4 2.
Detecting Bugs Using Assertions Ben Scribner. Defining the Problem  Bugs exist  Unexpected errors happen Hardware failures Loss of data Data may exist.
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
Code Documentation. Important!  It’s for you  It’s for others.
Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
CSE Winter 2008 Introduction to Program Verification symbolic execution continued.
ITEC200 Week02 Program Correctness and Efficiency.
Software Engineering and Design Principles Chapter 1.
Design Issues. Where to put class definitions  What goes in a source file? At most 1 public class At most 1 public class Other “helper” classes as needed.
Software Testing and Quality Assurance
Static and Dynamic Contract Verifiers For Java Hongming Liu.
Information Hiding and Encapsulation
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
Chapter 1 Principles of Programming and Software Engineering.
CSC 395 – Software Engineering Lecture 21: Overview of the Term & What Goes in a Data Dictionary.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Lecturer: Dr. AJ Bieszczad Chapter 76-1 Software engineering standards Standards for you Standards for others Matching design with implementation.
MS thesis/project ideas for MS students in the Department of Computer Science at the University of Minnesota Duluth suggestions by Dr Andrew Brooks, Heller.
CH07: Writing the Programs Does not teach you how to program, but point out some software engineering practices that you should should keep in mind as.
Computer Science 340 Software Design & Testing Design By Contract.
Language Evaluation Criteria
Introduction CSE 1310 – Introduction to Computers and Programming
Fruitful functions. Return values The built-in functions we have used, such as abs, pow, int, max, and range, have produced results. Calling each of these.
1 Shawlands Academy Higher Computing Software Development Unit.
COSO 1030 Section 2 Software Engineering Concepts and Computation Complexity.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
COP 3530 PROGRAM, FILE & DATA STRUCTURES Syllabus Syllabus Lab Information Lab Information Overrides Overrides Questions? Questions?
CS Fall 2007 Dr. Barbara Boucher Owens. CS 2 Text –Main, Michael. Data Structures & Other Objects in Java Third Edition Objectives –Master building.
1 Assertions. 2 assertions communicate assumptions about the state of the program, and stop processing if they turn out to be false very often comments.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
“The greatest crimes do not arise from a want of feeling for others but from an over-sensibility for ourselves and an over-indulgence to our own desires.”
CSE 219 Computer Science III Program Design Principles.
Design by Contract in Java Concept and Comparison.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Programming Life Cycle Problem analysisunderstand the problem Requirements definition specify what program will do High- and low-level designhow it meets.
The Software Development Process
Pre- and postconditions, Using assertions and exceptions 1 Pre- and postconditions Using assertions and exceptions.
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.
Exceptions and Assertions Chapter 15 – CSCI 1302.
Class Design I Class Contracts Readings: 2 nd Ed: Section 9.5, Advanced Topic nd Ed: Section 8.5, Advanced Topic 8.2 Some ideas come from: “Practical.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
Defensive Programming CNS 3370 Copyright 2003, Fresh Sources, Inc.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
Chapter 2 Comments, Conditions, Assertions Comments Preconditions Postconditions Assertions.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
1 Introduction 1. Why Data Structures? 2. What AreData Structure? 3. Phases of Software Development 4. Precondition and Postcondition 5. Examples.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
Chapter 2 Principles of Programming and Software Engineering.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
Software Design and Development Development Methodoligies Computing Science.
Implementation Topics Describe –Characteristics of good implementations –Best practices to achieve them Understand role of comments Learn debugging techniques.
Principles of Programming & Software Engineering
Software Testing.
Logger, Assert and Invariants
Topics: jGRASP editor ideosyncrasies assert debugger.
Principles of Programming and Software Engineering
CSE 143 Error Handling [Section 2.8] 3/30/98 CSE 143.
Programming in Java Assertion.
Slides by Steve Armstrong LeTourneau University Longview, TX
CSC 143 Error Handling Kinds of errors: invalid input vs programming bugs How to handle: Bugs: use assert to trap during testing Bad data: should never.
Java Modeling Language (JML)
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Computer Science 340 Software Design & Testing
Chapter 9: Implementation
Presentation transcript:

“Discipline is the refining fire by which talent becomes ability.” – Roy L. Smith Thought for the Day

Criteria for judging software quality: –Correctness –Ease-of-use –Generality –Efficiency –Portability –Clarity –Ease of coding and testing –Ease of modification Writing Good Programs

Quality Criteria (cont.) Generality and Efficiency –Often in tension –Try to solve a class of problems, not just one specific problem Portability –Keep to standard features

Quality Criteria (cont.) Clarity –How easily can the program be understood? Well-structured program Comments Good names for variables, methods and classes –Follow conventions for identifier names Simplicity of algorithm Good layout –Indentation, etc.

Quality Criteria (cont.) Ease of Coding and Testing –Well structured (modular) programs –Leave test code in program (commented out if necessary) Ease of Modification –Well written program –Modular design

Techniques for Improving Program Quality Preconditions and Postconditions Assertions Automatic system documentation

Preconditions and Postconditions We can characterise a method by the program’s state before and after the method is executed

“Before and After”

Preconditions and Postconditions Preconditions –Assumptions about the “before” state Postconditions –Statements about the “after” state Often expressed as comments

Example A method to calculate a square root public double squareRoot (double x) // PRE: x >= 0 // POST: squareRoot returns an approximation // to the square root of x {... } // squareRoot

Another Example Some methods have no preconditions A random number method: public double random () // PRE: None // POST: random returns a pseudo-random // number r in the range 0 <= r < 1 {... } // random

Checking Preconditions Can throw exceptions public double squareRoot (double x) // PRE: x >= 0 // POST:... { if (x < 0) throw new IllegalArgumentException("x<0");...

Assertions Similar to preconditions and postconditions Introduce the idea of checkpoints in the program –Describe the state of the program at certain points

Example A program to play a card game class PlayingCard {... } PlayingCard deck[] = new PlayingCard[52];... shuffleCards(deck); // ASSERT: deck contains 52 cards in // random order

Assertions Some programming languages provide mechanisms to check simple assertions Java does (since JDK 1.4) –assert statement –Two forms: assert boolean_expression; assert boolean_expression : expression;

Using Assertions in Java... skipSpaces(); ch = (char)System.in.read(); assert ch != ' '; java.lang.AssertionError at MyApp.main(MyApp.java:12) Exception in thread "main"

Assertions in Java Assertion checking is disabled by default –Allows checking to be done during development –When program is shipped to customer, checking is disabled for efficiency Full details in Sun documentation

Using Assertions Some conditions are too difficult to express as simple boolean expressions –Use assertion comments shuffleCards(deck); // ASSERT: deck contains 52 cards in // random order

Assertions and Preconditions and Postconditions Related concepts: –Assertions: general checkpoints –Pre- and postconditions: specific checkpoints (at start and end of methods)

Assertions and Preconditions Assertions can be used to check pre- conditions –better to use exceptions public double squareRoot (double x) // PRE: x >= 0 // POST:... { assert x >= 0;...

Benefits of Using Assertions, Preconditions and Postconditions Forces the programmer to consider the state of the program at key points Helps document the program –Assumptions and “guarantees” May provide run-time checking