Department of Computer Science, York University Slides based on Object Oriented Software Construction 16/10/2015 4:08 PM 0 COSC3311 – Software Design Gotos,

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Building Bug-Free O-O Software: An Introduction to Design By Contract A presentation about Design By Contract and the Eiffel software development tool.
Control Structures Ranga Rodrigo. Control Structures in Brief C++ or JavaEiffel if-elseif-elseif-else-end caseinspect for, while, do-whilefrom-until-loop-end.
Unit 6 Assignment 2 Chris Boardley.
Chapter 2 - Problem Solving
Chapter 2 - Problem Solving
Lecturer: Fintan Costello Welcome to Hdip 001 Introduction to Programming.
IMSE Week 18 White Box or Structural Testing Reading:Sommerville (4th edition) ch 22 orPressman (4th edition) ch 16.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
16/27/ :53 PM6/27/ :53 PM6/27/ :53 PMLogic Control Structures Arithmetic Expressions Used to do arithmetic. Operations consist of +,
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
Describing Syntax and Semantics
PRE-PROGRAMMING PHASE
Software Development Unit 6.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
TEACHING PROGRAMMING BY ITERATIVE DEEPENING Dr. Mark Lee | School of Computer Science, University of Birmingham
Language Evaluation Criteria
PRAGMATIC PARANOIA Steven Hadfield & Anthony Rice.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Towers of Hanoi. Introduction This problem is discussed in many maths texts, And in computer science an AI as an illustration of recursion and problem.
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
Team Skill 6: Building the Right System From Use Cases to Implementation (25)
1 Welcome to CS 362 Applied Software Engineering What happens after (and during) design? Testing, debugging, maintaining programs Lessons for software.
Gary MarsdenSlide 1University of Cape Town Principles of programming language design Gary Marsden Semester 2 – 2001.
The Logical Structure of Algorithms. Algorithms Steps necessary to complete a task or solve a problem. Example: Recipe for baking a cake –Will contain.
Department of Computer Science A Static Program Analyzer to increase software reuse Ramakrishnan Venkitaraman and Gopal Gupta.
Facts and Fallacies of Software Engineering (Rob Glass) CSE301 University of Sunderland Discussed by Harry R. Erwin, PhD.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Just as there are many human languages, there are many computer programming languages that can be used to develop software. Some are named after people,
2_Testing Testing techniques. Testing Crucial stage in the software development process. Significant portion of your time on testing for each programming.
SWE 619 © Paul Ammann Procedural Abstraction and Design by Contract Paul Ammann Information & Software Engineering SWE 619 Software Construction cs.gmu.edu/~pammann/
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
CPS120 Introduction to Computer Programming The Programming Process.
Software Engineering Chapter 3 CPSC Pascal Brent M. Dingle Texas A&M University.
Static Program Analyses of DSP Software Systems Ramakrishnan Venkitaraman and Gopal Gupta.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
Reasoning about programs March CSE 403, Winter 2011, Brun.
1 Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Software Development Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance.
Opening Slide You’re About to Discover the One Secret “__________” That Makes it Super- Easy to ____________________ That Allows You to __________________and.
Prof Rickus’ Rules of Writing “The Elements of Style” 4th Edition Strunk and White An Excellent Writing Reference:
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Department of Computer Science, York University Object Oriented Software Construction 22/01/ :58 AM 1 COSC3311 – Software Design Loop invariant/variant.
Error Handling Tonga Institute of Higher Education.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
The Last Lecture CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
Software Development Languages and Environments. Computer Languages Just as there are many human languages, there are many computer programming languages.
Testing and Debugging UCT Department of Computer Science Computer Science 1015F Hussein Suleman March 2009.
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
Testing and Debugging.
Reasoning About Code.
Repeating code We could repeat code we need more than once: i = 1 print (i) i += 1 print (i) #… stop when i == 9 But each line means an extra line we might.
Unit# 9: Computer Program Development
Programming Languages 2nd edition Tucker and Noonan
Structured Programming Taken from notes by Dr. Neil Moore
Unit 6 Assignment 2 Chris Boardley.
CISC101 Reminders All assignments are now posted.
ICT Gaming Lesson 2.
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Software Development Techniques
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

Department of Computer Science, York University Slides based on Object Oriented Software Construction 16/10/2015 4:08 PM 0 COSC3311 – Software Design Gotos, Breaks and Structured Programming

Department of Computer Science, York University Slides based on Object Oriented Software Construction 16/10/2015 4:08 PM 1 What’s wrong with `break’ | | Subject: AT& T Bug | | Date: Fri Jan 19 12: 18: | | | This is the bug that caused the AT& T breakdown the other day: | | In the switching software (written in C), | | there was a long do... while construct, | | which contained a switch statement, | | which contained an if clause, | | which contained a break, | | which was intended for the if clause, | | but instead broke from the switch.  A missing “break” statement brought down the entire long- distance telephone network in the North Eastern US, resulting in millions of dollars of damage!

Department of Computer Science, York University Slides based on Object Oriented Software Construction 16/10/2015 4:08 PM 2 Statement from Bertrand Meyer  (Feb 2004)  “I assume the question about "powerful weapons" refers to the break / continue control structures of C and Java.  BM’s response follows on the next few pages:

Department of Computer Science, York University Slides based on Object Oriented Software Construction 16/10/2015 4:08 PM 3 Structured vs. Spaghetti programs  Thirty five years ago, Edsger Dijkstra, followed by others, made a powerful case against using control structures other than the one-entry, one-exit blocks that came to be known as "the control structures of structured programming". They are, with a few complements, the control structures of Eiffel: sequence (implicit most of the time since you may omit the semicolon), if-then-else, inspect, loop, routine.  They are all one-entry, one-exit, meaning you can read the code sequentially and don't have to turn yourself into a computer and apply operational reasoning of the style "if when executing this instruction I'm coming from here it will satisfy this property, but if I am coming from there it will satisfy that other property, so in both cases... it will be true that... maybe... wait a minute... etc.

Department of Computer Science, York University Slides based on Object Oriented Software Construction 16/10/2015 4:08 PM 4 Linear inspection of loops  Some people view "break" and "continue" as milder forms of the goto that do not raise the same problems.  But in fact these forms are just as bad.  Note in particular that what makes it possible really to understand a loop is the notion of loop invariant: a property that is ensured by the initialization, and maintained by every iteration. The invariant is like an approximation of the loop's goal (e.g. if we want to compute the maximum of a structure -- the final goal -- the invariant states that Result is the maximum *of the elements seen so far*). Combined with the loop exit condition (in the example, "we've now seen all elements") it allows the program reader to check, through a simple inspection of the loop text, that the loop is doing its job. The loop variant plays a complementary role by telling us which decreasing quantity guarantees that the loop will terminate.

Department of Computer Science, York University Slides based on Object Oriented Software Construction 16/10/2015 4:08 PM 5 Reason statically not dynamically  The key point is to be able to reason about a program statically, i.e. by associating properties with its text as given, rather than operationally, i.e. by trying to mimic its execution within your head.  Computers are there to execute programs; humans can't really do it effectively for any non- trivial examples. The one-entry, one-exit structure helps us do something at which we are much better: static reasoning based on the simple rules of logic.

Department of Computer Science, York University Slides based on Object Oriented Software Construction 16/10/2015 4:08 PM 6 Dijkstra  In practice it is not surprising that if you have been used to goto-prone languages you will find it a bit hard at first to stick to the one-entry, one- exit discipline. I am sure that if you try earnestly to overcome what initially seems like a hurdle you will very quickly find that your programming style improves, that the control structure of your program becomes simpler, and that your programs become more readable and maintainable.  You can find Dijkstra's original paper at

Department of Computer Science, York University Slides based on Object Oriented Software Construction 16/10/2015 4:08 PM 7 C and Java  It's too bad the designers of C and Java did not heed its advice. I assume they had their reasons -- probably they were afraid to lose programmers who weren't ready to learn about structured programming.  In the case of Eiffel, the goal of helping people write high-quality programs -- easy to debug, easy to extend, easy to reuse -- was deemed more important.

Department of Computer Science, York University Slides based on Object Oriented Software Construction 16/10/2015 4:08 PM 8 Exceptions and rescue clauses  To make the discussion complete it's necessary to mention that branching out of the innards of a control structure *is* necessary in one special case: when you realize, deep into the computation, that due to some unforeseen condition you are unable to carry out the algorithm as expected.  This is why there are exceptions. But in the Eiffel approach exceptions don't function like goto instructions: they trigger a different algorithm, a "rescue" clause, which tries to patch things up if at all possible. The rescue clause itself is a one-entry, one-exit structure. (C++/Java exceptions are also not gotos, but they are based on a different view.) I hope that this clarifies the reasoning behind Eiffel's control structures, and that you'll soon stop regretting the absent "weapons" -- weapons of the kind that too often turn back to hit those who fired them. With best regards, -- Bertrand Meyer

Department of Computer Science, York University Slides based on Object Oriented Software Construction 16/10/2015 4:08 PM 9 Error Removal & Code inspections  Facts and Fallacies of SE, Robert Glass, 2003  Fact 31: Error removal is the most time consuming phase of the lifecycle  Fact 37: Rigorous code inspections are the closest we have to a silver bullet – inspections can catch and remove 60-90% of errors.  Despite this, code inspections are rarely used (vendors don’t make money from it; gruelling hard mind-intensive work)  Is it easier to write or read programs?  Current metric: 100 LOC/hour plus breaks

Department of Computer Science, York University Slides based on Object Oriented Software Construction 16/10/2015 4:08 PM 10 Error Removal techniques  Contracts  Tests (automated ETester tests are very useful)  Code inspections  Both contracts and tests are also forms of specifications.  To do a good code inspection, you need a good specification, which you need to check the implementation.  Structured programming significantly enhances code comprehension and therefore code inspections.