Posted on Leave a comment

Debug code better, faster and with fewer headaches

Every time you change code, there’s a very good chance that you will have introduced bugs to your existing code. IT’s important to take a methodical approach to squishing these bugs, or you may waste a lot of time hunting down the cause of specific problems. Here are 7 tips to debugging your code faster.

debugging php javascript c++ java

  1. Don’t pretend that this isn’t your fault (or your teams fault). You wrote the code and you made a mistake. Don’t beat yourself up over it, but don’t blame the computer for your mistake. By that same token, dont’ beat yourself up over a bug. Bugs will always¬†happen, just solve it and move on.
  2. Treat every error as an opportunity to learn about yourself. If you think of bugs as a puzzle or mystery to be solved, you won’t find yourself burning out as fast and this will encourage a more patient and relaxed approach to solving errors.
  3. Write tests. Testing is not only great at preventing bugs but also helps a lot in debugging. Testing forces your design to be more or less modular, which makes isolating and replicating problems simpler. The tighter control this provides over the environment will cause fewer surprises. Moreover, once you get a failing test case, you can be reasonably sure that you’ve caught the real reason of the code’s behaviour..
  4. Use a debugger! Don’t avoid stepping through your code with a debugger just because it’s time consuming. Checking every line of your logic will often help you to find better ways to do things and highlight the real cause of errors. I personally really like the built in debuggers in both Netbeans and PHPStorm
  5. Talk about someone about your problem, even if it’s just a rubber duck (I personally use my android figurines from Android TO). Forcing yourself to express the problem you are working on in words really does miracles.
  6. Give yourself a time limit. If for example after 45 minutes you feel you are going nowhere, just switch to other tasks for some time. When you get back to your bug, you’ll hopefully be able to see other possible solutions that you wouldn’t have have considered before.
  7. If you have narrowed it down to two systems that collaborate (for example a PHP back-end and a JavaScript front-end), inspect the messages between the two systems via traffic monitor or log files, and determine which system is behaving correctly and which one is not. If there are more than two systems in the scenario, you can perform pairwise checks and work your way “down” the application stack.

As you can see, debugging code isn’t always an exact science,but by applying the right mindset and techniques, you can speed up the process significantly. Fast debugging isn’t always

Related reading:
Why Programs Fail
The Pragmatic Programmer
Software Entrophy

Posted on Leave a comment

Let There Be LIFE In JavaScript

screenshot - javascript life simulator

screenshot - javascript life simulator

Can you create life in JavaScript?

My new project, LIFE, is a simple javascript life simulator in which each digital citizen moves randomly, socializes, ages and breeds to replace citizens that die up to a maximum of 50 live citizens at a time. There is a limit of 50 citizens to avoid crashing the browser. Each citizen starts as a newborn and grows to adulthood. Citizens turn orange while socializing. When the citizens reach breeding age, there is a chance that socializing will result in a new citizen being born and added to the top of the pile. when citizens leave breeding age, they turn grey. When citizens die they turn black, stop moving and decompose until they are removed from the stack.

check it out here