DEV Community

Cover image for Enhance Your Code: CodiumAI’s Automated Analysis and Suggestions for Python and JavaScript
Tom Smykowski
Tom Smykowski

Posted on

Enhance Your Code: CodiumAI’s Automated Analysis and Suggestions for Python and JavaScript

Image description

Writing code tests plays a vital role in software development, guaranteeing high-quality code, early bug detection, and enhanced maintainability. Yet, this process often becomes a time-consuming and monotonous endeavor.

Developers frequently find themselves allocating considerable time to writing tests, diverting their attention from actual development. Fortunately, the progress in artificial intelligence (AI) has opened doors to automated test generation, presenting developers with an innovative method for creating code tests. One such tool is CodiumAI, which allows you to automatically generate tests for your code.

With CodiumAI, you receive meaningful and straightforward test suggestions directly within your integrated development environment (IDE), enabling you to write better code. Let’s see how we can use CodiumAI on VSCode and PyCharm.

I will be keeping it simple and will only focus on how CodiumAI can be used to do an analysis of the code and also get suggestions.

How to Use CodiumAI to Generate Tests for Python

Let’s take a simple Python code to better understand how code analysis could be done using CodiumAI. The following function, ‘largest_prime_factor’ takes a number and tells the largest prime factor for that number.

Image description

For some people, this code could be difficult to understand. Along with that, this code is also not well-optimized. Let’s check out the analysis of the CodiumAI regarding our Python code.

Click on the ‘Generate tests for the below function’, to pop up the CodiumAI window. Once the CodiumAI tabs show up, click on the ‘Code Analysis’ tab.

Image description

As the name suggests, the analysis tab provides a detailed analysis of the code. This covers objectives, inputs, flow, outputs, and a few additional aspects. Almost anyone can easily understand the code by just simply going through the analysis. This makes it easier for other programmers to understand the code and also contribute to it.

You can also improve your code with AI-generated suggestions. For suggestions, click on the ‘Code Suggestions’ tab to get suggestions from the CodiumAI.

Image description

Under the ‘Code Suggestions’ tab, you will see multiple suggestions. Each suggestion contains two things, first the actual suggestion, and second, how your code will be affected by following the suggestion.

Following are the few suggestions given by CodiumAI regarding our Python code.

Image description

Image description

Image description

To apply the suggestion, just click on the checkbox on the top left of each suggestion. After checking the box, click on the ‘Prepare Code Changes’ button at the bottom right of the window. You can also select all the suggestions by clicking on ‘Select All’, which is present at the bottom left of the window.

Image description

Once you click on ‘Prepare Code Changes’ you will see a new window with the previous code along with the suggested changes for a better comparison. You can also see the list of suggestions that are being applied to the code.

Image description

After that click on ‘Apply to my Code’ to apply the changes. Right after clicking, your code will magically change into a well-optimized, functional code. Just a few clicks, it’s that simple.

Image description

How to Use CodiumAI to Generate Tests for JavaScript

We have seen how we can get detailed suggestions for our Python code. Now let’s see how we can do the same with JavaScript.

I have taken an easy and basic example of a Fibonacci series generator in JavaScript. The following function generates n number of terms in Fibonacci Series.

Image description

Is our code perfect? I mean it does the job but is it really perfect? Let’s see what CodiumAI thinks about this.

Click on the ‘Generate tests for the below function’, to pop up the CoidumAI window. Once the CodiumAI tabs show up, click on the ‘Code Analysis’ tab.

Image description

Once you click on it, a detailed analysis of the code is displayed. The analysis includes objectives, inputs, flow, outputs, and some additional aspects. As you can see in the screenshot, this is a pretty detailed analysis of such a small function that we wrote. Anyone can understand the code immediately by just going through the analysis. This might not look much helpful in this example that we are using, but this is very helpful once you are writing complex code. This makes it easier for others to understand your code.

This is the analysis part. The best thing is that we can get code suggestions for JavaScript too.

Click on the ‘Code Suggestions’ tab and you will be presented with some suggestions. The process is similar to what we followed for Python.

Image description

Under the ‘Code Suggestions’ tab, you will see multiple suggestions. Each suggestion contains two things, first the actual suggestion, and second, how your code will be affected by following the suggestion.

Following are the few suggestions given by CodiumAI regarding our JavaScript code.

Image description

To apply the suggestion, just click on the checkbox on the top left of each suggestion. After checking the box, click on the ‘Prepare Code Changes’ button at the bottom right of the window. You can also select all the suggestions by clicking on ‘Select All’, which is present at the bottom left of the window.

Image description

Once you click on ‘Prepare Code Changes’ you will see a new window with the previous code along with the suggested changes for a better comparison. You can also see the list of suggestions that are being applied to the code.

Image description

After that click on ‘Apply to my Code’ to apply the changes. This will convert your code into a well-optimized, readable code. I bet you haven’t seen an easier method of code refactoring than this!

Image description

As you can see CodiumAI is quite nice if it comes to code analysis and suggestions too. I found this feature by accident, and already using it often. Do you use any AI tools to improve your coding? Let me know about it, and what do you think about CodiumAI!

Subscribe for more coding articles and tools!

Top comments (2)

Collapse
 
coditamar profile image
Itamar Friedman

Thank you @tomaszs2 !

Where do you think CodiumAI could improve the most?

The magic wand question - what capability or feature would you like to see that would help you the most?

Collapse
 
tomaszs2 profile image
Tom Smykowski

Thanks for asking. As for now I'm pretty satisfied 🙂