Starting out as a young developer (a beginner) might be daunting at first, from setting up your environment to writing your very first code, trust me it’s normal— every developer has been through it.
This shouldn’t make you waver, it is all part of the learning process. If you’re hesitant to start your journey as a developer or you are afraid of making errors in your code, you shouldn’t be.
When I started out as a developer I found it difficult to solve my coding problems, I came across a strategy that would eventually help me with my problem-solving skill. Implementing this problem-solving strategy has helped me improve my problem-solving skill over time.
You will always encounter problems when you’re developing a digital product. The more you practice writing codes and solving these problems, the more familiar you get with the processes so when a problem arises you find it easier to understand and tackle.
You should do away with the fear of making errors when coding, as a developer you should be prepared to make mistakes.
As a developer, you need to know how to solve (coding) problems. Writing code is basically problem-solving.
Problem-solving is one skill a developer must possess, having great problem-solving skills will make it easier to detect and solve problems when you start writing codes.
In this article, I’ll go over some steps that you can use in solving problems.
1. Understanding the problem
2. Come up with a solution
3. Implement the solution
4. Go over your code
1. Understand the Problem
The first step to solving a problem is identifying and understanding what that problem is. It is up to your understanding of the instructions for the desired results that will help you come up with solutions.
Let us take a look at this example problem; find the area of a circle where radius = 5 and pi = 3.14.
Here we know we are to make use of the arithmetic Operators; + for addition, - for subtraction, * for multiplication, / for division, and, % for modulus. We also need to know the formula used in calculating the area of a circle, which is πr2.
We’ll use PHP as our language of choice.
So we have:
<?php
$radius = 5;
$pi = 3.14;
?>
Ask yourself;
⁃ Do you understand the question and would you be able to explain the question to someone else?
⁃ Do you have enough information? If not, you can try Googling it for clarification or you can request more clarity.
⁃ What are the inputs and how many inputs are required?
⁃ What is the desired output of those inputs?
Once you understand the problem and know the possible inputs and outputs, you can try out some examples.
It’s advisable to start with simpler examples, solve them then move to the complex ones with bigger inputs, to see the output. Solving examples will help you confirm your understanding of the problem.
2. Come Up with a Solution
Next, devise a plan for how you’ll solve the problem. List out the step-by-step process that you’d use to solve the problem, using comments.
For this problem you could write:
<?php
//First step - solve the parentheses πr2; (5)2 = 25
// Second step - multiply the parentheses result with the value of π; 3.14 * 25
?>
Now you have your solution written step by step.
3. Implement the Solution
The next step in the problem-solving strategy is to solve the problem.
While using the comments as your guide, write out your code. The simpler your solution, the more likely it is for you to implement it correctly.
Taking our comments we, could now write this:
<?php
$r = $radius * $radius;
$result = $pi * $r;
echo $result;
?>
It’s possible that you can’t solve the problem at once, not to worry if you can’t solve it fully at once you can focus on the simpler parts and start writing your code.
Temporarily ignore the difficult part of the problem that you do not understand, once you’re done writing out the simpler parts, come back to the harder part.
This allows you to get some part of the problem finished. And often, you’ll realize how to tackle that harder part of the problem once you come back to it.
4. Go Over Your Code
Once you’re done implementing your solution and it’s working. Take some time to go over it and figure out how to make improvements.
We can make our code more concise is by using the pow() function so we do not need to manually solve the parentheses:
<?php
$circle = $pi * pow($radius, 2);
echo $circle;
?>
Ask yourself these questions to figure out how you can improve your code:
⁃ Is there any other way to solve the problem?
⁃ Is the code readable?
⁃ Is the code efficient? Can it be more efficient?
⁃ Can you think of other ways to refactor?
⁃ How have other people solved this same problem? This can give you more insight.
SUMMARY
As developers, we are problem solvers so, if you don't feel confident about your problem-solving skills just remember that problem-solving is a skill that anyone can get better at with time and practice.
In this post, we have gone through the problem-solving strategy for solving (coding) problems.
Here are the 4 steps we discussed in this post:
• Step 1: understand the problem.
• Step 2: create a step-by-step process for how you’ll solve it.
• Step 3: implement the plan and write out the code.
• Step 4: go over the solution and whether the code can be improved.
I hope you found this article helpful 🤗.
Feel free to reach out to me anytime if you want to discuss something : ) moreover, I love making new friends, just send me a mail.
I would be more than happy if you send your feedback, suggestions, and questions.