banner
AgedCoffee

AgedCoffee

Practical Guide to Solving Difficult Problems

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 big discoveries here, just hard-earned advice.

  1. Think carefully about the problem for a few weeks before writing any code.
  2. Define the input and output of the function or class.
  3. 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.
  4. Write detailed pseudocode steps, it doesn't matter if you don't know the specific implementation.
  5. Try implementing some simple steps and mentally simulate the implementation to build your confidence.
  6. Attempt to implement the difficult steps by breaking them down further using the previous steps. You will be surprised at your progress.
  7. After implementing about 80% of the solution, try finding existing implementation solutions to help you. (Personally, I would practice this step as step 0)
  8. For particularly difficult problems where you have no idea, search for related problems on the internet and compare and learn from others' implementation solutions to improve your own.
  9. If you still can't find any relevant practices even with help, try taking a break and clearing your mind. Inspiration may come at unexpected times, like when taking a shower.

I believe these are steps that all programmers would take, but it's also nice to say them out loud sometimes.

I particularly value the decomposition of functionality. Functions are powerful abstractions, not just for writing less code, but also for thinking about problems.

Please do not misunderstand my use of the term "function" as referring only to what functional programmers like. 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!

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.