3 Minutes with Kent

How to solve programming problems

03.06.2021 - By Kent C. DoddsPlay

Download our free app to listen on your phone

Download on the App StoreGet it on Google Play

Hey friends so today is office hour stay and I am answered a question on

office hours that I thought I'd share with you and it's from Salem and the

question was hey can't can you walk us through the process for when you get

stuck on a problem and what I do is I try to find where the problem is.

I don't try to just do a bunch of random things and hope that one of them

works or the solves a bug or whatever because what can happen is, you can

implement the wrong solution in the right place and and move the problem

andSo that you like you haven't actually saw the problem you just moved it

somewhere else and now you think that you've solved the problem but you're

gonna hear about this in the future and or like you might implement

something wrong and and somebody else can create this problem all over

again, so you need to understand why the problem exists as well as how you

can avoid it in the future and then it can actually help to have a test in

place to make sure that the problem doesn't show up again, so one thing

that can be helpful is to write a test that that reproduces the problem

first because that way like,You just have a much better iteration cycle on

did I fix it no or yes or whatever but another really critical piece of

this is to isolate that problem so remove as much as you can and the best

way to do this is to reproduce it in a small isolated example, so try to

take it outside of your app just install the dependencies that you know,

you need or whatever bring in the code that you know, you need and

reproduce it in that small example sometimes that's possible sometimes it's

not but that's the best possible thing.

That you can do is to just remove as much as you can in a completely

isolated example sometimes it's a very difficult so if you can't then the

next best thing is to take your existing app where you're experiencing the

problem and remove pieces of code until ultimately eventually you'll wind

up with nothing on the page except the component that's giving you the

headache or whatever the case may be or you're running only a single file

on node that is causing the problem and and that can help you isolate the

problem sometimes that's difficult and so especially when you're talking

about like async stuff rate.

Conditions or whatever console logs can be really helpful in in those

situations but yeah really finding where the problem is and if it's a

regression then finding which commit caused the regression can also be

quite helpful so doing a get bisect whether using the command or just doing

it kind of by hand can also be really helpful in isolating the problem, so

hopefully all that is helpful good luck to you in dealing with these types

of problems, it's no fun, but I know you can do it have a great day.

More episodes from 3 Minutes with Kent