Think Python How to Think Like a Computer Scientist
A.3.4 I’m really, really stuck and I need help
Download 1.04 Mb. Pdf ko'rish
|
thinkpython
A.3.4
I’m really, really stuck and I need help. First, try getting away from the computer for a few minutes. Computers emit waves that affect the brain, causing these symptoms: • Frustration and rage. • Superstitious beliefs (“the computer hates me”) and magical thinking (“the program only works when I wear my hat backward”). • Random walk programming (the attempt to program by writing every possible program and choosing the one that does the right thing). If you find yourself suffering from any of these symptoms, get up and go for a walk. When you are calm, think about the program. What is it doing? What are some possible causes of that behavior? When was the last time you had a working program, and what did you do next? Sometimes it just takes time to find a bug. I often find bugs when I am away from the computer and let my mind wander. Some of the best places to find bugs are trains, showers, and in bed, just before you fall asleep. 204 Appendix A. Debugging A.3.5 No, I really need help. It happens. Even the best programmers occasionally get stuck. Sometimes you work on a program so long that you can’t see the error. A fresh pair of eyes is just the thing. Before you bring someone else in, make sure you are prepared. Your program should be as simple as possible, and you should be working on the smallest input that causes the error. You should have statements in the appropriate places (and the output they produce should be comprehensible). You should understand the problem well enough to describe it concisely. When you bring someone in to help, be sure to give them the information they need: • If there is an error message, what is it and what part of the program does it indicate? • What was the last thing you did before this error occurred? What were the last lines of code that you wrote, or what is the new test case that fails? • What have you tried so far, and what have you learned? When you find the bug, take a second to think about what you could have done to find it faster. Next time you see something similar, you will be able to find the bug more quickly. Remember, the goal is not just to make the program work. The goal is to learn how to make the program work. Index abecedarian, 72, 83 abs function, 52 absolute path, 139, 145 access, 89 accumulator, 100 histogram, 129 list, 93 string, 175 sum, 93 Ackerman function, 61 add method, 165 addition with carrying, 68 algorithm, 3, 7, 67, 132 Euclid, 62 MD5, 145 RSA, 112 square root, 69 aliasing, 96, 100, 149, 151, 169 copying to avoid, 99 alphabet, 37 alternative execution, 41 ambiguity, 5 anagram, 100 anagram set, 124, 142 and operator, 40 anydbm module, 141 append method, 92, 98, 101, 174, 175 arc function, 31 argument, 17, 19, 21, 22, 26, 97 gather, 117 keyword, 33, 36, 122, 184 list, 97 optional, 76, 95, 107 variable-length tuple, 117 argument scatter, 118 arithmetic operator, 12 assert statement, 159 assignment, 15, 63, 89 item, 74, 90, 116 multiple, 68, 110 tuple, 116–118, 123 assignment statement, 10 attribute dict , 168 class, 172, 179 initializing, 168 instance, 148, 153, 172, 179 AttributeError, 152, 201 Austin, Jane, 129 available colors, 154, 170 Bacon, Kevin, 146 Bangladesh, national flag, 154 base case, 44, 47 benchmarking, 134, 136 big, hairy expression, 202 binding, 191, 194 bingo, 124 birthday, 160 birthday paradox, 100 bisect module, 101 bisection search, 101 bisection, debugging by, 68 bitwise operator, 12 body, 19, 25, 47, 65 bool type, 39 boolean expression, 39, 46 boolean function, 54, 155 boolean operator, 76 borrowing, subtraction with, 68, 159 bound method, 189, 194 bounding box, 154, 186, 194 bracket squiggly, 103 bracket operator, 71, 89, 116 branch, 41, 47 break statement, 65 bug, 3, 7 worst, 169 worst ever, 195 Button widget, 184 calculator, 8, 16 |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling