DEV Community


Posted on

5 things I do when I'm stuck coding

As somebody who learnt coding by copying and pasting snippets from anywhere on the internet, I get stuck quite a lot when working on projects as that's not exactly the best way to learn.

But after almost 2 years of coding, I've gotten better and along the way made a mental checklist of things to do when I hit a new pothole to get back on track. I don't know what expert coders with CS degrees do when they're stuck so this may not be the best list. But if it helps anyone else, here goes:

1. Check for missing brackets.

I used to code in an editor in which I couldn't see missing brackets until the app would crash and the error message would mention something about a missing curly brace. I've since shifted to VS code that does the job for me before I run the code. Atom also has some great plugins that help you.

2. Change the order

Sometimes it will make no sense at all, and sometimes it will make all the sense in the world. But oftentimes just moving some lines of code back and forth does the trick.

3. Add lots of console messages

I saw an article on Medium the other day about how you should never use console.log. I think that's ridiculous. I'm sure even the experts use them.

Add as much console.log messages as you can in the functions that is crashing. Fit it in between steps. Add variables to the messages to see what they are at each step before processing.

4. Search the error message

Sometimes it's not even your fault. Might be some bug in the package or framework you're using. A quick Google search will show somebody else in the same predicament and an Einstein or two that would have already solved it.

5. Understand the code

If all else fails I go back to the documentation and try and understand every bit of the code I'm running. It helps. I used to do this more often in the beginning when I was learning programming. Because it also helps give me more technical terms for the stuff I'm working with.

Putting that in Google gives better search results than what you'd get with a description of the crash.

I'd love to hear what everyone else does when they're stuck programming. Also, if you're interested in seeing where I invest my time coding, check out my site:

Top comments (6)

ghost profile image
Ghost • Edited

What works for me every time, is: taking a nap, walk a little, go to eat something; unplug for a while, sometimes pushing through only makes you angrier. You can take a 30min break or spend hours getting frustrated. After the break I usually figure the problem aout in a few minutes, sometimes faster than that. When you get frustrated you start blaming the computer, the compiler, you even start to think that the PL is wrong and you start trying to prove that the universe is wrong instead of figuring out the real problem, you stop paying attention of the compiler messages and you keep getting more emotional and less rational. Just take a break and when you come back, you'll figure it out.

Other thing to consider is when you code tired or angry you'll spend the next day fixing the stupid things you did while tired or angry. Is easy to fix code but there is no VCS for a protoboard :|

dana94 profile image
Dana Ottaviani

I've been using the debugger command almost as much as console.log now. It helps to see if your code is running what you expect it to, or if it considers a conditional result to be true when it actually results in false.

bbessa profile image
Bernardo Bessa

Focusing on the bullets themselves, I'd say:

  1. Look for the development tools that suite your needs (e.g IDE). It is really cool to develop over notepads or basic text editors - it might shows how skilful you are -, but there are so many tools that can let you focus on the big problems. Don't let braces, commas or any basic language syntax consume too much of your time!

  2. Rethink about your problem solving approach. If you are changing the order of the lines on your code, you may are not understanding what problem you are really trying to solve. Design a solution can help you to implement it in a more understandable way.

  3. That is a major practical vs theoretical question: logging is not necessarily debugging. While logging is for definition a cross-cutting concern - which means it is a feature that is applied to all of your application, for a ton of different reasons e.g. communication between applications, error handling, auditing, debugging -, debugging is a method to test your application in runtime - which allows you a lot of features to control your test flows a lot better. Have a look on this blog post (focused on Javascript):

  4. and 5. You are definitely on the right path! First of all, any time you are stuck, it is fundamental to understand which kind of problem you have in front of you: business or technical. Do you really understand what you are developing? Or is it some technical issue that you are finding ahead (e.g algorithm effectiveness, data structure usage, data manipulation, etc.)?

To finish, I'd like to introduce you a concept that I've studied a few months ago and it was really eye-opening about being stuck: Strategic Procrastination. Take a look (it is quite contextualised on software design, but the concept is clearly explained):

smil3cz profile image
Jan Melicherik

My best advice is switch your brain focus to another non-it topic. Dont force yourself to solve everything right now.

I really recommend you to find some artiles how your brain works because it helps you to get a knowledge how to build right aprroach to learning code.

Cross my fingers

epszaw profile image
Konstantin Epishev

When I have really stuck โ€“ I just go out from the computer. "Brain switching" is the most powerful thing for solving there kind of problems.
The most of my greatest ideas reached me when I have washed dishes, for example, or during walking with my dog ๐Ÿคทโ€โ™€๏ธ

jaypatelbond profile image
Jay Patel • Edited

Thanks for the guideline. Its really helpful. Actually I will try the 3rd and 5th points. ๐Ÿ˜ƒ