This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 1 ee312 Spring 2008 Lecture 8 1 Announcements Lecture 8 • Functions from Chapter 9 • Review Exercises from the text • Topics for today – functions ee312 Spring 2008 Lecture 8 2 Review for Exam 1 Review the following chapter questions for Exam 1: 1. Chapter 2  7, 11 2. Chapter 3  3, 7 3. Chapter 4  5, 7 4. Chapter 5  1, 9 5. Chapter 6  7, 15 6. Chapter 7  5, 13 7. Chapter 8  1, 3, 5, 9 8. Chapter 9  1, 7, 9 9. Chapter 10  1, 3, 5 2 ee312 Spring 2008 Lecture 8 3 Functions in a Nutshell • A named collection of statements • Somewhat like mathematical functions: y = f(x) – Arguments are not required – Does not need to return a value (similar to a procedure in other languages) • Functions are like “miniprograms” called by name – declarations – body • Previously written standard functions are in the library for your use • You can write your own functions too ee312 Spring 2008 Lecture 8 4 C Standard Library Functions • See appendix D • In various header files (.h) – stdlib – stdio – math – time – ctype – string – assert – a few others #include <math.h> . . . float x; . . . If (ceil (x) ! = ceil (x+.5)) x = (int) (x + .5); else x = (int) x; What does this do? 3 ee312 Spring 2008 Lecture 8 5 Top Down Functional Programming main sub1 sub2 sub3 sub4 subsub1 subsub2 subsub3 subsub4 sss1 sss4 calls calls calls calls ee312 Spring 2008 Lecture 8 6 How does this work? • Chunking the problem – Let’s us divide a big problem into small problems – No one part is highly complex – However a balance must be achieved between too many and too few functions • Too few complexity of the size of each • Too many complexity of number and interconnects • Many ways to divide a problem – this is one of the fundamentals of the craft of design • Functions are key to – Reducing complexity – Increasing clarity 4 ee312 Spring 2008 Lecture 8 7 Complexity • Complexity – of detail, of logic, of interconnections • When is something too complex? – When it is difficult for your audience to comprehend – When it’s too difficult for you to solve • What increases complexity ? – Too much or too little context functions – Unfamiliarity idioms / design patterns – Complicated logic explanatory comments – Excessive coupling and side effects functional encapsulation • Elegance  a quality of ingenious simplicity and clarity in the solution of a problem Function Mechanics Functions allow us to modularize and encapsulate the processes of our programs. This is key to handling complexity. 5 Defining a Function (1) • A function operates on data passed through the parameter list, and either returns a value computed or causes some action to occur • It is called by name from some other function....
View
Full
Document
This note was uploaded on 04/15/2008 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas.
 Spring '08
 Shafer

Click to edit the document details