Helpful Coding and Debugging Tips

Image retrieved from: CleanRouter

Approaching problems:

Break down the problem first. – Look at the problem as a whole, can you break it up into sections? Are there any sections that need to be repeated? Do I need to create any objects or structs?

Look for repeated actions in the problem. – This will help identify where you need to put loops in you program.

Pick wherever you have the best understanding of the problem to start. – Starting a program can be hard but eventually the whole thing will have to work so you can start wherever you want. Starting where you have the most understanding is often the easiest and can lead to other sections easily.

Write comments to outline your program first. – This will help you section off the program and break up the problem into manageable stages and pieces.

Style:

Write methods for repeated code. – If you find yourself wanting to copy and paste code, think about making it into a function. Think about what variables are needed and what the output should be.

Try to create variables as close to the point they are used as possible. – This will reduce confusion about what a variable is for and its initial value.

Comment strange lines and loops. – It is generally good to label loops with comments by what they do and strange lines to remind you of their purpose and function. This is also a good reality check and a good way to keep you honest.

Debugging:

Isolate bugs using print statements. – Start putting print statements into your program to help find what part of the program is executing and where things are going wrong. This is good for finding wrong values and infinite loops.

Ask yourself questions about confusing code. – Ask yourself what a confusing line of code is supposed to be doing. Is it really working as intended?

Ask a coach (or a friend) for some help. – Often times someone else who is fresh to your code will take a moment to understand your code and will quickly see small logic errors that you do not.

 

If all else fails…

Don’t be afraid to Start Over. It is okay, occasionally we take the wrong approach to a problem. Starting fresh on the problem can be helpful especially in the case of large cascading errors. That said DO NOT delete your old work, just start a new file and re-approach the problem. This way you can access your old work as much as you want.