CHOOSE YOUR LANGUAGE --- G E R M A N --- E N G L I S H ---

Friday, April 19, 2013

Bug hunting



Do you know about the crawling bugs hiding inside the source codes and bring the programmers sleepless nights? I would tell you a little bit about it ;) There´s many ways you can breed some nice population of bugs inside your source code as programmer. I give small non programmer compatible example.

First in detail 


You write a list with 10 balls flying around your screen for a little game. This list starts from 0 to 9, so 10 elements inside, because 0 gets counted as the first element in chain. If you forget that fact, and try to tell BALL[10] to move, you get a evil program error. But you find out quick.

If you delete balls going out the field, and use a automatic rutine for that like NSMutableArray, they fill the deleted ball with the next element. So after deleting BALL[4] your list gets shorter and now BALL[8] ( Ball number 9 ) is the last one. Sounds logic, didn’t it? But another more dangerous bug can happen by make one small mistake that way.

You write a loop handling all balls from 0 to the last element in list. And then maybe delete a ball out of the list if its moving out the screen. Then you jump over one ball in calculation! 
Why? At the moment you delete for example BALL[3] the highest ball in chain [9] replace his position, so the list now only contain 9 balls. But your loop after handling BALL[3] going to handle the next ball and this is BALL[4]. Ball[9] who´s now in position of the deleted ball Ball[3] gets not handled this frame in game. Maybe that causes no problem, but maybe in some constellations this bug happen just once a hour in your game and can do everything, starting with a empty not shown image for some frames, up to break the program by error. And the not every time happening bugs, you cannot reproduce the same way again and again, are very different to hunt down, like try to shoot a deer eating grass every day at the same time at a clearance ( defined position ). Its a simple job in opposite hunting down a wild leopard where you don't know when and where he´s located between the bushes.

Some funny story from "BLACK AND WHITE"


One time the developers of BLACK AND WHITE written about some funny bug they have had. Some big creature like a pet you can act with, walking around in game, you can try to command him, feed him etc. And one time in game he just run in cycles around, and they don’t find out why he do that first. They try long to find the reason, and finally they find out he was hungry, in the mode for finding food, and so he checked all other units around, and walking to the nearest… and they do not make this procedure precluding himself in the list of possible units to eat. So he just try to eat himself... ;)

Everything is just logic, but logic can be very complex, and even if you have great skills, sometimes a mistake happen. In opposite of this it makes you stunning if you write long parts of source code without checking or running it, and after finish it you see all is running like planned without any problems. Its like driving car to the next city with closed eyes, and arrive without any accident ;) But its already great enough if you can make the written code running just by read over it once again and fix small details in about 5 minutes.

No comments:

Post a Comment