Now, I've got some final tips for debugging,
and these are not so much techniques, but there are just really,
really important tips from somebody who's done quite a lot of coding and created
a massive amount of bugs in my lifetime.
So tip number 7 is take a break. It's really,
really important when you're just staring at the code and you keep looking at
it, it's not going to tell you the solution.
Just have a cup of tea or have a nap,
or just go to sleep and try to tackle it tomorrow.
You will be surprised just how much easier things are when your brains had some
downtime and then you come back to it. Everything seems so much more obvious.
And if you really, really get stuck and you just can't see it, ask a friend,
not your friend print, but your actual friend,
a real human. Preferably a developer, but they don't have to be.
It could be somebody who's taking the course with you.
You could go onto discord and find other students to help you because after all,
you're all just leveling up your own programming skills
right? The really good thing about asking a friend to look through your code is
they won't make the same assumptions that you've made.
So they have some fresh eyes that they can look at the code with,
and it might be incredibly obvious what's actually happening.
And it's really not embarrassing at all.
If somebody managed to help you with your code,
you can offer to help them the next time when they get stuck. And for the person
who's helping you,
they're also just working out their programming muscles, right? Now
the next tip is to run often. No,
you don't have to go exercising to be a good programmer.
But what I mean is run your code often.
Don't wait until you've written loads and loads of code to hit run
and then find out you've got loads of snags and loads of bugs.
But run it after every little execution.
Once you feel like you've changed the program ever so slightly, run it. Confirm
that it's actually doing what you want it to do,
because if you leave it all to the end,
then you end up with a pile of bugs and you don't know where to start. Now,
if you do end up in that situation and you can see multiple bugs at the same
time, try to tackle them one at a time
instead of trying to do bits and bobs of each. It will really, really help.
And the final tip is, of course, Stack Overflow. I've saved this the last
because you really don't want to take every single small bug of yours to Stack
Overflow, that's not what it's designed for. Instead,
it's really designed as a way of asking other developers
when you think that you've come across a bug or an issue that should be unique.
Now, if you think that you issue isn't unique and other people should have
encountered this, then just search Stack Overflow.
If you really think that nobody in the world has had this issue that you are
having right now, then that's the moment to ask the oracle, I mean Stack
Overflow.
I've worked in a lot of companies where everybody just goes to the part when
Stack Overflow is down, because there's just no point. As programmers
we use it and we search it so much and it's become a really vital tool in the tool
belt.
But you only wanna ask a question when you've pretty sure that you've exhausted
all other avenues of debugging and you've searched all of Stack Overflow and you
finally end up with something very strange and very weird that you want others
to help you figure out. So don't worry about creating bugs.
And hopefully at this point, you're creating friendly bugs,
like this little Caterpillar right now.
And as you scale up and become even more advanced,
you're going to be creating bigger and more scary bugs.
So at some point in the future, when you're creating bugs like these,
then you really know that you've become a professional.
You will wish to come back to today when you can tackle bugs like these
instead. So don't worry about
about creating them. It doesn't mean that you are bad programmer. In fact,
it's an important part of every programmer's journey. Just as a sort of personal
note,
there was a point in time where I've really thought that I was not a programmer of
code, that I was just a programmer of bugs.
It seemed like every line of code I wrote was a bug.
So these are my 10 top tips for debugging.
And I hope that any time when your code is not doing what you expect it to do to
come back to this lesson, review these 10 steps, go through them one by one
and I bet 99% of the time, once you've gone through all of these stages,
you will have solved your bug and you will have made your code a lot better.
And remember that every bug that you catch in your code and that you fix is like
lifting a dumbbell in the gym. It's just one rep.
And the more reps you do the better you'll get at programing. In the next
lesson, I've got some coding challenges for you to debug.
Are you ready to flex your programming muscles?
I hope so. Head over to the next lesson and get started.