top |
Posted - 04 June 2011 : 01:18:19 Programming and Debugging Tips Part of the gadget development process (or any code development process) is understanding why things don't always work the way you expect them to. This section describes some basic techniques for avoiding problems, and for fixing them when they occur.
Start Small A fundamental rule of programming is to start small. Get a basic, skeletal gadget working, and then build it up gradually. Test it at every stage before moving on. Using this approach makes it easier to tell when a change you made introduced problems.
Study Existing Gadgets One of the greatest resources available to you as a gadget developer is existing gadgets. Go to the content directory and look at the source code of gadgets that closely resemble what you are trying to implement.
Use the Firefox JavaScript Console You can use the Firefox web browser to test your gadgets on iGoogle during development. If a gadget isn't working properly, open the JavaScript Console (Tools > JavaScript Console), select Errors, and scroll down to see if your gadget has JavaScript syntax errors. Before each test, remember to clear the Console to flush old error messages.
If you're using a different type of browser, look for a JavaScript console or debugger supported by your browser.
Confirm Your Assumptions Confirming your assumptions during the development process can save you a lot of time and wasted effort. Are you sure that your variable has the value you think it does? Are you certain that your array contains elements? Is it possible that the function that "doesn't seem to be working right" isn't getting called at all? You can test your assumptions by printing out status messages at different points in your program. For example, the following gadget has a print() function that writes debugging messages to debug_div if the debug flag has a non-zero value:
code removed - post it as a link to a text file |