Programming Tips

1. Start when the program is assigned. Don't wait until the night before it's due! By beginning to plan your project right away you'll better understand the project requirements, the comments and suggestions made by the professor, and the questions asked by other students. Start Now.

2. Read the assignment all the way through. Read it again. Make sure you understand what you are supposed to do before you start. Halfway through your project, read the assignment again - all the way through - to make sure you're on the right track. When your project is finished, read the assignment once more to make sure you've met all the requirements.

3. Plan your project. DON'T start by sitting down at a computer and typing code. Start your project by sitting down with the assignment and paper and pencil. Draw a representation of what the program looks like - the data structures, the input, the output, the relationships among different parts. Figure out what things depend on each other, which stand alone, and what data or cases you will use to test your program. Make sketches, draw pictures, or make lists - whatever works for you, but get a firm picture in your mind of what you are doing before you start to write code. Not only will this help you decide where to start, but it will serve as a guide and a reference as you proceed to write the code.

4. Have a good reference book at hand. Whatever language you're using, there are many good reference books that explain concepts, give code examples, and list commonly-used libraries. It's amazing how many programmers don't want to stop to look something up because they're sure that the next compile will be correct. Five minutes looking up a principle or s tandard technique can save you hours of constant retrying and recompiling - and frustration!

5. Write and compile your program a little bit at a time. Test frequently. It's much easier to find a bug in the last 10 lines of code you've written than in the last 100 lines.

6. Don't despair when the compiler gives you many errors. Usually an error early in the code will create other errors further on. Fix the first couple of errors that the compiler lists, then compile it again. Hint: If you find no error on the line number cited by the error message, check the line before it. The error may be as simple as missing punctuation.

7. Use function stubs. When writing a larger project, write your function headers or method declarations with empty bodies and compile your project to see that the structure works. Once your program compiles, go back and write one piece at a time. This is the incremental build method.

8. Try a different compiler if you get stuck trying to find an error. Different compilers give different error messages or find different problems. For example, when using C++ the "CC" compiler will not tell you about an uninitialized pointer, but the "g++" compiler will.

9. Learn to use a debugging program before you need it. When you need to use a debugger, you probably won't have time to stop and figure out how it works. Running through a debugger tutorial now will prepare you for using it when that mystery bug shows up the night before your program is due. To use the school Unix system debugger for C++, type "help debug" at the system prompt.

10. Insert print statements in your code to help isolate a problem location. Sometimes it's useful to know the value of a variable before and after a calculation; when a program is entering into, inside of, or returning from a function or method; or to confirm that a pointer points to what you expect it to.

11. UPE tutors are available throughout the week check our tutoring schedule.