**Disclaimer:
My blog contains content that may be objectionable. Some of the posts in this blog may contain strong language or (because of my religious and personal views) may be offensive to some readers. In the future I may separate my programming posts from personal posts, but for now they are all contained in this blog. I should not have to even mention this, however some readers may be looking at my blog for programming help, therefore I am giving an advanced warning. All posts with material that may be offensive contain 'Objectionable material' at the end of the post title. If you see a post with "Objectionable material" in the title, and you are closed-minded or think that you may get queasy, don't fucking read it.


Friday, August 21, 2009

SSCCEs and getting help by providing test code

SSCCE: Short, Self Contained, Compilable and Executeable

When debugging a program, you may run into problems that you simply cannot find on your own. If you have tried using a debugger, and have gone over your code many times looking for the problem, it may be time to give in and ask for help. The first thing to do before asking your question is to create an SSCCE. This is a small simple test program that can be compiled and run by someone else to help find the bug. You should make this test case as simple as possible. Remove any code that is not related to the problem. Remove any GUI components, methods, variables and anything else that is not related to the problem. You want the code to be clean, readable, and short. The test case must also be compilable and executeable. There is no point in posting an SSCCE if the person trying to help cannot run the code to look for the problem. Be sure that the problem is in the test case. It can be a real pain to create a test case and spend the time to remove sections of code. But if you remove small sections, such as one method at a time, then try running the code before removing another section, you will find that 9 times out of 10 you will find the bug yourself. You can quickly narrow down and find a bug yourself this way, just by creating an SSCCE. If you have trimmed down your code and still cannot find the problem, post the code into a site like www.pastebin.com and then copy the url to add with your question. Be polite, clear, and concise when you ask your question. Tell them what is happening, what you have tried while debugging, and provide the SSCCE url. Don't be rude or demand help, as most of the people where you go for help are volunteers do not have to help you, however they are offering their personal time to help others. They also may not give you an exact answer, but will point you in the direction to find the answer yourself. This way you will learn why you have the bug and will be able to prevent it from happening again in the future.