- Take a break learning commands to talk about general approaches
- Real computational tasks are complicated. To accomplish them you need to think before you code.
Problem decomposition steps
- Understand the problem
- Restate the problem in your own words.
- Know what the desired inputs and outputs are.
- Ask questions for clarification (in class these questions might be to your instructor, but most of the time they will be asking either yourself or your collaborators).
- Break the problem down into a few large pieces. Write these down, either on paper or as comments in a file.
- Break complicated pieces down into smaller pieces. Keep doing this until all of the pieces are small.
- Code one small piece at a time.
- Think about how to implement it.
- Write the code.
- Test it… on it’s own.
- Fix any problems.
- One way to do this is to identify functions.
Example
Build this example up piece by piece. First do then top level, then breakdown one bullet, etc.
Make a graph of the relationship between diameter and height in trees and highlight the relationship for a single species.
- Prepare data on diameter and height
- Download data
- Import data
- Clean data
- Filter nulls
- Make plot
- Plot diameter vs height for all species
- Basic plot
- Good labels
- Transformation?
- Colors?
- Add points for highlighted species
- Clean up plot
- Plot diameter vs height for all species
- Reproducibility check
Make a simpler version first
If you aren’t sure how to do something, make a simpler version that you do know how to do first.
- Experiment
- Write a simpler version
- Make sure it works
- Make sure you understand it
- Modify it to make it more complicated
- Repeat until finished