7 min read

Problem Solving : The Right Way!

When learning computer science we always making programs, where we don’t understand that the real skill of a SWE is problem solving not…
Problem Solving : The Right Way!
( AI Image )

When learning computer science we always making programs, where we don’t understand that the real skill of a SWE is problem solving not making the program itself. Anyone with any amount of tools available can make something but not everyone can solve problems efficiently. Its very easy to fall prey into just using AI to help us and we just copy paste or find other people’s code online and we copy paste. And once it works we move on.

This causes real strain once going into doing work in the office. You may be able to be decent and solving problems but moving up the ladder and trying to master the work you start to have real trouble.
And all of this stems from how we started learning. Bad habits, will always be hard to break. So how do we fix this?

Learn Problem Solving the right way :

We will talk about 3 topics

  1. How to problem solve
  2. How to understand code solutions
  3. How to use AI to bring it all together and become efficient

How to problem solve :

Solving a problem starts from understanding the flow of problem solving, this a method by Comptia Linux+ on how to troubleshoot a network but it is a brilliant way to use it for any type of program

  1. Identify the problem. …
  2. Develop a Theory. …
  3. Test the Theory. …
  4. Plan of Action. …
  5. Implement the Solution. …
  6. Verify Program Functionality. …
  7. Document the Issue.

Step 1 : Identify the problem

E.g : I want to make a button in JavaScript and I need the button to send an alert, the process flow works like this

user click → button run function → function runs alert box → alert box displayed.

We have mapped out a simple flow of how the process works, this might seem too simple but when working with much more complex programs, like wanting to create a GPT wrapper for your web application, the flow becomes huge, and without you having a flow in your head or on paper, you will feel lost.

By doing this now we can take a look at which part of the process there is an issue, you should learn how to use breakpoints and unit testing, to see how to check which part of your workflow has the issue.

Step 2 : Develop a theory

Now that you have figured out the issue and done enough research in identifying the problem, time to develop a theory. Think about the simplest problem. Very common indentation problems, missing brackets, semi-colon. If the problem is more complicated you can come up with more than 1 theory. This way you cover all parts of reasons why the issue will be caused.

If you are looking at a problem that has never occurred and you have no idea what is happening. You can put the error message in google first, as most commonly we can find similar issues very easily. You will also be able to find a solution. But what if this is a problem that no one has had before, that’s where the next steps come in, to aid you.

Step 3 : Test the Theory

Now time to test your theory, see if you can remove the piece of code or add a dummy output that should definitely work in place of where the code was and test the system. Based on the theories that you made you will want to keep trying until you find the exact code snippet that is causing the problem.

Step 4: Plan of Action

Now you have to figure out how you want to solve the issue, most likly you will find others peoples code and want to just replace. DO NOT DO THIS IMMEDIATELY. You need to ask yourself, do you understand why this solution works? If you don’t then what is the purpose of just using the code, what happens when the same code causes an edge case issue that’s even more tough to solve.

I will go into more detail, in the next section on how to understand other people’s code.

Step 5: Implement the Solution

Implement the solution is simple, you will just need to replace the faulty code, but you can also choose other options of removing the function entirely or changing the flow of the process by making the code do something else that you know will work .

Step 6: Verify Program Functionality

This is very important. Using code that you didn’t write can break other parts of your program so its very important to run tests to make sure everything previously that was working still works so you don’t have to now solve another problem.

Step 7: Document the Issue

This is a step very rarely done by most people. We solve the issue but we don’t make a note about what the process was. Especially in the workplace this can save you and your colleagues a ton of time in case the same or similar problem occurs. Having a document that is permanent you can reference it years down the line without having to find the same solution again.

Note taking apps like Obsidian, Notion are great as you can create templates where you document the dates, the type of problem, add tags and in Obsidian, create a link between files, you can have a good collection of documentation that will make you an efficient and better programmer.


How to understand code solutions :

When you look online, websites like stackoverflow or quora or even reddit, you may be able to find code solutions to your problems. But the issue is, if you have a lack of knowledge you are going to be just copying and pasting someone else’s code without seeing if it works completely with your code.

You will be able to see people explain the codes output or purpose but they won’t delve deep into each part of the code. This is where we need to do our own due diligence to learn and understand what we are doing.

You need to first understand, DOCUMENTATION DOCUMENTATION DOCUMENTATION.

Documentation is your best friend, its daunting but its a reference literature not a story book. You want to use it as a reference to understand the purpose of why something does something.
Lets take for example we had an issue with React Hooks. We were not using useState in the right way. ( React Hooks use react features like useState, that you would have had to normally make a class for) ( useState is a hook function that gives 2 values where 1 declares a state variable to store value and the second variable has an update logic inside a reducer function )

function ImageGallery() { 
  const [index, setIndex] = useState(0); 
  // ...

All the information that I have provided was gotten from the react.dev website. These reference websites contain deep information about all of the features and multiple examples. So you just need to read through to understand the logic behind the code.

And that’s all you need, just using references of documentation you are moving closer and closer to understanding better what you are doing. You may not fully comprehend everything but as you use the features more, then you start to understand and see the process flow better in your head.


Using AI to become more efficient :

Now with the introduction of AI, we need to use this as a tool to help us become faster. Those not using AI will slowly get left behind. We will do the same tasks that we did in the previous steps just adding AI to sort us faster.

  1. Prompting

You need to understand AI is a program, a program that you need to command just like how you command code. Just the difference is that AI understands English commands.

Prompt Engineering is a very very important thing that you need to understand if you want to use AI the proper way.

tell me how it works

This a common prompt most people tend to use and it may work for layman tasks that are simple but code is not that simple. You need to direct the AI to the point you want to go. Your prompts need to be long and direct because they only way to get better and more accurate answers will be using prompting.

Take this example, I want AI to give me and output in JSON format if i give it a sentence. I can say

I will give you a sentence, give me the JSON format

What will happen if I just type banana banana banana banana

This is nonsense, that humans understands AI doesn’t it will still try to give and output that makes no sense

What if we be more detailed and direct
You are a CS student who needs to create JSON from sentences, I want you to take in information as a sentence, the sentence needs to contain a name, if the sentence has a name give me a JSON output or you can just tell me there is no name in this sentence. You are to not give any other output other than those 2 options.
{ 
 "Name" : "Jason", 
}, 
{ 
 "Name" : "Jacob" 
}
This is the only way you are to give the output, follow this format for every name in the sentence, keep the format exactly same for every sentence I give you. You only can stop when I say stop.

This seems like a lot for just getting a JSON output but this is necessary, its the way that you avoid edge cases, its the way you avoid hallucination as best as possible, its the only way you can force the AI to work in the manner you want it to.


In the case of documentation, We will do the same type of prompting but we will give snippets of the documentation that we want to discuss to the AI. We want to give as much information to the AI as possible so that we can get the right output we want.


And that’s it. It might seem hard to do everything all at once, so working on trying to implement 1 thing in your process. Once that becomes easy then you go to the next step then the next. Slowly you will be able to do all of these things very easily. I didn’t understand doing most of this until after a few years of learning programming so don’t be disheartened. If you have any questions about my post or if I missed something or something is wrong, feel free to message me on twitter @ gauranshmathur.