正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology our particular version of good enough"needed to use the absolute value procedure, though other versions might ot Slide 7.1.7 Once we had separated out these notions of different computations: average and good-enough, we considered the An example of code modules overall flow of information through the modules. Note by the Finding the sqrt of x Make a guess, G way that we can consider each of theses processes as a black If it is good enough, stop ox abstraction, meaning that we can focus on using these Otherwise, get a new guess by averaging G and procedures without having to have already designed the specific implementation of eacl Now what about the flow between these modules? In our case Good-enur? average G we began with a guess, and tested to see if it was good enough If it was, we could then stop, and just return the value of the 600SC Slide 7.1.8 An example of code modules If it was not, then we needed to average the current guess and Finding the sqrt ofX the ratio of our target number to the guess Make a guess, G -If it is good enough, stop Otherwise, get a new guess by averaging G and G Good-enuf? Average 82003 Slide 7.1.g And then we need to repeat the entire process, with this new alue as our new guess An example of code modules The point of laying out these modules, or black boxes, is that Finding the sqrt of X Make a guess, G we can use them to decide how to divide up the code, and how If it is good enough, stop to isolate details of a procedure from its use. As we saw when Otherwise, get a new guess by averaging G and we implemented our sgrt procedure, we can change details of a procedure, such as average, without having to Good-enur? change any of the procedures that use that particular Abs omponent. As well, the flow of information between the modules helps guide us in the creation of the overall set of Thus, when faced with any new computational problem, we want to try to engage in the same exercise: block out hunks of the computation that can be easily isolated; identify the inputs and outputs from each chunk; and lay out the overall flow of information through the system. Then we can turn to implementing each of the units separately and testing the entire system while isolating the effects of each unit6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. our particular version of “good enough” needed to use the absolute value procedure, though other versions might not. Slide 7.1.7 Once we had separated out these notions of different computations: average and good-enough, we considered the overall flow of information through the modules. Note by the way that we can consider each of theses processes as a black box abstraction, meaning that we can focus on using these procedures without having to have already designed the specific implementation of each. Now what about the flow between these modules? In our case, we began with a guess, and tested to see if it was good enough. If it was, we could then stop, and just return the value of the guess. Slide 7.1.8 If it was not, then we needed to average the current guess and the ratio of our target number to the guess. Slide 7.1.9 And then we need to repeat the entire process, with this new value as our new guess. The point of laying out these modules, or black boxes, is that we can use them to decide how to divide up the code, and how to isolate details of a procedure from its use. As we saw when we implemented our sqrt procedure, we can change details of a procedure, such as average, without having to change any of the procedures that use that particular component. As well, the flow of information between the modules helps guide us in the creation of the overall set of procedures. Thus, when faced with any new computational problem, we want to try to engage in the same exercise: block out chunks of the computation that can be easily isolated; identify the inputs and outputs from each chunk; and lay out the overall flow of information through the system. Then we can turn to implementing each of the units separately, and testing the entire system while isolating the effects of each unit
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有