Bug-free code. It sounds like an extremely ambitious goal or rather... a mission impossible, right?
Is that even possible? To write immaculate code? To get your backlog from swarming with bugs to storing just a few stubborn bugs to... being a zero-bug zone?
This goal is only as intimidating as you allow it to be...
Once you have an effective code review checklist at hand to rely on and you stick to it, this bug-free code challenge starts to turn from discouraging to... manageable.
So, here's an example of a well-constructed checklist to use for preventing silly mistakes and identifying bugs early:
But First: Why Would You Be Tempted to... Keep the Detected Bugs?
Do you dread the idea of clearing out your backlog... completely?
I can totally relate to that: there's valuable knowledge stored along with all those age-old bugs left lurking within. Knowledge that you could still leverage to upgrade your software product.
And to improve the customer experience...
Still, it's precisely those bugs that have a negative impact on the UX. So, coming up with a strategy for:
- removing all the dusty bugs collected in your app, “safely” stored in there a long time ago
- quickly detecting all the new coming ones as you continue to add on new features and upgrades
… remains a critical long-term strategy.
1. Check for Memory Leaks
And here are the most common signals that you've just found a leak that “drains” your app of its memory:
- dead threads, if your application is a multithreaded one
- maps referencing DOM that... no longer exist (JavaScript)
- an unmanaged resource that has been left...lingering (Java or C#)
Besides doing all the manual work to check your code for any leaks, feel free to use the diagnostic tools that your specific environment provides you with:
- the memory profiler in .NET
- the Developer Tools' memory tab in JavaScript
2. Test Your App in Every Environment that You're Deploying It
How does your own “ecosystem” of environments look like?
- a developer server?
- production/release/live environment
- local developer machine
- stagging and/or QA
Testing your app in every one of those environments where it's being deployed is a key and a constant step to take when you aim for bug-free code.
Note: this step goes from “key” to “critical” when a specific feature or update to your app depends on certain environment-specific elements (database schemas, configuration values, resources...)
Particularly in such cases, small neglects like... typos in one of the configuration values risk impacting your app's performance/UX.
3. Test It Against All Possible Edge Cases
In other words, find out just how much your app can take:
- overloads of values having null or empty values or being formatted in an unfamiliar manner
- multiple instances running simultaneously
- different elements of its UI being clicked on, really quickly
- a never-ending list, over-stuffed with items
- over-repetitive undo/redo operations: carry out an operation, then keep on undoing it and redoing it
Does your app withstand this “mistreatment”?
Note: if your combinations of inputs to be battle-tested is overwhelming, consider running unit tests.
4. Bug-Free Code: Look for Data Dependencies that Load Asynchronously
Do all those sets of data that your app depends on load... simultaneously?
If not, then we can't be talking about bug-free code. But we can surely be talking about your application risking to crush.
How do you check whether your data dependencies load at different times? You add a lag to one of the dependencies, by leveraging the “delay” mechanism provided by the language that your app uses:
- Thread.Sleep()in .NET
- setTimeout in JavaScript
- Delay operator RX
5. Are the References and Values Being Used Correctly?
Should a specific value get updated in most of the places or be used under different copies?
Or maybe you want it to be set in a specific place?
Are your references being used correctly in relation to their values? This should be one of the top 10 must-look-into aspects of your checklist...
6. Double Check All the Numeric Values (e.g. Currency Values)
Pay special attention to those elements of your app that operate with numbers while pursuing your “bug-free code” strategy.
Are the currency values used correctly? Are all the dates properly formatted?
7. Make Sure All the In-Built Accessibility Features Work Properly
Ensuring that your app's accessible is not just about implementing all the key features when building it.
It's about constantly auditing them, as well.
Therefore, grow a habit of testing them on a regular basis:
- how challenging is it for you to use it relying exclusively on a screen reader?
- what does the output of the Waveautomated testing tool indicate to you
- how effortlessly is it for you to use it... keyboard-only?
8. Simulate a Heavy Load of Records
Check how the system copes with... an unexpected “infusion” of lots and lots of items.
“Go wild” when testing your app and “injecting” up to... millions of records, just to see if it can withstand the overload.
9. Look for Code that Gets Executed too Often
Code that generates identical results with every iteration is not bug-free code.
Therefore, check whether unnecessary code operations are being executed with:
- every rendering cycle
- every game loop
- every template
Such unwanted operations lead to... unnecessary code getting piled up and to poor loading times for your app, obviously
10. Double Check If all the Requirements Are Met
Have you met all the initial requirements when building your application?
If not, are there suggestions that you overlooked? Or maybe ambiguities for which you haven't yet asked for further clarification?
Make sure all these blurry aspects get cleared up and the original requirements get either met as such or updated first.
The END!
This is how a well-constructed, effective code review checklist looks like. Pair it with a mindset focused on rigor, attention to detail, discipline and self-improvement and you'll get there.
You'll reach your bug-free code goal...