
B16: Software Engineering 2 Four Parts Structured Programming Design patterns Algorithms, data structures, complexity, Tested program structures to solve typical correctness problems B16 Software Engineering Structured programming languages: C Structured Programming Object Oriented Programming Operating Systems Lecture 1: Software engineering Object-oriented programming Hardware abstraction and virtualisation Dr Andrea Vedaldi Object-oriented languages: C++ Programming the hardware 4 lectures, Hilary Term For lecture notes, tutorial sheets, and updates see http://www.robots.ox.ac.uk/~vedaldi/teach.html B16 Part 1: Structured Programming 3 Texts 4 Software engineering principles Algorithms Design, modularity, abstraction, encapsulation, Proving algorithm correctness by mathematical etc. induction Structured programming languages Time and space complexity Interpreted (MATLAB) vs compiled (C) languages Recursion Control flow Sequencing, alternation, iteration Functions and libraries Data Data types: primitive, aggregate, and compound The C programming language, 2nd edition Introduction to algorithms Local and global variables, parameters Kernaghan & Ritchie Cormen, Leiserson, Rivest, Stein The heap and the stack Lecture 1 outline 5 Lecture 1 outline 6 The challenge of building software The challenge of building software Why we care about software Why we care about software The size and complexity of code The size and complexity of code Software engineering Software engineering The aims and scope of software engineering The aims and scope of software engineering Abstraction and modularity Abstraction and modularity Design, validation & verification Design, validation & verification Structured programming Structured programming Structuring programs by using abstractions in a programming language Structuring programs by using abstractions in a programming language Types of languages: imperative vs declarative Types of languages: imperative vs declarative Fundamental abstractions Fundamental abstractions Software is ubiquitous 7 Software in engineering: Design & Control 8 From nuclear reactors ... Business / productivity Communication Entertainment ... to cars. The “size” of software 9 10 SLOC: number of source lines of code /* Cy=CyMin + iY*PixelHeight; c program: if (fabs(Cy)< PixelHeight/2) Cy=0.0; /* Main antenna */ -------------------------------- for(iX=0;iX<iXmax;iX++) 1. draws Mandelbrot set for Fc(z)=z*z +c { using Mandelbrot algorithm ( boolean escape time ) Cx=CxMin + iX*PixelWidth; ------------------------------- /* initial value of orbit = critical point Z= 0 */ 2. technique of creating ppm file is based on the code of Claudio Rocchini Zx=0.0; http://en.wikipedia.org/wiki/Image:Color_complex_plot.jpg Zy=0.0; create 24 bit color graphic file , portable pixmap file = PPM Zx2=Zx*Zx; see http://en.wikipedia.org/wiki/Portable_pixmap Zy2=Zy*Zy; to see the file use external application ( graphic viewer) /* */ */ for (Iteration=0;Iteration<IterationMax && ((Zx2+Zy2)<ER2);Iteration++) #include <stdio.h> { #include <math.h> Zy=2*Zx*Zy + Cy; int main() Zx=Zx2-Zy2 +Cx; { Zx2=Zx*Zx; /* screen ( integer) coordinate */ Zy2=Zy*Zy; int iX,iY; }; const int iXmax = 800; /* compute pixel color (24 bit = 3 bytes) */ const int iYmax = 800; if (Iteration==IterationMax) /* world ( double) coordinate = parameter plane*/ { /* interior of Mandelbrot set = black */ double Cx,Cy; color[0]=0; const double CxMin=-2.5; color[1]=0; const double CxMax=1.5; color[2]=0; const double CyMin=-2.0; } const double CyMax=2.0; else /* */ { /* exterior of Mandelbrot set = white */ double PixelWidth=(CxMax-CxMin)/iXmax; color[0]=255; /* Red*/ double PixelHeight=(CyMax-CyMin)/iYmax; color[1]=255; /* Green */ /* color component ( R or G or B) is coded from 0 to 255 */ color[2]=255;/* Blue */ /* it is 24 bit color RGB file */ }; const int MaxColorComponentValue=255; /*write color to the file*/ FILE * fp; fwrite(color,1,3,fp); char *filename="new1.ppm"; } char *comment="# ";/* comment should start with # */ } static unsigned char color[3]; fclose(fp); /* Z=Zx+Zy*i ; Z0 = 0 */ return 0; double Zx, Zy; } output: double Zx2, Zy2; /* Zx2=Zx*Zx; Zy2=Zy*Zy */ /* */ int Iteration; const int IterationMax=200; /* bail-out value , radius of circle ; */ const double EscapeRadius=2; double ER2=EscapeRadius*EscapeRadius; /*create new file,give it a name and open it in binary mode */ fp= fopen(filename,"wb"); /* b - binary mode */ About 90 SLOCs of C code /*write ASCII header to the file*/ fprintf(fp,"P6\n %s\n %d\n %d\n %d\n",comment,iXmax,iYmax,MaxColorComponentValue); /* compute and write image data bytes to the file*/ for(iY=0;iY<iYmax;iY++) { Source: https://www.rosettacode.org/wiki/Mandelbrot_set#C 11 12 13 14 What 130K lines of code look like 15 Lecture 1 outline 16 Apollo-11, 1969 The challenge of building software Why we care about software The size and complexity of code Software engineering The aims and scope of software engineering Abstraction and modularity Design, validation & verification Structured programming Structuring programs by using abstractions in a programming language Margaret Hamilton, Types of languages: imperative vs declarative director of software engineering Fundamental abstractions Code available here: https://github.com/chrislgarry/Apollo-11/ Software engineering 17 Abstraction and modularity 18 Aims Scope The complexity of software is reduced via: Modularity Software engineering seeks principles and Software engineering is concerned with all aspects of Decomposing the system into smaller components methodologies to make programs that are: software production. It includes: Abstraction Usable Theory Each component's behaviour has a simple description, independent of the Meet their requirements, including being Computability, algorithms, correctness, other components and of the internal implementation acceptable by the users complexity, formal languages Dependable Tools and best practices Benefits: Reliable, secure, safe Specific programming languages, programming Understandability environments, developer tools to build, debug, Individual components are simple and easy to understand Maintainable and analyse programs Can be updated with minimal effort Reuse Management The same component can be used in many applications (e.g. transistors) Efficient Processes of software creation & maintenance Run as fast as possible with limited resources Isolating changes The implementation of a component (e.g. transistor materials) can be changed as long as the behaviour (e.g. electrical properties) does not Abstraction and modularity 19 Abstraction and modularity 20 Examples A hierarchy of increasingly-powerful abstractions transistor transistors flip-flops registers CPU A Tristate buffers (4 in parallel) CPU MAR 4 Address Bus Bus PC SP Memory INCpc/LOADpc IC β IB, CLKmem = C 4 IR IR(opcode) IR(address) MBR IE = IC + IB, Data Bus B AC VEB 60 mV 4 = CU Status ALU s SETalu Select CLK Control Lines to Registers, ALU, Memory, etc Outside the CPU operational amplifier computer virtual machine (OS) application / interpreter I+ V+ Iout - + Vout V- I- Vgnd V+ = V-,I+ = 0 A, I- = 0 A [Some images from Micro-controller, Murray] Producing software 21 Design & implementation 22 A software process is a set of related activities that leads to the production of a software product [Sommerville]. Design Implementation Key activities of a software process: Formal Top-down collect the requirements implement first the most abstract module break down the problem in sub-problems use placeholders (mock-ups) for sub-modules Design & map them to software sub-modules Bottom-up Specification implementation start from elementary module Informal (aka "extreme programming") then build more complex ones using them quickly implement & iterate over a prototype incorporate user feedback at each iteration Verification & Evolution validation Verification & validation 23 Lecture 1 outline 24 Verification Testing strategies The challenge of building software Why we care about software Squash the bugs: Top-down: test that the system behaves correctly overall. If not, dig into your code to find the problem. The size and complexity of code Black-box: test what the code does White-box: inspect the code (possibly automatically) Bottom-up: create unit tests to test individual sub- Software engineering modules, starting from the smallest ones. This is The aims and scope of software engineering Validation extremely useful! Abstraction and modularity Test the code in the real world and get feedback Test coverage Design, validation & verification Exhaustive testing is impossible More often than not, the requirements are wrong (i.e. you don't know exactly how the software should behave Pick representative examples of “normal” inputs as Structured programming well as “corner cases” to be useful to the user). Structuring programs by using abstractions in a programming language Example: Test a function to compute the tangent Types of languages: imperative vs declarative normal input: tan(1.1) corner cases: tan(-pi/2), tan(0), Fundamental abstractions tan(pi/2) Imperative languages 25 Imperative languages 26 The most common programming languages are imperative. Abstractions can have a massive impact on the ease of use, understandability, maintainability, power, and efficiency of programming languages. An imperative program is a list of instructions to be executed in a specified order. Look at these three versions of the same program: Different imperative languages are characterised by different abstractions. Machine Code (Intel
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages36 Page
-
File Size-