QA Friday 2016-Feb-12

Take Up Code - A podcast by Take Up Code: build your own computer games, apps, and robotics with podcasts and live classes

Categories:

What advice can I provide to help you debug your code? In this episode, I give you seven tips to help you debug your code. One of the students brought in a programming assignment to the live class last week. This assignment was from another class and I explained some of these tips and we used them to solve the problem. Here are the tips that I recommend to help you fix software bugs: Make sure you know exactly what is expected and what’s not working. Just being very clear about what should happen and what’s actually happening will be a huge help. Sometimes, the problem is just a misunderstanding. Try to isolate parts of the code. If you can replace methods with versions that just return known good data, then you can start narrowing down your search. Try to simplify your data. Just like the previous tip, this will help you to narrow down your search. Focus on the edge cases and try to purposefully cause some bugs. Fix the bugs and you just might fix the original problem. Sometimes a bug is similar to an edge case. What do I mean by this? Modify your data so maybe there is no data at all. If you have a range of values, try the lowest and the highest. And try values outside of the range. Even try creating malformed data. Keep track of all the scenarios you identified when working with the edge cases because these make excellent unit test cases. Make use of unit test cases and run them after making a set of changes as soon as your program is back in a running condition. This will help raise your confidence in your changes. Learn to use your debugger. This is a great tool to use even when you’re not looking for a bug. It can help you become familiar with code that somebody else wrote. Create a log file and add trace statements. Record information as you enter and leave methods, as you test conditions and branch into various if and else statements. And record your loops and data variables you’re working with. Remember that many times, the clue to helping you fix a bug won’t be what’s written to the log file but could also be what wasn’t written to the log file. Listen to the full episode or you can also read the full transcript below. Transcript Thank you for your review and comments. The thing I liked about this review was the support from recommending the podcast to other students. If you know anybody who would like to learn how to program, then let them know about it. I put a lot of effort into producing each episode so that you can get the most benefit from an organized and information packed 10 to 15 minutes. Your friends will be sure to thank you for the recommendation. Okay on to the question this week. And, well, it’s not really a question. In the live class last week one of the students was struggling with a programming assignment from another class and he asked for my help. I don’t believe in doing somebody’s homework for them but I do believe in helping people learn skills so they can breeze through assignments like this. This episode contains seven tips that I provided during the class. And maybe one or two more that I thought of while preparing this episode. I don’t always know what you’re struggling to understand. If you’re having difficulty with something, then others are probably having the same trouble. Taking the time to ask a question is a great way to get an answer to your situation and help others too. The first problem was a lack of clarity about what was expected. The assignment was not clear at all even to me and we made some good guesses for what was expected. When you’re faced with a situation like this, make sure to ask questions and don’t stop asking until you know what the problem is and what solution to provide. In fact, when I’m interviewing an experienced programmer, I’ll often give a vague problem on purpose just to make sure that a candidate knows how to define a problem and the requirements. #2