正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 7.1.16 In general, taking care to meet each of the stages when you Documenting code create code will often ensure an easier time when you have to efine or replace code. Getting into the habit of doing this every time you write something, even if you are only minutes Expected or required types of arguments Type of returned value away from some problem set deadline, will greatly improve List of constraints that must be satisfied by arguments or stages of computation Expected state of computation at key points in <: 8n2003 6 001 SICP 6.001 Notes: Section 7.2 Slide 7.2.1 While we would like to believe that the code we write will al ways run correctly, the first time we try it, experience shows Debugging errors that this is a fortunate happenstance. Typically, especially with. Common sources of errors complexcodethingswillnotworkrightandweneedtodebug.commontoolstodebug our code. Debugging is in part an acquired skill -with lots of practice you will develop your own preferred approach. Here we are going to describe some of the common sources of errors in code, and standard tools for finding the causes of the errors and fixing them Slide 7.2.2 Common errors A common and simple bug in code arises when we use an unbound variable. From the perspective of Scheme, this means that somewhere in our code we try to reference(or look up the value of)a variable that does not have one. This can Solution: search for instance occur for several reasons. The simplest is that we mistyped-a spelling error. The solution in this pretty straightforward-simply search through the code file using editor tools to find the offending instance and correct it 6 001 SICP6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 7.1.16 In general, taking care to meet each of the stages when you create code will often ensure an easier time when you have to refine or replace code. Getting into the habit of doing this every time you write something, even if you are only minutes away from some problem set deadline, will greatly improve your productivity! 6.001 Notes: Section 7.2 Slide 7.2.1 While we would like to believe that the code we write will always run correctly, the first time we try it, experience shows that this is a fortunate happenstance. Typically, especially with complex code, things will not work right, and we need to debug our code. Debugging is in part an acquired skill – with lots of practice you will develop your own preferred approach. Here, we are going to describe some of the common sources of errors in code, and standard tools for finding the causes of the errors and fixing them. Slide 7.2.2 A common and simple bug in code arises when we use an unbound variable. From the perspective of Scheme, this means that somewhere in our code we try to reference (or look up the value of) a variable that does not have one. This can occur for several reasons. The simplest is that we mistyped – a spelling error. The solution in this case is pretty straightforward – simply search through the code file using editor tools to find the offending instance and correct it
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有