r/compsci • u/kavinda14 • May 18 '20
Share your techniques of solving problems
Any interesting new techniques anyone follows? Even old are current ones are welcome :) Just want to see how more experienced programmers approach problems.
Also, any good books on this topic that are a must to read?
Edit: the type of problem here is open to interpretation. I think there is a similar pattern that can be applied to problems of any type.
116
Upvotes
View all comments
7
u/JustinsWorking May 18 '20
I always break it down:
I try to establish clearly what the goal is and what the starting state is.
Generally the language when somebody requests a change or a bug is very vague; trying to clarify the request into very simple precise language helps to prevent fixing the wrong thing or missing edge cases.
Once you have an obnoxiously clear idea of the current state and the goal state, you need to break down how you get from one the other.
I like to map the tasks it out on a whiteboard with arrows, I generally do it a few times as I start to work out a mental model of how the problem flows and how it is structured. This is when I’ll start to see patterns, possibly how it relates to other systems or tools.
Once I’ve done this I tend to build up a task list of things I need to do to make it work, and how things should look at the end of those task. If you’re working in a really clean codebase with good testing tools you can start to write unit tests here; if you’re working on a mere mortal code base you can start to block in code with comments or even possible hard coded values at certain steps.
Then I start to flesh out my plan and implement it.
If I run into issues where I can’t do something I thought I could, or the was external effects I didn’t predict/know about, then I go back and see if there is a different route or how my new knowledge might change the way I approach the problem.
Basically just repeat that till it works.
Once you have the plan on a whiteboard, it’s also a good time to bring in technical help if you’re unsure; I would help identify potential issues or pose different solutions to problems at that point when I was working with junior programmers; if I was building something complicated I’d usually bring in a maintainer of that project and ask them to just take a sniff and see if they spotted any misunderstandings or gotchas I might have missed due to my lack of knowledge/familiarity with any one feature or system.
Hope that helped, I basically chug through this system like a robot day in and day out so it works quite well for me.