### re: How Do You Approach Your Coding Problems VIEW POST

The trick is to break it down into small steps.

Step 1: Understand the problem.
What is it exactly you're trying to accomplish?

In the example above, it's converting a temperature from celcius to farenheit.
There's a formula for that. Google time.

Step 2: Draw out what has to be done.

Literally, get a pen and paper and draw a picture or write down the steps.

This helps clarify your thinking and keeps you focused. Focus and clarity are two very important things when working through a problem.
Yeah, a rubber duck helps. ;-)

In this case,

• create a function
• get the celcius number input
• apply the conversion formula
• return the results.

As you're thinking it through, you realize you need to make sure it's a number, not a string to do the math etc.
Note that, but don't get caught up in these details yet.

Step 3: Start writing the code step by step you outlined.

Get a basic working model. Don't worry about the 'best way to code it' just get it done!

Write it so it works with simple inputs.

Now you have something that works!

Ok, now make your code more elegant. Clean up the var names, etc.

Test again.

Step 5: Idiot proof it.
What if it's a string instead of a number, or a null etc.
Lock it down.

I find this method works for problem solving. Break it down into small pieces, be clear about what you're accomplishing and take it step by step.

A lot of time, people keep telling beginners to break big problems into small ones and I'm already doing this. But what I am lacking is how to draw plans to solve problems. In other words, I have tactics, but no strategy.

Now that I'm aware how to approach problems, it's just a matter of being patience with time and be perseverance.

I would add one thing: as part of step 1, ask yourself "Do I really need to solve this problem?" There could be any number of reasons for the answer to be No. For example, sometimes the requirements may be wrong ("We don't actually need the temperature in Fahrenheit"). Other times someone else -- a colleague, a third-party library -- will have done the work for you.

I've been there -- wasting time and brain power on a problem that didn't need solving. It's painful.

Of course, if you're solving the problem just to learn or have fun ... well, completely disregard this part, and move on to Lisa's steps.

Fun is an important part of this, otherwise what's the point? ;-)
... mind you, sometimes you're having fun, you just don't know it yet.

True: check to see if the problem has been solved elsewhere, although beware of falling into a black hole of searching for and implementing solutions that would be easier to just code yourself.

Absolutely, there's a balance to be found. That black hole is a very real danger. Still, I tend to err on the side of not writing the code if I can avoid it ... which probably makes me lazy and/or lacking in curiosity.

Fun is an important part of this, otherwise what's the point? ;-)

So true!

code of conduct - report abuse