7 Powerful Principles to Tackle Complex Coding Problems 😤
Tags: webdev, programming, typescript, vue
Published: 2023-10-25 13:59:17

Recently I was given the task to fix a bug in a very complex component with some mind bending recursiveness going on. It took me days to wrap my head around everything but I eventually got through it. 

These 7 powerful principles helped me to tackle the problem:

**1. Think first, then code**
My first tip is to step back and think about the problem first. Maybe draw a little sketch, create a diagram, write down your thoughts or talk to somebody else about it if you can. 

Separate the coding environment from your thinking environment,  meaning, close your editor and work on a piece of paper, whiteboard, or inside a diagram tool. 

Only when you fully understood the problem and have a clear strategy to work on it, it's time to dive into the code.


**2. Break down the problem**
Complexity is really just a bunch of simple problems chained together. Try to break down your task into smaller chunks that are more manageable. 

This is the hard part, because it requires some training to understand how bigger problems are made up. Only thing that really helps here is to have seen a lot of simpler problems before and try to recognize patterns.

**3. Fix your data first**
Lot's of problems arise because the underlying data is structured in a way that causes unnecessary problems along the way. Of course it's not always possible to change the underlying dataset, but maybe you can normalize it to avoid running into edge cases.

Sometimes filling optional parameters with empty values is all that it takes to reduce upcoming headaches. Or you just have to add a single additional parameter to simplify the codebase. 

So if it is a possibility in your project, take the time to think outside the function that you work on, and also try to consider tweaking your data to avoid edge cases.

**4. Start with a MVS**
Your MVS is the MVP for your problem. A "minimum viable solution". I just came up with that term, so don't start googling now.

Your MVS should just demonstrate that your fix or feature works. Think of it like a mini version of an MVP. Intentionally skip edge cases and only focus on the meat of the problem.

For example, in the coding problem that I faced, the recursive functions called a chain of 10 other functions. To begin with, I started commenting out all of that and only focused on the core functionality. From there I slowly added more logic as I proceeded.

**5. Ignore everything you know about clean code**

<img src="https://media.giphy.com/media/Kdgb5zBjJtVRLW2sV8/giphy.gif"/>

Ditch everything that you learned about how to write clean code. Move fast and break things. Did you repeat some logic along the way three times? Good. Is your function starting to approach 300 lines? It's fine! 

You can clean up all of that later. Focus on the essence of the problem. The 80% that matter instead of procrastinating by thinking about how to group your functions in a logical way or debating about how to call your variable names.

**6. Abstraction is your Enemy**
Your problem is complex enough. Don't start to introduce additional complexity through abstract classes or factory design patterns... Sure sometimes that stuff is beneficial, but the priority here is simplicity first. Don't abstract anything unless you really have to!

**7. Don't forget to clean up**
While some of these principles might help you to quickly find a solution to your problem they might leave you with a little mess. That's why it's important to clean up afterwards. Make sure to think about your coworkers and ideally leave the code in a way that others won't face the struggles that you had. Thoroughly test everything and leave some notes of your findings.


## Summary
Working on a complex problem can be frustrating but at the same time very rewarding if you manage to power through it. Hope you found these tips helpful and I'm looking forward to hearing your tips on how to deal with complex coding problems? 

> Side note: If you need professional support on a Vue/ Nuxt project reach out to me on [https://nuxt.wimadev.de](https://nuxt.wimadev.de?utm_source=complex-coding-problems)