Skip to main content

Top Skills to Master in the Age of AI

AI is finding it's way in  a wide variety of applications pertaining to  almost every industry. This AI driven rapidly evolving landscape has created a demand for a unique blend of technical, creative, and interpersonal skills highly sought-after by employers. Listed below are some specialized AI-related skills that are becoming increasingly valuable in the modern times. 1. AI Models Development Understanding how AI and ML work including the underlying algorithms, and learning to develop ML powered apps using tools like TensorFlow or PyTorch is a highly desirable skill to master in the age of AI. Furthermore, the skills in fine-tuning and adapting large pre-trained models (like GPT, BERT, or Vision Transformers) to specific use cases are also useful, allowing you to create specialized applications without starting from scratch. Leveraging pre-trained models and adapting them to new tasks with limited data is particularly useful in NLP and computer vision. 2. AI Models Deployme...

How to Debug Your Code Properly Step-by-Step

How to Debug Your Code Properly Step-by-Step

From smartphones to spacecrafts, there is no machine in the world powered by a software program which is guaranteed to be bug free. You can try to minimize the chances of occurrence by adopting good programming practices, but you cannot guarantee absence of bugs in your code. Living with the fact that bugs will eventually come your way any time during the lifecycle of software product, software debugging becomes an essential skill to master. Especially for huge and complex software programs, identifying the cause of the bug is a daunting and challenging task. Furthermore, it is critical to speed up the debugging process, so that the time to market is reduced for the product. Although, researchers have explored and presented plenty of tools and techniques to assist in identifying and fixing bugs, software debugging can be simplified by following some general principles without the use of any tools. This blog post will specify the general procedure on how to debug your code properly step-by-step.

“The only certainties in life are death, taxes and bugs in code.”

STEP # 1 - COLLECT AND REVIEW BUG REPORT

The first thing you need to do is to collect and review the bug report. Since the bug may surface any time during software lifecycle, the bug report may be a general user feedback or a professional report from a tester entered in some bug tracking software. The bug report typically includes bug id  (for traceability), title, description, steps to reproduce the bug, environment and file attachments including stack traces, logs or screenshots.

Bug Report Example
Example Bug Report

To understand the problem and eventually solve it, it is very important to collect and review all the data you can possibly gather. If the bug is reported by users in their feedback or reviews, carefully classify and analyze all the reviews pointing to the same problem, as the reviews can be very general and misleading. Stack traces may look scary to interpret, but they usually contain all the information down to the root cause. If the stack trace is available, try to understand each and every bit of it by working backwards from the last line. To interpret the stack trace, you should know everything about your code including any error codes, exceptions or the libraries used.

Stack Trace Example
Example of Stack Trace

STEP # 2 - REPRODUCE THE BUG

Once you have all the available data explaining the bug, try to reproduce the bug by executing the software under same scenario and input conditions. If you cannot reproduce the bug, seek more data or help from the tester who reported it, or additional user reports pointing to the same bug. It is possible that your maybe missing something and you are not able to reproduce the bug because you may not be executing the same specific scenario. It is also possible that the exact same scenario cannot be reproduced on developer workstation using emulator / simulator and it can only be executed in user environment using actual device. Remember, if you cannot reproduce a bug, you cannot fix it. After all the efforts and executing all the steps, if you cannot reproduce the bug, close the bug report mentioning the details and steps you have carried out.

Developer May Get Frustrated if Bug is not Reproduced
Developers May Get Frustrated if Bug is not Reproduced

The bugs in your code may cause a software to crash with some exception, or produce an erroneous output. If the bug causes the software to terminate abnormally or generate an exception for some obvious inputs, it may be easy to reproduce. However, many bugs lay dormant in untested pieces of code, which only surface when the software is executed under complex scenarios and input conditions. Therefore, it is really a daunting task to reproduce the bug by executing the software under exact same scenario.     

"Don't fix it if it ain't broke."

STEP # 3 - WRITE A TEST CASE TO TRIGGER THE BUG

After you have reproduced the bug, write a unit or system level test case which triggers the bug, if such a test does not exist already. This will speed up the debugging and bug fixing process since you will not need to execute the scenario again and again to test your fix.

STEP # 4 - CREATE NEW VCS BRANCH

After you have reproduced the bug and before starting to make any changes in your code, it is very important to create a new branch in your Version Control System (VCS) for the bug fix, so that your changes do not break the already working functionality. Each bug fix should be carried out in a separate branch in order to maintain a readable history as well as for reverting to previous versions later if required. Remember to use meaningful branch name explaining the specific bug fix in order to distinguish it from other branches. 

Create a New VCS Branch for Bug Fix

Create a New VCS Branch for Bug Fix

STEP # 5 - REVIEW THE SOURCE CODE

After you have reproduced the problem, you must have identified the piece of code to search for the bug. As a first step in finding the bug, statically scan and analyze your code line by line. This will speed up the debugging process as you may find the bug without dynamically running the program in debug mode. During this step, you can also request another developer to assist you and pair program your way out of it.

STEP # 6 - USE PRINT DEBUGGING

If the static code review was not helpful, use the logging framework to print the state of your program at various points in your code. One major advantage of printing to console is that the developer can see the flow of the values in one go, without having to click through steps using the debugger. There are plenty of logging frameworks and libraries for different programming languages and domains.

Example of Printing to Console in Android
Example of Printing to Console in Android

STEP # 7 - ANALYZE CODE WITH A DEBUGGER

Sometimes the bug lays dormant in the software program, which is only triggered once the complex execution path is reached. In that case, it is difficult to find the bug by static review or sequential print statements. It can only be found by executing the program in debug mode and carefully examining the state by pausing the execution at various points. To analyze your code using a debugger: run your program with a debugger attached, enter breakpoints at some places in your code to pause execution and review the code chunks, step through your code line by line or chunk by chunk. The debuggers are typically included in the Integrated Development Environments (IDEs) you may be using for your project.

GNU Debugger (GDB) Basic Commands

STEP # 8 - MAKE CHANGES IN CODE

Now its the time to modify the source code to fix the bug already identified in previous steps. You should spend enough time in fixing the bug, and make all the required changes so that you do not leave any incomplete work, which comes back to you again.

STEP # 9 - TEST THE FIX

After implementing the fix, test if the bug has been fixed. Run the same test case you wrote to reproduce the bug and see if the test is passed.

STEP # 10 - CARRY OUT REGRESSION TEST

A bug fix may induce regression errors and new bugs in the source code. To test if the bug fix has created any side-effects, carry out the complete regression test of the software.

STEP # 11 - CLOSE THE BUG REPORT

Once the bug has been fixed, close the bug report by mentioning all the details.

STEP # 12 - COMMIT AND MERGE

Finally, commit your changes and merge the branch to the master branch. Remember to enter a meaningful commit message explaining the changes in code to fix the bug along with the bug tracking id for traceability.

A Template of Good Commit Message
A Template of Good Commit Message

Comments