Do programmers memorize every function in the languages they work with? Is their knowledge sufficient to code effectively in their specialized languages under all circumstances? And what happens when a programmer switches to a new programming language? Do they memorize everything?
In the technology age, where libraries are constantly updated, requirements change, and entirely new languages emerge, it is not always possible for a modern programmer to keep track of all these changes and independently produce effective code in every required circumstances. Thatâs why universities teach us, engineering students, not to rely on ready-made functions or code but to do researches. Itâs great; we can code correctly and efficiently by researching, but when we search something in the internet, it takes serious time to find out up-to-date, effective, and correct solutions inside numerous, maybe even hundreds of solutions. Moreover, we may not even notice the mistakes we made as long as the code runs.
In such situations, we need something to guide us. We can definitely say that nowadays, the most significant guide for a modern programmer is artificial intelligence. In this article, we will discuss the machine learning powered real time code generator: Amazon Code Whisperer.
CodeWhisperer, released by Amazon in April 2023, is designed to serve as a powerful tool for software developers. Its primary purpose is to suggest real-time single-line or fully functional code snippets based on the written code and comments, significantly accelerating the software development process and resulting in relatively qualified code.
CodeWhisperer relies on large language models (LLMs) trained on billions of lines of code, including both Amazonâs proprietary code and various open-source projects. This rich data pool enables it to offer well informed recommendations, and if the suggested code snippets are linked to open source projects or has similarities with code segments from those projects, relevant information such as the repositoryâs URL, the file path reference, and the projectâs licensing details are presented. Additionally, CodeWhisperer is able to scan the written code, swiftly identify, and highlight potential security issues, ensuring developers can work with confidence.
CodeWhisperer is free for individual users, while it provides membership to organizations through a monthly per-user subscription method. With organization membership, users can receive code suggestions based on training data consisting of selected open source projects.
Currently, CodeWhisperer supported by some popular IDEs such as JetBrains, Visual Studio Code, AWS Cloud9, and AWS Lambda console. CodeWhisperer supports a wide range of programming languages, including Python, Java, JavaScript, TypeScript, C#, Rust, Go, Ruby, Scala, Kotlin, PHP, C, C++, Shell Scripting, and SQL. In Visual Studio Code and JetBrains IDEs, both code generation and security scanning are available for Python, Java, and JavaScript languages.
First Impression
Below, you will find some simple examples related to the coding process with CodeWhisperer. Before diving into the examples, you can check the user actionsâ shortcuts. When preparing my examples, I preferred writing some basic Java code using IntelliJ Idea. If you are also using IntelliJ Idea, you can watch the installation video.
AWS Toolkit keyboard shortcuts for JetBrains and Visual StudioCode:
For JupyterLab and more you might want to check the documentary.
Single Line Suggestions
In this example, I wrote a Java code snippet where I defined two integer variables named âaâ and âbâ. Additionally, I included a comment line indicating the task: âMultiply a and b then print the resultâ
It is important to note that the tool provided this particular suggestion as the second recommendation. The recommended line was âSystem.out.println(a*b);â, which effectively prints the product of âaâ and âbâ on the console.
Whole Function Suggestion
In the example below, you can see that CodeWhisperer suggested a whole function that implements the BubbleSort algorithm based on the comment line.
Line by Line Suggestion
In some cases, it may not be possible to present an entire function within a single suggestion. Instead, as shown in the example below, progressive recommendations can be made, and ask the user for their approval when necessary.
- Reversing a string:
After accepting one of the listed suggestions, the cursor moves to the next line, and CodeWhisperer suggests different code approaches to reverse a string.
To put CodeWhispererâs suggestions to the test, I have accepted one of the listed recommendations. Below, you will find the main function and the relevant code suggestions offered by CodeWhisperer.
Letâs see how these suggested approaches perform in action.
Docstring Based Suggestions
CodeWhisperer goes beyond simple suggestions and also provides us DocString based recommendations. To explore this feature, I will attempt to implement the âreverse()â function in a new file within a separate class.
I have created a new class named âStringReverser.â The basic docstring structure will be as follows.
After completing the docstring, CodeWhisperer suggested a function signature.
Iâve accepted this suggestion to go forward and see the function body suggestion.
Result of the âreverse()â function execution using StringReverser class:
- Palindrome Number Checking Example:
For you, in addition to the string reverser example, I wanted to seek CodeWhispererâs insight on the Palindrome number detection problem, one of the common problems in Jr. Developer interviews.
Firstly, I created a new class named PalindromeChecker and defined a docsting within this class. Then, Iâve selected the 3rd suggestion using the right arrow key.
I wasnât satisfied with the initial suggestion, so I modified the docstring and made a specific request for a function that determines whether the input string is a palindrome, utilizing the previously defined StringReverser class and returning âYESâ or âNOâ accordingly. As a result, CodeWhisperer adjusted its suggestions to align with the updated docstring.
Since the first suggestion satisfies my requirements, I accepted it. Here are two test cases and the results of our newly implemented function.
I tried to share my first experience with CodeWhisperer with you. It is exciting to see artificial intelligence technologies supporting us in the coding process. However, I felt uncomfortable with constant suggestions appearing while coding. Therefore, I believe it would be better to run CodeWhisperer only when it needed. Additionally, I donât think such a technology is suitable for students as an normal person constantly receiving suggestions might not want to reject them and learn through their own efforts.
Bonus: Data Collection Preferences
- Telemetry Metrics Permission
- From side bar, right click ol âAWS Toolkitâ button
2. From the menu select âShow AWS Settingsâ .
3. You can change your preferences about your usage metrics by unchecking the checkbox that shown below.
- Managing Your Content Sharing Preferences in CodeWhisperer
4. Expand the AWS option located in the settings screenâs right panel and click on the CodeWhisperer option.
5. Then uncheck the âShare CodeWhisperer content with AWSâ option and save your preferences by clicking âApplyâ button.
REFERENCES
2.) User Guide PDF
3.) Amazon CodeWhisperer Features
5.) Amazon CodeWhisperer Pricing
6.) Amazon CodeWhisperer Workshop
Author: Elif Nur AFĹAR
Thanks to Mehmet GĂźr for providing me with the required environment to test my cases.
Contact for suggestions and complaints: tobb.yapayzeka.kulubu@gmail.com