5. Abstraction
Society for Industrial and Applied Mathematics eBooks · 2010
5.1 Reshaping Rectangles A Square and a Root 5.2 Oval Odometer Ellipse Perimeter 5.3 The Betsy Ross Problem Design Parameters There are a number of reasons why the built-in sin function is so handy. To begin with, it enables us to compute sines without having a clue about the method used. The design of an accurate and efficient sine function is somewhat involved, but by taking the “black box” approach, we are able to be effective sin users while being blissfully unaware of how the built-in function works. All we need to know is that sin expects a real input value and that it returns the sine of that value interpreted in radians. Another advantage of sin can be measured in keystrokes and program readability. Instead of disrupting the “real business” of a program with lengthy compute-the-sine fragments, we merely invoke s in as required. The resulting program is shorter and harmonizes better with our mathematical thinking. Being able to write effective functions is central to the problem-solving process. It supports the top-down methodology, enabling us to hide lower-level details while we address higher-level design issues. We start by developing a function for computing square roots that is based on a rectangle averaging process. The fact that sqrt is a built-in function gives us a standard against which we can measure the quality of our implementation. Next, we consider the problem of computing the perimeter of an ellipse. Two reasonable function-writing strategies emerge, providing an opportunity to discuss the tension that sometimes exists between clarity and efficiency. The challenge of designing the 13-star Colonial flag dramatizes the power of the top-down methodology and illustrates how function writing can crystallize our thinking during the design process. It forces us to identify the factors that characterize the design and to spot underlying hierarchies.