How to overcome the struggle of not being able to find a fix for a coding problem?

How to overcome the struggle of not being able to find a fix for a coding problem?

by Nedim F.

·

8 min read

Let's face it, coding is hard. It's hard for a human brain to think like a computer. Unfortunately to understand the problem you have to think like a machine. One thing to have in mind from the very start, no one can teach you how to think. You have to do that all on your own.

You have to practice, more you practice more comfortable you are in your knowledge, by being more comfortable you are making a better foundation. Having a solid and good foundation is key.

How to build a solid foundation

To build a solid foundation you'll need dedication. Lots and lots of dedication. You have to start small. Learn the absolute basics of the topic. If you are learning a new programming language, usually that it is language syntax.

How did you learn to ride a bike, or drive a car? You practiced, those are skills we have to practice every day so we don't forget. The same is with basic math, as a kid, you had to do all these small problems, as homework. Even tho most of us hated our homework, it helped us to understand how basic mathematics works. Apply the same thing to coding as well, when you are teaching yourself basics, be sure to practice them.

Here is an example of what you can build, after you are comfortable enough in the syntax of the language:

This applies only to OOP programming languages

  • Imagine you are having a bakery 🧁 . Create classes and methods to run your bakery, make it into a CLI app. Play around with language syntax as much as you can. If language has various patterns, try them out.

I think I have a solid enough foundation, what now?

If you think you have a solid enough foundation, you can start by researching your problem. Don't be afraid to use Stack Overflow or any internet resource, there is a good chance, someone already had the same issue and found a solution for it. Especially if the error you are getting is not even your fault, many times it can be IDE just messing with your will to live. jk, ofc.

After you are positive that your problem fix is not a quick search away, then you have to start thinking logically. This part applies to most programming problems, it doesn’t matter if you are a Mobile, Web, or even AI developer.

Break your problem into smaller pieces

To best show this, I'm going to use the example of one of the problems I have faced years ago. When I was just starting coding, I had this cool idea for an app, I can’t really remember what it did, but I know it had something to do with camera and saving photos to a phone storage. The issue was the path that I was looking for, wasn’t valid.

Let say you have the same problem path data://mobile/storage/DCIM/pictures/myimage.jpg isn't valid. The only thing that you know at this point, this path isn't valid, You don’t know why, you just know that image taken does not show when you try to load it.

Let's break our issue into smaller bits: First, we have to check the whole path of that problem. Let's call it our "route to hell". So what does my code do before this issue occurs?

  • takePhoto() method is called. This method does this and that. Alright, let's see if an error occurs there
  • takePhoto() returns object TakenPhoto
  • TakenPhoto contains few object properties, but most importantly it contains path property
  • Check if the property is alright and if we can access it.

After checking all these little things, we have concluded that "route to hell" is working how it's supposed to. Now it's time to think logically. We start by searching documentation for object TakenPhoto. We came across the developer page for that object and we look for property path. We read documentation about that property. Property path of the object TakenPhoto returns path as String but have in mind that string has prefix data:// in front. Now we have to figure out why the prefix data:// is added in the first place. We search for that answer as well, we find the answer being data:// is added because property path returns place in device storage. Now we have even more information about our problem.

Let's review, we have broken our problem into smaller pieces, analysis of the "route to hell" has shown that all methods are indeed working correctly. Then we have an isolated issue, and we figured that path property is causing us all this trouble. Now we just need to fix it. Easier said than done, right?

Fixing

Our investigation has confirmed that the issue is in path property. We then read documentation in loading images from device storage where we discovered that we have to convert our type String to type URL. We approached converting part

let pathURL = URL(string: path)

Final Test

After few hours of solving this problem, we have finally find a fix. Run it -> Loading ... -> Booom! -> It's working!

Final thought

Being a developer is amazing, it gives you the ability to build whatever you put your mind to. But with power comes issues. Some are solvable in few minutes, some take days or even weeks, but most importantly it's to not quit. You can take few days break, even weeks of break, but solving the problem is the key. Don't quit on the problem, give your best to solve it, solving it even partially can have a huge impact on your career.

About me

I'm Nedim, backend, and mobile app developer, who enjoys working on new stuff every day. Currently, I'm developing this cool app called Tweetly. You can find me on Twitter and be free to DM (@nedimcodes)!