正在加载图片...
Introduction 7 ·Work incrementally .Be open to negative feedback .Program with a friend. Write concise programs .Write clear programs. .Write correct programs Consider each of these principles in turn. 1.5 Deciding If a Program Is Needed and Whether You Should Write It The first principle is less obvious than you might suppose.Consider the problem discussed above(finding the largest of a set of values).The numbers corresponding to the bars in Figure 1.3.2 are as follows: 73339268181540 Do you need a computer program to find the largest of these values?Obviously not.You know that the largest of these numbers is 39 and that this largest number occupies the third slot in the serie If you only had to find the lagest value in this rray. be fooli h to write a program for this tas pt as an exerci On the oth hand,if you were quite sure you d often need to find the largest number in each of a large numb 金 es,w sen e.A progran uld be too taxing to perform by nt If .also m for a task if somec Our answer to this question is analogous to the answer a math teacher might give to a e this theorem if it's been oved before?"Prac tice makes perfect"the teacher m ply.He or she may go on:"Even if true perfection is beyond your reach,practice will increase the chance of your proving something new yourself. Our view of programming is the same.You might be able to locate programs that already do things you need to,and it may make sense for you to use those programs,especially for problems that seem very complicated or that are beyond your technical ability.But the more practice you get programming.the more likely it will be that you will be able to gen- erate programs that either solve new problems or solve old problems in new ways.Don't be discouraged if it takes an hour or more to get your first"real"program up and running.even if you might have done the same computation by hand in a minute or less.As you developIntroduction 7 Ć Work incrementally. Ć Be open to negative feedback. Ć Program with a friend. Ć Write concise programs. Ć Write clear programs. Ć Write correct programs. Consider each of these principles in turn. 1.5 Deciding If a Program Is Needed and Whether You Should Write It The first principle is less obvious than you might suppose. Consider the problem discussed above (finding the largest of a set of values). The numbers corresponding to the bars in Figure 1.3.2 are as follows: 7 33 39 26 8 18 15 4 0 Do you need a computer program to find the largest of these values? Obviously not. You know that the largest of these numbers is 39 and that this largest number occupies the third slot in the series. If you only had to find the largest value in this particular array, you would be foolish to write a program for this task, except as an exercise. On the other hand, if you were quite sure you would often need to find the largest number in each of a large number of arrays of unpredictable sizes, writing a program would make more sense. A program is useful, then, for performing a well-defined task that would be too taxing to perform by hand. The second part of the first principle, whether you should write the program yourself, also deserves comment. If you decide you need a program, it may or may not make sense for you to write the program yourself. Why should you write a program for a task if someone else has done so before? Our answer to this question is analogous to the answer a math teacher might give to a rebellious student: „Why should I prove this theorem if itÊs been proved before?‰ „Prac￾tice makes perfect,‰ the teacher may reply. He or she may go on: „Even if true perfection is beyond your reach, practice will increase the chance of your proving something new yourself.‰ Our view of programming is the same. You might be able to locate programs that already do things you need to, and it may make sense for you to use those programs, especially for problems that seem very complicated or that are beyond your technical ability. But the more practice you get programming, the more likely it will be that you will be able to gen￾erate programs that either solve new problems or solve old problems in new ways. DonÊt be discouraged if it takes an hour or more to get your first „real‰ program up and running, even if you might have done the same computation by hand in a minute or less. As you develop
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有