Download presentation
Presentation is loading. Please wait.
1
Week 7 - Wednesday CS 113
2
Last time What did we talk about last time? Euler paths and cycles
Minimum spanning trees Shortest paths
3
Questions?
4
Project 2
5
Software Engineering
6
Software development Often goes through phases similar to the following: Understand the problem Plan a solution to the problem Implement the solution in a programming language Test the solution Maintain the solution and do bug fixes Factor of 10 rule!
7
A Tragedy of Software Engineering
8
Therac-25 Radiation treatment machine for cancer patients Caused:
Used June Jan 1987 Caused: At least six serious overdoses Several deaths Many permanently maimed Radiation treatment is normally around 200 rads 500 rads can be lethal Therac-25 delivered dosages of over 20,000 rads because of a software error 11 units in US and Canada had treated hundreds of patients over the course of several years Earlier Therac-20 and Therac-6 models had been in service, without incident, for many years
9
Problems not caught for two years
The doctors involved had never seen radiation overdoses of this magnitude Manufacturer was both tragically ill-prepared and probably willfully dishonest Government regulatory agencies slow and out of the loop The fundamental problem stemmed from the machine having two different modes Low power which projected a beam directly into the patient High power which projected a beam onto a beam spreader plate which changed the kind of radiation and shaped it
10
Race condition //thread 1 value = 3 //thread 2 value = 7
One of the problems behind the Therac-25 disaster was a race condition A race condition is when the output of a program is dependent on the scheduling of certain threads Threads are parts of the same program that can run independently at the same time Threads can share data We won't talk about how to do multi-threaded programming in Python But try to imagine which number will be stored into value if the following two threads are both running //thread 1 value = 3 //thread 2 value = 7
11
Race conditions in Therac-25
The problem emerged with the Therac-25 only after operators became skilled at typing commands It took time for the keyboard loop to read keystrokes and time for the magnets to adjust the radiation beam Operators changed settings faster than the second magnet alignment loop The device could activate in high power mode with no beam spreader plate
12
Overflow error Even with the race condition, a safety check should have prevented the accident There was a loop which checked a counter The value 0 meant okay The counter was only 1 byte Every 256 cycles, it would roll around to 0 When that happened, the operator could proceed without a safety check
13
Subsequent investigation
The Therac-25 software was programmed by a single programmer, who had long since left the company No one at the company could say anything about his education or qualifications FDA investigators said Program was poorly documented No specification document No formal test plan
14
In the programmer's defense
Therac-6 and 20 had no computer control, only add-on computer monitoring Legacy software from the earlier devices had been adapted Hardware safety devices had been removed, probably to save cost Programmer had probably been under time pressure, and had been learning as he went along Programmer probably had no idea his code would go into a device in which software bugs could kill people
15
Who is to blame? Techniques for synchronization and data sharing already existed which would have prevented several of these deaths What if the programmer had a formal education that involved these techniques or had bothered to study the literature? What if management had understood software engineering and quality assurance principles? What if hospitals or regulatory agencies had strong safety requirements for safety-critical software?
16
Quotes A significant amount of software for life-critical systems comes from small firms, especially in the medical device industry; firms that fit the profile of those resistant to or uninformed of the principles of either system safety or software engineering. Frank Houston FDA investigator into the Therac-25
17
What is different today?
Does Elizabethtown require a course on testing methods, software engineering principles, or formal specification writing? Do other major universities? Does the government understand how to properly regulate safety-critical systems? Do consumers have stringent requirements for the quality of the software they buy?
18
Testing
19
Unit testing Unit tests are tests for a single piece of code in isolation from the rest of your program A unit test could test A single method or function A whole class None of the programs we've written in CS113 is large enough to go beyond unit testing
20
Test case selection Positive test cases Boundary condition test cases
Cases that should work, and we can easily check the answer Boundary condition test cases Special cases, like deleting the first or last item in a list Sometimes called "corner cases" Negative test cases Cases that we know should fail
21
Regression testing When you find a bug, keep the test case that demonstrated the bug Include it as part of your test suite Always run all your tests when you make a change to your code Sometimes a "fix" can break something that was working Especially if you didn't fix the bug correctly the first time
22
Black box testing One philosophy of testing is making black box tests
A black box test takes some input A and knows that the output is supposed to be B It assumes nothing about the internals of the program To write black box tests, you come up with a set of input you think covers lots of cases and you run it and see if it works In the real world, black box testing can easily be done by a team that did not work on the original development
23
White box testing White box testing is the opposite of black box testing Sometimes white box testing is called "clear box testing" In white box testing, you can use your knowledge of how the code works to generate tests Are there lots of if statements? Write tests that go through all possible branches There are white box testing tools that can help you generate tests to exercise all branches Which is better, white box or black box testing?
24
Finally… Understand each error before you fix it
If you don't understand a bug, you might be able to "fix" it so that one test case succeeds Nevertheless, the real problem might be unsolved Nothing is harder than truly fixing problems This is a very important skill for computer scientists But we're just happy if you know what a bug is in CS113
25
Quotes Testing can only show the presence of bugs, not their absence.
Edsger Dijkstra Turing Award Winner Designer of shortest path and MST algorithms Worked on Dining Philosophers Problem
26
Programming Languages
27
Unambiguous languages
English is no good "The peasants are revolting!" We need precise, unambiguous languages to write programs in Syntax is the rules for constructing meaningful statements Like the grammar for the language E.g., English sentences are made up of a subject and a predicate E.g., Python has to be indented under an if statement Semantics are the meaning of the statements
28
Type systems A feature of most modern programming languages is a type system In a type system, each piece of data has a particular type (string, integer, floating point value, Wombat) In a static type system, the type of a variable is known before the program runs and never changes In a dynamic type system, the type of the variable is only known at run-time and might change Type systems help define what code is legal (and what legal code does)
29
Python vs. Java Interpreted (code is not compiled before running)
Dynamic typing Whitespace has meaning Doesn't take much code to do stuff Relatively slow (in terms of execution time) Object oriented (somewhat) Compiled Static typing Whitespace is ignored Takes a lot of code to do stuff Relatively fast (in terms of execution time) Object oriented x = 4 int x = 4;
30
Object oriented programming
Object orientated programming (OOP) is a way of organizing code into objects containing Data Methods to manipulate the data OOP is used To protect data inside of objects from being changed in unexpected ways To safely reuse code It's hard to see why OOP is useful until you've programmed a big project The shapes in Visual Python are examples of objects ball = sphere(color=color.red) ball.pos.x = 10 #data inside the ball
31
Early developments The very earliest programming languages used punch cards for player pianos and looms A mechanical computer, the Analytical Engine, would have used punch cards, but it was never completed Work was done on the Engine during the mid to late 19th century Ada Lovelace described an algorithm for it and is considered by some to be the first programmer
32
The electronic era Early electronic computers were built in the 1940s and 1950s They were programmed directly in the machine language of 1s and 0s that they would understand Machine language was succeeded by assembly language Had human readable commands like load, store, and add But the commands were specific to machines and very low level
33
Modern programming languages
The third generation of languages is a set of general-purpose, high-level languages still used today Pioneered in the 1960s and 1970s Although they are written with a computer now, programs in these languages were written on punch cards before PCs existed Examples: C FORTRAN LISP
34
Fourth and fifth generations
Java and Python are actually newer additions to the third generation of general purpose languages Fourth generation languages are for specific purposes SQL for talking to databases Unix shell for interacting with a Unix file system Fifth generation languages are given constraints on a problem and use artificial intelligence to solve it Prolog is the best known example
35
Popular programming languages
Description Typing C/C++ Fast and powerful systems language, prone to nasty bugs Static Java Platform independent OO language, uses virtual machine Objective-C Apple language for writing Mac, iPhone, and iPad apps C# Microsoft language for applications and the web, like Java Python Interpreted language with unusual syntax, easy to read Dynamic Perl Scripting language, good at processing text Ruby Interpreted language, popular for making websites PHP Interpreted, C-like language that runs on web servers JavaScript Interpreted language that runs on web browsers Visual Basic Microsoft language, good at making GUIs SQL Language for talking to databases
36
Quiz
37
Upcoming
38
Next time… Finish programming languages and compilers Functions Lab 7
39
Reminders Finish Project 2 Keep reading Python Chapter 7
Due this Friday before midnight! Keep reading Python Chapter 7 Think about what you want to do for your Final Project
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.