Thursday, May 6, 2010

Suggestions for coding

Here are some suggestion for troubleshooting while you are coding.

First, don't get lost in the details. Try to step back and see the pattern of what you are doing.

It doesn't hurt to write out the steps you need to take.

Use the intellisense. It tells you what objects or methods are available in the context of where the cursor is.

Most errors are typos, either misspelling a variable name or an object name. If VS claims an object doesn't exist and you know you dimmed it, the problem is probably that you mispelled it or it is out of scope.

Read the error messages. Even if they aren't exacty right about where the error is occuring, they can usually lead you there.

In VS if you doubleclick on a error message at the bottom of the code window it will move the cursor to the line and postion of the error. Always start with the first error message. Correcting it may clear dozens of other errors that cascaded from the first one.

Develop your program in discrete steps. (Do one small thing at a time.) Test your code after each step. That way if an error occurs you know it has to be in the most recent code you wrote.

For the classes, build your program after you complete each class. (You can't actually run the code in any useful way until you have all the necessary classes in place, but you can make sure they compile OK.)

If you find yourself struggling with something over a long period of time. Stop. Walk away from it for a couple of hours or even a day or so. You will often find whey you come back, the problem was obvious and staring you in the face, but you just couldn't see it at the time.

If you're having problems with a section of code, comment out parts to test variations. Don't delete the commented out code until you are sure you have it working properly. Often in a panic, people delete working and necessary code in a wild attempt to change things to make them work.

Related to this, only make one change at a time. Determine the effects of that change before trying to make a second change.

No comments:

Post a Comment