- [Instructor] The name of this video is, Debugging Lite. In lesson two of the course, I'm going to go deeper into debugging with a more involved lesson, but I thought it would be important at this point before you start to get into some of the in-video exercises and the assignments, to go over some debugging and cover what are the three most common errors that early programmers will face and make? So the first question is, what's debugging? Well, debugging's when you have a problem in your code and you were trying to figure out why it's not working. So you're trying to hunt down that bug and resolve it. So for example, if I run this code, down at the bottom of the screen, in my editor, I get an output that the interface, that section of the interface, turns pinkish color, and I'm given a message and something called a traceback. And so these items that you see in the output, when you get this pink screen, are little clues that will help you track down what's wrong with your code and why it's not working. So this is one that we've seen before from the last lesson. And the message is saying, the name INTx, INTx is not defined. And then the traceback is telling me where I might start looking for that error. So it's telling me, line six. So I looked up at line six and I noticed that I've written INTx differently than I wrote it when I assigned the variable. So, that's what my problem is. And this is a very typical problem for early programmers is to not write the variable the same way when you use it after assigning it within the code. And so Python is telling me that it doesn't know what I-N-T, lowercase X means because I haven't defined it, I haven't assigned it in the code. So, this one's fairly easy to correct. I just find where I've written it incorrectly, and I correct that. And that should work. So now it's running five and it's printing out the integer five. Next, another common error is to forget a parentheses. So if I turn this line, on line nine, and we run this, and I can turn off this, so it's shift+control+C to comment out multiple lines. So I'm gonna run this, and I'm getting a rather strange error that says something about a syntax, unexpected EOF while parsing. I'm not exactly sure what that means. And it's throwing an error in line 16. Well line 16 isn't even turned on. So maybe let's turn on a line below this line to see if we can figure out what's going on. So I'm assigning point here, these values, and it should run that. Let's run this again. Okay, now I'm getting an error, syntax error, a different one called, unexpected token point. And so this is rather strange because it's throwing the error in the line, line 10, the one I just turned on, and this looks totally fine. I have, you know, a variable, I'm assigning it these values, everything seems to be fine. So, I look in the line above it and I have add line. Well, I could check to see if this is actually working. Run it one more time, get the error again, and it's not producing a line. So, something's going wrong with this line. So what the problem is is that every time when I have a function, the assignments need to be contained within their own parentheses. And so what I'm missing here is the end parentheses of my function, which closes it or stops it. So, why this is throwing the error in the line below it is that it's seeing the line below it as part of that function. So it's seeing this line as continuous because I haven't ended this function right here. So I need to end that by putting a parentheses on the end. The editor also does something that's pretty handy is that it shows me pairs of parentheses. I always have parentheses in pairs. So, when I'm running a point like this, it's showing me the closed, it's showing me the partner of that parentheses. So this is showing me the partner of that parentheses, this one, that one. And so the ending one here, if that was missing, it's going to not show me an ending or a partner of that parentheses. So I need to have that in place, which ends the line of the function. And now that should run, and it does, it creates that line. So that's another one. If you're getting a sort of strange error and it's sort of showing up in a line that doesn't seem to have an error in it, it seems to be written correctly, it might be that you've forgotten a parentheses in a line or two above it. Third one is giving a function incorrect data. So, I'm trying to add another line and I've written in the variable line, which I've created here. So whatever I've produced out of this function, I'm holding within that variable line. And then I'm feeding it into this function line here. And it's telling me an error, could not convert this long set of characters, which I recognize as a G-O-I-D, to a point 3D. But I see something strange in the traceback. So the traceback is telling me to look at three different lines, and two of those lines I don't have in my code. So, 655 and 480. So I don't have that many lines in my code. But if I look a little bit further, it's showing me that, that's really part of the sort of structure of the editor. So it's showing me IronPython and some other path settings. So, what that's really telling me is it's throwing an error sort of in the works behind all of this stuff, behind the code, there's a code behind this code that's getting it to run and it's throwing an error in there. Well, I can't do anything about that. I can't look in that code, but then I recognize there's a line 13 here. So that's the one I wanna look for. So you sorta want to ignore the ones that seem outrageous in terms of their line numbers and look for the ones that are more obvious, that they would be in your code. So, it's throwing an error at line 13, and it's saying it could not convert this ID to a 3D point. Well, a couple things to ask here is, what is the line carrying, and what is add line looking for? So the first thing to do is look at well, what's add line? What do I actually need to give it? So if I go under my Help menu and I look up that function, add line, I can look under parameters. This is what it's asking for. Okay, it needs a start and end, it needs points. Now it also, so it is a point, which I understand is coordinates, but it also has a GUID. I'm giving it a GUID, but it's not recognizing that GUID as a point. So I need to give it points. Now, there's a difference here between these two things, but they're also, they share something if they're a point, and we're gonna talk about that in the next part of this lesson is what really constitutes a point in RhinoSpace and also in PythonSpace? But I would assume now that I need to give it point data, and I'm not giving it the right thing. Either I'm not giving it the correct GUID, or I'm not giving a correct point data. So, one thing to ask is what is line holding? And the easiest way to find out what something is holding, what a variable is holding, is to print it out. So if I type in, line, here and what I'm gonna do is temporarily turn off line 13 by putting a hashtag in front of it. I'll comment it out so it doesn't run. And then I'm just gonna print out. What I wanna do is just print out what's being held in line. So, run that. And it shows me that there's an ID being held in line. And because it's output from the function ad line, I understand it as a line. So, that's not gonna work because this needs a point. It's not gonna work with a line. So, I understand that point here is holding a point, point values, so I can put that variable in here. And we'll run it again. And I'm going to turn this off to make sure that, that creates that line. And now it's telling me line is not defined because I've turned that off. So, I've turned off that line of code, line nine, by putting a hashtag here. So we need to either turn this off or print something else out, or I'll just print out point. And that's what it does. So in debugging, especially when you're first starting out, and we haven't really looked at other ways of seeing what variables are holding, the print function is going to be your best friend 'cause it's the way that you really find out what's being held in a variable. You just print it out. And so there's a mantra, you should remember, a mantra for this course. When in doubt, print it out. So when you're doubting what you know is being held within a variable, just print it out to see what type of data it is. You could also use the type function to see if it's the correct type. But chant this to yourself over and over again, when in doubt, print it out. And that's one of the basic fundamentals of debugging.