{"id":23,"date":"2021-10-12T10:40:27","date_gmt":"2021-10-12T10:40:27","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/shemakesblank\/?p=23"},"modified":"2021-10-12T10:40:29","modified_gmt":"2021-10-12T10:40:29","slug":"there-is-a-debugger","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/shemakesblank\/2021\/10\/12\/there-is-a-debugger\/","title":{"rendered":"There is a Debugger??"},"content":{"rendered":"\n<p>I\u2019d like to start today\u2019s adventure by passive aggressively asking, why didn\u2019t anyone tell me about the debugger?? Like seriously, it is a total game changer and even helped me understand my coding projects even better.\u00a0 I went through a semester and a half struggling unnecessarily by putting print statements all over my projects to figure out what I was doing.\u00a0 Oddly enough, CS271 \u2013 Computer Architecture and Assembly Language is what introduced me to this wonderful and I am here to share the wealth.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">So, what is it?<\/h2>\n\n\n\n<p>It is a program that allows individuals to detect and remove errors (aka bugs) within the code.&nbsp; By running your code in debug mode, you may see what is going on when you execute the program.&nbsp; This can be done be clicking through each line and seeing what happens or it can be done by using breakpoints.<\/p>\n\n\n\n<p>\u00a0A debugger is a tool that we should all have in back pockets because it saves you time! You don\u2019t have to go around putting print statements everywhere trying to guess what exactly your code is doing.\u00a0 By running it in debug mode you can get a quick glance at what every variable is doing.\u00a0 Another reason I find a debugger to be super helpful is to help familiarize yourself with code that someone else has written.\u00a0 I typically run the debugger and go through the entire program to find out the flow and give me a better idea of what is going on?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How do I do it?<\/h2>\n\n\n\n<p>Lucky for you, most IDEs have a built-in debugger. I will give you a quick tutorial on how to debug a simple python application using Visual Studio Code.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: Find the button <\/h4>\n\n\n\n<p>Create your program and hit the debugger button. Here are two ways to do it.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/media.giphy.com\/media\/VOeBnMdyK78fgcI2un\/giphy.gif\" alt=\"\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/media.giphy.com\/media\/KHW1LAlMr2R84eWtx2\/giphy.gif\" alt=\"\" \/><\/figure>\n\n\n\n<p>If your program has no apparent bugs, then nothing is going to happen on your screen.\u00a0 This doesn\u2019t mean everything is working at 100% it just means that the debugger is not catching anything.\u00a0 However, if there is you\u2019ll probably get an error code pop up (see below).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"641\" height=\"136\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4769\/files\/2021\/10\/image.png\" alt=\"\" class=\"wp-image-24\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4769\/files\/2021\/10\/image.png 641w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4769\/files\/2021\/10\/image-300x64.png 300w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: Using Breakpoints<\/h4>\n\n\n\n<p>A breakpoint is basically a stop sign for the debugger. They are set by lighting up a little red dot beside the line of code you want to take a closer look at and you can have multiple breakpoints set up.\u00a0\u00a0 As mentioned in step 1, the debugger can be run and have no error message pop up which is great but to be a little more thorough with our debugging it\u2019s always wise to use breakpoints and verify each step of the application.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/media.giphy.com\/media\/RtmwzYIAbKDOPmg0I5\/giphy.gif\" alt=\"\" \/><\/figure>\n\n\n\n<p>Now go ahead and restart the debugger and you should get a screen like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"646\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4769\/files\/2021\/10\/image-1.png\" alt=\"\" class=\"wp-image-25\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4769\/files\/2021\/10\/image-1.png 626w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/4769\/files\/2021\/10\/image-1-291x300.png 291w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n\n\n\n<p>There are 3 immediate changes:<\/p>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\"><li>The debug pane opens on the left-hand side.<\/li><li>The currently line that is executing is highlighted yellow<\/li><li>The debugging toolbar appears.&nbsp; It is located right about line 1.<\/li><\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: Run through the code<\/h4>\n\n\n\n<p>To step through the code line by line, we will be using the debugging toolbar. You can use the debug pane to watch how your code changes as you move through it.&nbsp; You can also set certain variable to \u2018Watch\u2019 which will allow you to always see how they are behaving.&nbsp;<\/p>\n\n\n\n<p>Here is a simple python function that will give an example of how to use the toolbar.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Continue: moves forward to the next breakpoint or the end of the application<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/media.giphy.com\/media\/3lh95c42QGkVpIBiy6\/giphy.gif\" alt=\"\" \/><figcaption>Continue Function<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Step Over: \u00a0skips over a line that contains a function. The function is still executed and will produce any relevant results.\u00a0 If the line does not contain a function, then it we behave just like Step Into.<ul><li>Notice that the results from the square function are displayed in the debug pane.<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/media.giphy.com\/media\/y9s3lnRmBsO8paDwNL\/giphy.gif\" alt=\"\" \/><figcaption>Step Over function<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Step Into: moves into the next line of code<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/media.giphy.com\/media\/EdBUIjDPgfq6yrpl4L\/giphy.gif\" alt=\"\" \/><figcaption>Step Into function<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Step Out: \u00a0returns to the line where the function was called. Think of it as fast forwarding through a function. <\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/media.giphy.com\/media\/EdBUIjDPgfq6yrpl4L\/giphy.gif\" alt=\"\" \/><figcaption>Step Out function<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Restart<\/li><li>Done<\/li><\/ul>\n\n\n\n<p>Now you can finally see what your code is doing line by line.\u00a0 You can tweak anything you need to and redo all 3 steps until you are satisfied with you application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Master Debugger<\/h2>\n\n\n\n<p>The thing about writing code is that there will always be mistakes, some visible and some not.  It is important to be thorough with our work and readjust as necessary.  The debugger is a handy tool that can help us wade through our mistakes in a more efficient manner than making print statements all over the place. So I think it&#8217;s safe to say, you can now call yourself a master debugger! Yay!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019d like to start today\u2019s adventure by passive aggressively asking, why didn\u2019t anyone tell me about the debugger?? Like seriously, it is a total game changer and even helped me understand my coding projects even better.\u00a0 I went through a semester and a half struggling unnecessarily by putting print statements all over my projects to&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.oregonstate.edu\/shemakesblank\/2021\/10\/12\/there-is-a-debugger\/\">Continue reading <span class=\"screen-reader-text\">There is a Debugger??<\/span><\/a><\/p>\n","protected":false},"author":11643,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/shemakesblank\/wp-json\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/shemakesblank\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/shemakesblank\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/shemakesblank\/wp-json\/wp\/v2\/users\/11643"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/shemakesblank\/wp-json\/wp\/v2\/comments?post=23"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/shemakesblank\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":27,"href":"https:\/\/blogs.oregonstate.edu\/shemakesblank\/wp-json\/wp\/v2\/posts\/23\/revisions\/27"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/shemakesblank\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/shemakesblank\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/shemakesblank\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}