In this post, through a real-world scenario, you'll briefly learn how I - as a Senior Software Developer - think when debugging issues in systems or applications.
The art of problem-solving
My good friend is currently having an issue with his laptop keyboard. Whenever he types something, the browser inherently opens Edge with the default page. This drastically hampers his productivity especially given he’s studying for a master’s degree.
On researching, he isolated the issue to the F1 key, which is automatically pressed due to a hardware or software issue. Difficult to know exactly at this point.
I think this illustrates a good example of how we developers debug issues on our system.
Whenever we are trying to understand a problem, the best way is to isolate it in the most efficient way possible. We can do this by asking questions to further probe down the rabbit hole.
In his case, is this a hardware or software issue? How to determine this? It's important to know the source of the problem to avoid wasting time. For example, if this is a software problem, he might be able to solve it himself rather than going to the regional distributor to look into the problem. This will result in a loss of time and money especially if this issue is not covered under warranty or it has expired.
What he has tried?
He first checks if there’s a problem with the keyboard’s driver, which however doesn't indicate any error and is up to date. He uses a well-known brand with the best drivers freely available online. With the continuous prompt of updating his OS to the latest version (Windows 11 as of this writing - 29/03/2022), even after doing so, the problem is still present.
What about Safe mode?
This can also indicate that we’re having more of a hardware problem than software.
One way of quickly isolating this issue between hardware and software is by loading a Linux distribution such as Ubuntu using a configured pen drive. By doing so, this OS loads the drivers for the machine respectively. Since the drivers are freshly updated and different from the existing ones in Windows, if the problem persists, we can then assume that it's indeed a physical problem with the keyboard.
In the debugging world, this approach is known as Binary search. Here's a description:
A better approach is to explore the code using a divide-and-conquer approach, to quickly pin down the bug. For example, starting from a large piece of code, place a check halfway through the code. If the error doesn't show up at that point, it means the bug occurs in the second half; otherwise, it is in the first half. Thus, the code that needs inspection has been reduced to half. Repeating the process a few times will quickly lead to the actual problem.
Solution – Disable the F1 key using tools such as AHK
According to his research and experimentation over multiple days, he has come to the conclusion that it is his F1 key that has an issue and is triggered without actually pressing the button.
The real way to address this problem is to get his keyboard repaired, which though, as mentioned above can take a lot of time and may cost plenty of money if it's no longer under warranty. Moreover, he needs his laptop to complete his assignments within tough deadlines.
Another quick fix can use an external keyboard. Nevertheless, there's no default way on Windows to disable a particular key or the embedded keyboard itself. Therefore, this problem will continue to persist.
A much lower effort yet effective solution is to disable the key and remap it into another one if it's really needed.
Here's an example of disabling this button:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. F1::return
There are plenty of ways of debugging issues related to computer systems. As a software developer with almost a decade of having a professional programming background, I've experienced that the most efficient manner of resolving such problems is to quickly isolate them via a principle of divide and conquer (Binary Search). Then solve this one issue.
The aim of this post is only a glance into the debugging world. In the references section below, you can read more about techniques such as Backtracking and the use of debuggers over print statements.