Identify the Bug
Here we are in the bugfix lesson. You may or may not have decided to go on this side quest to identify and fix the bug in the
.move() method. Irrespective of whether you did or not, here’s my quick walk-through of how I ended up fixing this myself.
00:18 Before being able to fix it, we first need to identify what the bug actually is. And like I mentioned earlier, it’s a bit subtle. It only happens in a specific situation. So I’ll try to reproduce this.
I give it two spaces. And we need a
barn. And I give this one one space. The bug is related to trying to move animals into a location that’s currently full. And it works if the animal doesn’t have a location, but it has a strange result. If the animal does have a current location, let me show you. We’ll need two animals. I’ll start with a
So if I say
pig.move(barn), my code tells me the
barn is full. The pig’s location is still the void, and
barn.animals still only contains the
Dog object. So that’s fine. However, the bug starts if the
pig moves from somewhere else.
So this is the bug that I’ve introduced in here by kind of messily constructing my conditional logic in the
.move() method. So after establishing what the problem is, in the next lesson, let’s reset up the code that I wrote in the interactive shell here in a way so that we can run this more often without having to type all of these lines of code every time.
Become a Member to join the conversation.