Debugging Tips which helps me a lot 👇

code newbies, my most common tips for beginners who feel stuck when your code is giving errors or isn’t doing what you want it to do.

Let's decode this in this đź§µThread đź§µ

#100DaysOfCode
Print (console logs ) a lot ✍

-Every single line of code, you should have a sense of what all of the values of the variables are.
If you’re not sure, print them out!

Then when you run your program, you can look at the console.
Start with code that already works ✍

When in doubt, start with someone else’s existing code that already works.

If you’re a beginner, you’re still in the learning phase, and so it’s better to start with an existing structure and tweak it to meet your needs.
Run your code every time you make a small change ✍

Do not start with a blank file, sit down & code for an hour, and then run your code for the first time.

You’ll be endlessly confused with all of the little errors you may have created that are now stacked on top of each other
It’ll take you forever to peel back all the layers and figure out what is going on.

Instead, you should be running any changes or web page updates every few minutes – it’s really not possible to test and run your code too often.
Read the error message (Your best friend) ✍

It’s really easy to throw your hands up and say “my code has an error” and feel lost when you see a stack trace.

But in my experience, about 2/3rds of error messages you’ll see are fairly accurate and descriptive.
The error message does its best to tell you what went wrong. At the very least, it will tell you what line number it got to in your program before crashing, which gives you a great clue for places to start hunting for bugs.

Don't run away from error message, they are real friend
Google the error message ✍

If you can’t seem to figure out what your error message is trying to tell you, your best bet is to copy and paste the last line of the stack trace into Google.
Comment-out code ✍

Every programming language has a concept of a comment, which is a way for developers to leave notes in the code, without the language runtime trying to execute the notes as programming instructions.
Take a break and walk away from the keyboard ✍

It’s really easy to get caught up in the details of your current implementation.

You get bogged down in little details and start to lose sight of the forest through the trees.
In cases where I feel like I’ve been spinning my wheels for the last 20 or 30 minutes, I try to step away from the code and do some other activity for a little while before coming back. I’ll go get a drink of water, meander around a bit or have a snack. It’s a great way to reset
How to ask for help (Most Important) ✍

Final Stage so you’ve really tried everything and it seems like nothing is working.

Now you feel like you’re really ready to ask someone else for help.
Before asking anyone help, it’s important that you make sure you have all of the following components of an excellent question 👇

-Explain what you’re trying to do
-Show the code that’s giving the error
-Show the entire stack trace including the error message
Hopefully, that’s helpful to you all who is new to programming or getting started with their first coding projects.

Share your love in comments. 👇
You can follow @TheAnkurTyagi.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.