Title: Practical Guide to Solving Difficult Problems
Date: '2022-05-04'
Tags: ['Hackers and Painters', 'Blog Translation']
Draft: false
Summary: ''
Original Article: Practical Guide to Solving Hard Problems
Sometimes, I find myself needing to write some code, but I don't know how to do it. Have you ever experienced this? Here are the steps I take when facing difficulties. There are no major discoveries here, just hard-earned advice.
- Before writing any code, carefully think about the problem for a few weeks.
- Define the input and output of the function or class.
- Break down the functionality into multiple steps with clear goals. You may not know how to achieve these goals, but you can plan abstract implementation methods.
- Write detailed pseudocode steps, even if you don't know the specific implementation.
- Try implementing some simple steps and mentally simulate the implementation to build your confidence.
- Attempt to implement the difficult steps, breaking down the challenging parts into smaller steps as before. You will be surprised by your progress.
- After implementing around 80%, try finding existing solutions to help with the implementation (I personally practice this step as step 0).
- For particularly difficult problems where you have no ideas, search for related problems online and compare and learn from others' implementation solutions to improve your own implementation.
- If you still can't find any relevant practical help, try taking a break and clearing your mind. Inspiration may strike at unexpected times, like when taking a shower.
I believe these are steps that all programmers take, but it's also nice to say them out loud sometimes.
I particularly value function decomposition. Functions are powerful abstractions, not just for writing less code, but also for problem-solving.
Please don't misunderstand my use of the term "function" as something only favored by functional programmers. I mean any data transformer, from low-level lambdas to monolithic objects with stateful IO processing.
Thank you for reading! Now go solve those difficult problems!