A software bug is an error, flaw, failure or fault in a computer program or system that causes it to produce an incorrect or unexpected result, or to behave in unintended ways. A bug fix is a change to a system or program to handle a programming bug.
Bugs are unavoidable because programmers are human; all we can do is try our best to prevent them, react quickly when a bug occurs, (hopefully) learn from our mistakes and stay up to date.
Zero bugs is impossible for a non-trivial program.
A bug can be fixed only when you find out what it is.
The first thing to do when the bug occurs is to find out if it actually is a bug ?
If it is a bug, try and reproduce it to find out which of the following categories it falls into.
- Always Reproducible.
- Always Reproducible on specific platform/environment.
- Randomly occurs without anyway of reproducing it.
Bugs which are Always Reproducible are the ones that can be easily investigated. There are modern debugging tools available with almost all IDEs, which is really useful in helping you find out where exactly is the issue occurring. (Example Instruments on OS X ,winDbg on windows) .
There are crashing issues that can occur due to Zombies, NULL pointers , Divide by Zero, Invalid pointers.( Some Debuggers can provide detailed crash logs) .
If there are app freezing issues, it’s a good idea to look in to see if the application has blocked the UI thread, or if there is deadlock or some database issue (heavy transactions). Once the issue is known, the solution to the bug can be found out. Fixing these issues won’t necessarily be an easy task, though – it all depends on what the problem is.
Always Reproducible on specific platform or environment
Bug fixing gets a little trickier when it behaves differently for different platforms or environments.
Ideally, comparing the working version of the software to the non-working can give some hint to the source of the bug.
It can be helpful looking at the following items in your code to see if any of them are popping up in your case.
- Some old code being deprecated on the new versions.
- Some new code not being supported on older versions
- 32bit – 64bit variables issues.
- Race condition due to different operating system speeds.
- Running out of memory due to heavy allocations.
- Permissions issue.
- It can be Heineken bug that occur only on the release version of the app and not on debug. Details of this kind of issue can be looked into at https://en.wikipedia.org/wiki/Heisenbug.
Debugging the code on the platform/environment where it fails can point you in the right direction, too.
Randomly occurs without any way of reproducing it
These bugs are very difficult to fix because there is no proper pattern to reproduce these issues.
Doing the following might help to find out where the issue lies:
- Adding lots of logging to the code which is suspected to fail. It can give away some hint of what is happening.
- Take screenshots of a series of operations that you perform while testing . It might help looking back at those screenshots when the app fails, exhibiting the bug.
- Review the code with a group of people for suspected faulty code, with the aim of fixing theoretical issues.
- Advanced tools like live recorder can be used to live record the bug and reproduce it.
There is not much you can do in the face of these kind of issues. Fixing them also needs thorough testing to make sure the solution has actually stuck. It might be the case that you haven’t actually fixed the issue at all, and it just happened not to be reproducible in that particular testing run.
Try Preventing Bugs
No matter how talented the development team is, bugs are inevitable in every software coding effort.There are a few things that can be done during software development to help create a robust software;
- Follow a software development process to make sure you develop the right system, and also develop the system right!
- Follow a standard design pattern (like MVC ,HMVC, MVA ,MVP..) that best fits your Software/Program.
- Target zero warning software. (Sometimes warnings turn into bugs)
- Use Automated testing.
- Writing unit tests.
- If available for your platform, use Code Analysing tools that points out leaks, allocations, invalid pointers and many such errors within the code.(Analyse in Xcode)
- Use profiling tools to look in memory pool, CPU usage and other diagnostic information of your software (Instruments in Xcode)