As I continue to embark on my coding journey I had a random thought about the way I think and approach coding problems. In grade school we learned about the scientific method and I’ve come to the realization that its been my subconscious way of problem solving my code.
1) Ask a Question
I guess the question in this case would be, what problem am I trying to solve. Maybe you have a recipe object, and an ingredients object and you need to find out how many items you can make based on how many ingredients you have.
So I can think of the question as the problem, or as a deliverable.
2) Construct a hypothesis
This is where I would start pseudo coding. Writing out my logic to figure out how to solve the question being asked. Being able to pseudo code is such an important skill to have. Pseudo code works for any programming language. You can research all the syntax you want, but without being able to logically solve the problem, knowing all the syntax in the world will not help.
3) Test with an Experiment
This is the step where I would start writing out the actual code and test it to see if it even runs. Did this code work?
Then “trouble shoot the procedure.” Begin with the new question “why?” This is where I check for any typos, syntax errors, or bugs. Break it down step by step and see where it went wrong and adjust accordingly.
Move on to the next step.
4) Analyze Data and Draw Conclusions
So the code ran. Did I get the expected results from the hypothesis?
If yes, I can either move on, or check to see if there’s a different way of solving it. Maybe there’s a more efficient solution.
If the results only partially align with the expected outcome or are completely wrong, then ask the favorite question. Why? Why didn’t I get my expected result? Why didn’t the new object save to the database? Why didn’t the function or method render the correct objects onto the screen. Use these new questions to form a new hypothesis and repeat steps 3 and 4.
5) Communicate Results
If I had to apply this to coding I would say this is where you would return your results to the user or to another part of the program. Maybe the algorithm was a search function and you are returning the search results to the user. Maybe it was just one step in a multi step process. Maybe the search function was designed to find an object in the database and the next step is to do something with that object.
Being a developer isn’t just about what you know, its about how you think.