CS 111 Spring 2010: Lecture 3 Scribe Notes
Scribed by: Kyungtae Kwon, Spencer Sutterlin, Nim Nahum, James Galvan
Problems with last week's stand-alone application:
How to cope with complexity:
Modularity's effect on finding bugs:
As a general rule, the more modules we have, the less debug time is required. We can thus use this model as a good estimate of the required debug time for bugs that reside in only one module, as most bugs occur in single modules. However, we do take into account that some bugs can span across multiple modules, and more time will be needed to examine all the different modules relating to the bug, in turn increasing debug time.N lines of code, M modules
Bugs = N, time to find/fix bug = N
Debug time (M = 0) = N^2
Debug time (M = M) = (N/M * N/M) * M = N^2/M
(this assumes bug is isolatable and easily found in which module)
- Performance - modularization usually costs performance
- Robustness - tolerance of faults/failures - well designed modules should work well in harsh environments
- Simplicity - easy to learn/use, small manual
- Portability, neutrality, flexibility, lack of assumptions
- let components be used in many ways
- let "file" be anything - bytes on disk, packets in network
Redefining the API
off_t lseek (int fd, off_t b, int flag)-> Because the ability to read a sector has been taken away, and all that remains to seek to a spot is the offset, there is also a function lseek to move the pointer to the desired spot
x86 Review in 10 minutes
1 int fact (int n) { 2 if (n == 0) 3 return 1; 4 return n*fact(n-1); 5 }
fact: pushl %ebp //save fp movl $1, %eax //ax=1 movl %esp, %ebp //fp=sp subl $8, %esp //sp-=8 movl %ebx, -4(%ebp) //save bx movl 8(%ebp), %ebx //bx=n testl %ebx, %ebx //is n==0? jne .L5 //if nonzero go to L5 .L1 movl -4(%ebp), %ebx //restore bx movl %ebp, %esp //restore sp popl %ebp //restore fp ret //pop stack, go there .L5 leal -1(%ebx), %eax //ax=bx-1 movl %eax, (%esp) //*sp=ax call fact //pushes return address on stack/jumps to fact imull %ebx, %eax //result*=n jmp .L1
             
Review: How to enforce modularity - function calls