Build a smart bridge, Amazon CodeWhisperer helps you program easily

Zero: Preface

As time goes by, artificial intelligence technology is developing at an alarming rate and is setting off a new programming paradigm revolution. Not only limited to code generation, innovative applications such as intelligent programming assistants have further improved development efficiency and code quality, greatly promoting the rapid prosperity of the software development field.

There are more and more intelligent programming tools emerging on the market today, which are designed to help developers build applications more quickly and securely. Among them, Amazon Cloud Technology’s AI programming assistant Amazon CodeWhisperer stands out for its excellent performance, effectively improving developer productivity. With the introduction of this powerful tool, developers can create, design, and improve projects more efficiently and achieve impressive results. It builds a convenient bridge for developers, allowing them to use artificial intelligence technology more intelligently to accelerate innovation and optimize programming processes.

Today, let Brother Xu Zhu take you to learn about Amazon CodeWhisperer.

1. Amazon CodeWhisperer

1.1. Common pain points in development

  • Writing boilerplate code is a repetitive and tedious task during development
  • Syntax errors and issues can become bottlenecks when developers need to code in unfamiliar programming languages
  • Security vulnerabilities are a serious problem in software development, but are often difficult to detect and fix early
  • Typos and typical mistakes can cause code to not work properly or create potential problems, causing unnecessary trouble and debugging time for developers.

1.2. What is Amazon CodeWhisperer?

Amazon CodeWhisperer is a powerful intelligent programming assistant based on the experience of training billions of lines of code. With the help of its advanced algorithms and deep learning technology, CodeWhisperer can provide developers with various code suggestions with amazing accuracy and real-time performance.

1.3. Advantages

  • Get more work done faster : CodeWhisperer helps developers save a lot of time while coding by quickly generating accurate code suggestions. It can generate code suggestions in real time, from code snippets to full functions, and help developers build with unfamiliar APIs to increase work efficiency and productivity.
  • Code with confidence : CodeWhisperer can flag or filter code suggestions that are similar to open source training data and provide repository URLs and license information for relevant open source projects. This allows developers to easily view and add attributions, promoting code sharing and collaboration. Developers can use these coding suggestions to create high-quality software and can use them with confidence because they have been professionally trained and verified.
  • Enhanced code security : CodeWhisperer can scan for hard-to-find vulnerabilities and provide fixing suggestions. It follows security standards such as OWASP to help developers fix security vulnerabilities in a timely manner and improve software reliability and stability. CodeWhisperer can also check for possible vulnerabilities in the code and give corresponding warnings to help developers fix vulnerabilities and errors before release.
  • Improve developer work efficiency : CodeWhisperer can greatly improve developer work efficiency. According to the results of the Productivity Challenge, participants were 27% more likely to successfully complete tasks and completed tasks 57% faster on average when using CodeWhisperer. Development teams can spend less time creating boilerplate and repeating code patterns and more time building great software.
  • Supports multiple languages ​​and IDEs : CodeWhisperer supports nearly 15 programming languages, including Python, Java, JavaScript, C++, etc. It can be seamlessly integrated with popular IDEs (such as VS Code, IntelliJ IDEA) to provide developers with an efficient and convenient development experience. Developers can use their preferred environment to write their code and can also easily use CodeWhisperer in different projects.
  • Can be opened and closed at any time : CodeWhisperer can be opened and closed at any time. Developers can open it when needed and close it at any time when not needed. This allows developers to have more control over their workloads without having to worry about CodeWhisperer causing other issues.
  • Free to use : CodeWhisperer is free to use, which is very attractive for individual programmers and small teams. It provides a low-cost way for developers to easily obtain high-quality code advice without having to worry about cost.
  • Can support learning and skill growth : CodeWhisperer can help developers learn new coding techniques and APIs. Using CodeWhisperer, developers can easily create new code and get suggestions on how to improve their workflow. CodeWhisperer also helps developers improve their skill levels as it provides professional-grade code suggestions and constructive feedback.
  • Flexible output options available : CodeWhisperer can provide code suggestions in a variety of formats, including code snippets, functions, classes, and entire projects. Developers can choose the output options that suit their needs, making CodeWhisperer even more flexible and adaptable.

2. Applicable scenarios

  • Write boilerplate code : Developers can use CodeWhisperer to quickly generate boilerplate code. For example, just enter "Create a class for preprocessing scripts for ML data" and CodeWhisperer will be able to generate a code block for the entire preprocessed data class, saving time writing boilerplate code.
  • Coding in unfamiliar languages : CodeWhisperer helps developers code in unfamiliar programming languages. For example, a new Java user who joins the team can use CodeWhisperer to easily start writing Python code without worrying about syntax errors.
  • Detect security vulnerabilities in code : CodeWhisperer has the function of detecting security vulnerabilities in code. Developers can choose to run a security scan within the IDE, and CodeWhisperer will provide detailed information about security issues. This helps developers detect and resolve potential security issues early.
  • Eliminate typos and typical errors : CodeWhisperer leverages artificial intelligence technology to help developers eliminate typos and typical errors, thereby improving the accuracy of their code.
  • Reduce repetitive coding : CodeWhisperer reduces repetitive coding efforts by recommending subsequent code snippets that may be needed. Developers can write code faster and avoid writing similar code segments over and over again.
  • Other common tasks and using unfamiliar API scenarios : CodeWhisperer can also help developers complete other common, time-consuming and undifferentiated tasks, such as writing code to read and write files, process images, write unit tests, etc. It's also useful for building sample code when using unfamiliar APIs or SDKs.

  • Practical experience

Install

Install the Amazon CodeWhisperer plug-in on IDEA (Brother Xu Zhu uses the IDEA2022.1.4 version)

Follow the steps below to install the Amazon Toolkit plugin in IDEA:

1. Open IDEA, click the "File" menu in the upper right corner, and then select "Settings".

2. In the menu bar on the left side of the settings window, click "Plugins".

3. In the upper right corner of the Plugins page, enter "Amazon Toolkit" and select the corresponding plug-in from the search results .

4. Click the "Install" button to start installing the plug-in.

5. After the installation is completed, click the "OK" button .

Note that after the installation is complete, IDEA must be restarted for it to take effect.

Click "View" -> "Tool Windows" -> "Amazon Toolkit". This will open the Amazon Toolkit view.

On the Amazon Toolkit view, you will see a tab called "Developer Tools". Click this tab.

On the "Developer Tools" page, you will see an option called "CodeWhisperer". Click this option.

On the CodeWhisperer page, you will see a button called "Start". click this button

选择“Use a personal email to sign up and sign in with Amazon Builder ID

Then click "connect"

In the pop-up window, click Copy. This is the copy code.

Then select "Open and Copy Code"

A browser page will pop up, enter the copied code and submit

Enter your email address and click " Next "

Enter your name and click "Next". CodeWhisperer will send a verification code to your email.

Go to your email to find the verification code, copy it, and next step

Set a password, the password requirements are relatively high

If something like this appears, it means the creation was successful.

Practical combat 1:

Complete comment function

You can complete the comments based on the previous article and the effect will be pretty good. I don’t like writing commentaries on the gospel.

Actual combat 2:

I wrote a comment and wanted to write a bubble sort. Automatically generate code for me

Select insert code 

Press Enter in the method body and the code will be automatically generated.

Code is generated

package com.xiaoxuzhu.csdn;

public class TestCodeWhisperer {
      
      

    /**
     * 写个冒泡排序
     */
    public static void main(String[] args) {
      
      

        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int temp = 0;
        for (int i = 0; i < arr.length - 1; i++) {
      
      
            for (int j = 0; j < arr.length - 1 - i; j++) {
      
      
                if (arr[j] > arr[j + 1]) {
      
      
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
      
      
            System.out.println(arr[i]);

        }
    }

}

operation result:

Actual combat 3:

Practical Combat 1 is just a simple sorting algorithm, and the requirements are not high. Now let’s upgrade the experiment. Enter a paragraph, the general requirement is: find the maximum value of each swipe of the window.

You are given an array of integers nums with a sliding window of size k moving from the leftmost side of the array to the rightmost side of the array. You can only see k numbers within the sliding window. The sliding window only moves one position to the right at a time.

 Requests to return the maximum value in the sliding window.

Select insert code 

Select insert code 

Finally, the complete code is generated.

package com.xiaoxuzhu.csdn;

public class TestCodeWhisperer2 {
      
      

    /**
     * 给你一个整数数组 nums,有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的 k 个数字。滑动窗口每次只向右移动一位。
     * <p>
     * 返回 滑动窗口中的最大值 。
     */
    public static void main(String[] args) {
      
      
        int[] nums = {1, 3, -1, -3, 5, 3, 6, 7};
        int k = 3;
        int[] res = maxSlidingWindow(nums, k);
        for (int i : res) {
      
      
            System.out.println(i);
        }
    }

    public static int[] maxSlidingWindow(int[] nums, int k) {
      
      
        int[] res = new int[nums.length - k + 1];
        int index = 0;
        for (int i = 0; i < nums.length - k + 1; i++) {
      
      
            int max = Integer.MIN_VALUE;
            for (int j = i; j < i + k; j++) {
      
      
                max = Math.max(max, nums[j]);
            }
            res[index++] = max;
        }
        return res;
    }


}

The execution result is correct

The experiment process was very smooth, and the AI's understanding ability is still very strong. It can correctly understand what Brother Xu Zhu meant and generate the corresponding code.

Actual combat 4:

Choose an algorithm question with a relatively high level of difficulty from leetcode and see if AI can understand it and answer it correctly.

Choose a difficulty level in dynamic programming:

The topic is:

Given a string containing only  '('  and  ')'  , find the length of the longest valid (well-formed and consecutive) bracket substring.

Start writing code in ai

Follow the prompts and continue to insert code

Final generated code:

After running it, the result is 2, which is correct.

Is this enough? No! Let leetcode judge the quality of the generated code

Copy the code into leetcode and run it first

Passed~

submit

Defeat 100%~ 

At this moment, a BGM sounded: How, how lonely it is to be invincible~

Practical combat 5:

Write a small game and see if you can understand the context.

game rules:

Write a number guessing game, from 1 to 188, and let the user input the number on the console. If the user guesses a higher number, it will prompt the higher number, and if it is smaller, it will prompt the smaller number.

Prompt word: Randomly generate a number between 1 and 188

Prompt word: write a mark, default false

Tip: Create a Scanner object

Prompt word: In the loop, the loop condition is that the flag is true to terminate the loop. The user is first prompted to guess the number. The user enters the number and determines whether the value of guessNumber is the same as number. If they are the same, set the flag to true. Jump out of the loop; determine guessNumber. Is the value the same as number? If it is larger, it will indicate that it is too large. If it is small, it will indicate that it is too small.

Prompt word: Finally generated prompt: Congratulations, you guessed it right

The complete code generated, try running it:

Precautions

The " Amazon Toolkit " plug-in of Amazon CodeWhisperer has restrictions on the version support of the idea. I started trying it from the 2019 version, and there were incompatibility issues. I looked up the information later and found that it is only supported from the 2022.1 version and above.

3. Summary

Over time, artificial intelligence technology has developed rapidly. Intelligent programming assistants such as Amazon CodeWhisperer greatly improve development efficiency and code quality. CodeWhisperer is a powerful intelligent programming assistant that helps developers build applications faster and more securely.

CodeWhisperer solves common pain points in development. It quickly generates accurate code suggestions, saving time. For unfamiliar programming languages, it provides accurate code suggestions to avoid syntax errors and problems. In addition, CodeWhisperer helps developers discover and fix security vulnerabilities early and improve software security and stability. It also eliminates typos and typical errors, improving code accuracy.

CodeWhisperer has many advantages. It improves work efficiency and productivity, allows you to code with confidence and provides relevant open source project information. It supports multiple programming languages ​​and popular IDEs, providing an efficient and convenient development experience. Developers can use it or turn it off at any time, and it is free to use, reducing costs.

Suitable for a variety of scenarios, CodeWhisperer can quickly generate boilerplate code to aid coding in unfamiliar programming languages, detect security vulnerabilities, eliminate typing and typical errors, and reduce repetitive coding efforts. It is also suitable for other common tasks and scenarios using unfamiliar APIs.

In actual experience, installing and using the Amazon CodeWhisperer plug-in is very simple and can be seamlessly integrated with popular IDEs. Brother Xu Zhu installed the Amazon Toolkit plug-in using IDEA and successfully used CodeWhisperer to generate some code. The experiment process ranged from simple annotation generation to complex algorithmic solutions, and finally the experiment was to write a small game . CodeWhisperer accurately understood Brother Xu Zhu’s intention and generated the corresponding code.

This experience was very pleasant and rewarding. It can be put into development and production, reducing the amount of development, allowing me to have more time to devote to more valuable work.

You can also experience it, and you are welcome to communicate with Brother Xu Zhu to share your experience.

I'm Brother Xu Zhu, see you tomorrow~

Guess you like

Origin blog.csdn.net/shi_hong_fei_hei/article/details/133345923