Problem-solving For Developers
My notes on a helpful Fireship YouTube video.
Written by Anthony Ongaro, on 2022-09-22
Watch on YouTube
1. Identify and Understand Problem
“If I had an hour to solve a problem, I’d spend 55 minutes thinking about the problem, and 5 minutes thinking about solutions.” - Albert Einstein
- Start with context
- Explain why it’s an issue / what you’re trying to accomplish
- Summarize why problem should be solved
2. Research and Refine
Start Googling…
- Research other people’s solutions as a starting point
- Look for other sources of learning like YouTube videos, and other free online sources
- Make sure you confidently understand what the code does before using it
- Discuss the idea with other developers
- Refine problem into smaller problems
- Weigh pros and cons of different approaches
Number 5 above is arguably the most important: break down a problem into it’s smallest logical components and then work on the ones you can figure out first. Start with what you know how to do and build on that.
3. Write Pseudocode
Focus on logic (how it works and flows), NOT syntax (proper code formatting). Work through what you want to achieve using plain english language as though you were writing code.
age is 40
if age is more than 40
print Age is above 40 to terminal
else if age is equal to 40
print age is exactly 40! to terminal
otherwise
print I guess age is less than 40! to terminal
end
becomes…
age = 40
if age > 40
puts "Age is above 40"
elsif age == 40
puts "Age is exactly 40!"
else
puts "I guess age is less than 40!"
end
- Added benefit is that you can work on naming your variables and methods well before worrying about other stuff
- Creates general idea on how to implement the code
- If working with API, use Insomnia to implement code before making requests
4. Test Driven Development
- Write good tests that will be helpful for making sure it’s working
- When possible, write tests before writing code
- Use red/green/refactor, prevents regression and allows refactoring
5. Implement The Solution
- Get to passing code as quickly as possible
- Doesn’t have to be perfect
- Leverage dopamine to see success
- Rush to implement initial code like a hackathon
- Make sure the problem can be solved.
6. Reflect and Improve
It’s easier to improve existing code that works vs write new code
- Improve readability by naming better
- Add comments
- Remove duplication
- Optimize time/space complexity
- Add error handling
7. Practice
Unlimited problems to solve, so practice solving problems. You can get good at problem solving just like getting good at a musical instrument. It takes time and practice, and your brain will start changing to understand the types of problems you’re working on solving. Every aspect of what you’re learning and doing can and will improve.
- You’ll get faster at typing
- Your brain will know what to look for and where
- You’ll learn more shortcuts, programs and systems
- Your knowledge will grow exponentially as each understanding stacks upon the previous learnings
- You’ll even get better at Googling and knowing what to look for to find your answer
8. Get Feedback From Other Developers
Made with ☀️ in Phoenix, AZ