Bugs & Debugging

Hi! Programming is an activity I engage in a lot, and it felt weird not having written any blogpost about it before. I therefore wrote this one. It’s probably quite cheesy, and there are a lot of “obvious facts” in it, but I just had to try, for a first at least. I hope you like it, enjoy!
____________________________________________________________________________ _________

image

Debugging (for those who dunno) is the process of removing removing bugs (which are basically flaws) present in your code. It’s something we all as programmers have to and eventually get used to (or just quit), at least until maybe we create “Artificial Intelligence” Programming languages that would detect and correct errors both syntactic and semantic (we’ll get to that) by its self during compile time (that would be cool eh?). Anyways it’s simply impossible to write meaningful code without coming across annoying bugs, except you’re writing pretty elementary code. I know for one that debugging is one of the reasons people hate programming. Ironically it’s also the reason some like it…I think!

Bugs come in different shapes and sizes. There are 2 major classifications of them (though it’s actually 3 with the 3rd being Runtime bugs..i think), Syntax and Semantic Bugs. Syntax bugs are the obvious ones. The compiler tells you straight up that there’s a problem, probably because you “gbagaun- ed” in your code. Those ones are relatively easy to find and handle. The semantic bugs on the other hand are to me the real headache. It’s when you didn’t quite gbagaun, but still your code somehow isn’t making sense somewhere. It’s an error in meaning. Semantic bugs can be obvious too, when you test your code well with a wide range of scenarios, but some are also rather subtle, and you may not notice until much later when they put you in trouble. Most Software Engineers believe that you can never really locate the last bug in software anyway!For every beginner, debugging can be a truly arduous and frustrating activity. The littlest things, like not closing an opening brace can scatter your head for 30 minutes (if you’re not using an IDE), but after a while you gain experience, and you become moderately good. In my journey so far, here are a few things I have learnt about debugging that have improved my “debugging skill” to an extent:
i) Calm down: When you’re trying to fix code, it’s important not to panic. It’s also better when you’re not too stressed. This is because you need to focus and be level-headed. Whenever I’m debugging and I’m starting to feel stressed, I simply stop and chill a lil’. Forget about the deadline, what’s the point if you can’t think straight?? I’m sure it doesn’t apply to every programmer, but generally I think it’s better to be relaxed when debugging.

ii) Understand the problem: You can’t really solve your problem until you understand it now can ya? When you are a beginner, chances are sometimes you’ll just try different things hoping you’ll stumble on a solution and live happily ever after man and code! This is more common when you use code that isn’t yours. The “magic solution” may come, but you’ll end up not learning much from the bug. Ideally the first step anyone should take when handling a bug is understanding why the bug is there in the first place. What part of the code is behaving funny? Why is it behaving funny? Strive to answer these questions first and your problem is half solved (some people say sharing it does that too but who cares??)!!

iii) Be Patient: Debugging can be annoying (obviously), but you won’t get anywhere if you give up easily. The same applies to basically anything worth striving for in life. If you want to be a good programmer, you have to have perseverance and doggedness. Keep trying and eventually you should arrive at a solution.iv) Enjoy It: Sounds crazy hun?? But sometimes I think about it and I realize that programming might as well be boring without bugs!! Debugging really is a mentally stimulating activity! I know you can’t enjoy it all the time (especially when there are deadlines) but it’s nice to have fun when you’re trying to fix bad code. It’s like solving a puzzle or something.

v) Utilize the internet (and other resources well): Most times a person’s bugs won’t be one of a kind. Many people have probably had the same issues and have had more experienced people solve it for them. It’s usually all there, on the internet, for you to access (free of charge) and it’s definitely a good idea to access them!

So that’s all I can think of for now. I’m sure there are other useful tips but my brain is too small 😦 . Please feel free to add as many as you think should be on the list. Thank you for reading! 🙂

Advertisements