Solving Programming Problems
Going from a problem statement to code
Seven Step Approach to Solving Programming Problems Duke University coursera video (7:02)
work example by hand
write down what you did
find patterns
check by hand
translate to code
run test cases
debug failed test cases
1. Work Example by Hand
Spend time thinking about the problem and solution before sitting down to write code.
Program with a blank piece of paper in front of you.
Create an IPO chart.
2. Write Down What You Did
Create pseudocode and/or a flowchart.
Draw an empty box every time you create a variable. Write the variable name next to the box. Write the value assigned to the variable inside the box.
Draw a row of boxes with subscripts for arrays.
Draw a large box for modules. Put the module name at the top and variable boxes inside.
Draw something like a UML diagram for classes and objects.
3. Find Patterns
Think about what could be done with a loop, function, or class.
Make it work for any instance, not a specific instance of the problem.
Consider conditions.
4. Check by Hand
Check with different inputs.
Simulate the program by having a real or imaginary dialog with another person where one person acts like the program.
Use a calculator or spreadsheet to test formulas.
5. Translate to Code
Write a little bit of code at a time, making sure it continues to work.
Write without loops or functions at first if necessary.
6. Run Test Cases
Execute program to see if it gives expected answers.
7. Debug Failed Test Cases
Use scientific method.
Delete or comment out sections of code, attempting to isolate the error.
When using a language / IDE with the capability… Use breakpoints!