Fix_My_Code_Challenge

DON'T PANIC!

THINGS WILL GO WRONG!

It’s Probably Your Fault

Computers try very hard to carry out your instructions and it’s very rare that the computer will have a hardware bug. If your program doesn’t work as you expect it to, it’s almost entirely going to be your fault since the computer is only carrying out exactly what your instructions tell it to do.

So, the most likely cause of the bug is that you have done something wrong in your code.

Upon reflection, this is a good thing, becuase more often than not, you can also fix it by reading your code carefully, working out how what you wrote isn’t what you really meant to write, and then correcting things.

Don’t Just Sit There, Do Something!

The usual way you’ll learn something has gone wrong is with an error message. Unfortunately, to non-programmers error messages might as well look like this:

  • Clearly Define the Problem Welcome to programming, where most of your time is spent trying to make sense of why stuff doesn’t work as you expected.

The most important aspect of this exercise is that you build up a picture of what the program was doing, why it was doing it and how it got into a state which caused it to fail.

  • First I did this
  • Then I did this
  • Then I did this other thing
  • After which I did this thing over here
  • But then I couldn’t do the thing you asked so, “ValueError”

Starting at the bottom tells you what caused the failure, but you may need to read backwards to work out what led to the problem.

  • Talk to the Rubber Duck If you’re still struggling, talk to the rubber duck.

image

Rubber Duck debugging is a great technique for seeing things that may at first not seem obvious. It simply involves explaining each line of code where the problem is found to an imaginary programmer represented by a rubber duck (you don’t have to use a rubber duck, and it’s probably best if you imagine yourself explaining things to the duck rather than actually talk to a rubber duck… that would look weird).

This simple trick is a great way to shift your perspective to allow you to see things you at first missed. For example, “First I set X to 15, then I loop over the list X number of times so all the values are added to the total. Dammit. The total is never reset to zero… no wonder it was so high. Why the hell didn’t I see that earlier..?” is a typical way this sort of thing plays out.

Ask for Help

So you’ve looked up the exception, checked the code, rubber ducked for ten minutes and the damn thing still won’t work properly. Now what?

**Easy… just ask for help.

Don’t be afraid to ask questions - good developers are always asking questions. Knowing how to ask and what the right questions are is an essential skill to develop. Asking questions is NOT a sign you don’t know what you’re doing. To good developers it’s evidence that you’re exploring the problem and a signal that you’re engaged and interested.

So, learn to ask questions in the right sort of a way.

“It doesn’t work. What do I do?” is not going to be answered (at least in a polite way)

image

Debugging code can be frustrating, time consuming and disheartening. However, once your program works, the elation you will feel is definitely worth it.

Best of luck! :-)