Now let me spit some facts here, We all have written that console.log("aefasfaad", data)
line in our code to check what that data variable contains! π
Some people even go one step further by adding this line in multiple places to track the value. That gibberish string will never get old and I have seen that in many codebases even in production. There will always be one ticket/story to disable the console in production! π
Debugging is the most fun activity when you are dealing with your code and you know what you are doing, debugging other peoples code is a nightmare. Even there, a well-written code will be easier to debug than a poorly written code. I learned programming by debugging my code (Truth! π‘). Like most of the programmers out there, I have spent more time debugging than programming.
Debugging can be fun if it is done right and here are some tips and common mistakes people make when they are debugging:
Not reading the error message: Come on, we all have to admit this. Whenever we see a red-colored line on our console, we immediately send a screenshot of that error to our colleague or senior and say I am getting this error, or copy-paste the error into Google and read the series of stack overflow answers, without even reading the error message. I have to admit it but yes, I have been there and it sucks when you realize that you were like that back in the day. We dont care to read the error message in the first place, the mentality of just writing the code and expecting it to work is a fairy tale when it comes to programming. I have seen my juniors sending me screenshots of their errors which will say, Cannot read property of undefined (reading forEach). My immediate response would be, Please read the error message. I am ready to help you out but I dont wanna steal your opportunity to learn something. Here the error message clearly says that you are trying to access something out of
undefined
. The worst part is even people who are senior to me have done the same and I have had awkward moments where I wanted to say this statement but I couldnt. πUsing the debugger: This is an obvious tip, to debug you use a debugger, Duh! But only a few people use the debugger. The IDEs that we are using, even the browser have a very powerful and feature-rich debugger that allows us to track a variable, add breakpoints, and even have access to the call stack. So learning how to use the debugger is essential to increase your productivity as a developer and to look cool! π
Knowing what you are doing: This point may be a bit harsh but lots of people dont know what our code does! Having a command over the fundamentals, language, and framework will reduce the time of debugging significantly. If you have a good grasp on your tools, sometimes by just glancing over your code, you can find the bugs without any debugging activity which in my opinion is a superpower! I have seen people who identify themselves as copy-paste developers, I mean they just copy code from another file or Stack Overflow, rename the variables and try to achieve the functionality rather than coding the stuff from scratch. Dont get me wrong, Copy-pasting is great for productivity but it can be done only when you know your craft! π§ So try to spend more time getting better at the tools that you are working on and see the wonders! π
So thats it, guys! Those are the 3 points I wanted to discuss in this blog. All these points are something that I observed in my 3-year coding journey and giving them to you so that you can benefit in your career! πΌπ
Top comments (0)