锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 开源技术 / AI代码助手 / Amazon Q和Amazon CodeWhisperer评价和生成C++代码测试
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
量化预测
股票离线分析软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

锐英源精品原创文章,禁止转载和任何形式的非法内容使用,违者必究


Amazon Q和Amazon CodeWhisperer评价和生成C++代码测试


AI代码助手是最近流行的话题,特意找了排名第二的Amazon Q和Amazon CodeWhisperer进行了试用。首先声明,收费模式下的生成结果会更好,这里只是测试了普通版本。Amazon Q和Amazon CodeWhisperer的Professional Tier模式,可能会帮你生成出来大段的AWS接口代码,让你一句描述变成一个函数,会节省大量的精力。而Free Tier相当于入门级别的试用。

对Free Tier下,我写了一些注释,按Alt+C和Tab生成了一些代码,总体评价对刚入门程序员很有用,对于中级和高级程序员用处不大。在定制需求开发情况下,AI代码助手不可能把爬到的代码精华直接给出来,因为这涉及到代码版权和著作权问题,虽然是开源代码,但是让AI代码助手直接给出项目框架,是不可能的。Amazon Q和Amazon CodeWhisperer在Free Tier下的测试评价就是类似抄MSDN,把MSDN里的例子代码抄到代码窗口上,但是抄并不是说AI代码助手没用,AI代码助手的核心在于理解程序员的注释,这比枯燥的搜索强。但对于复杂注释能让AI代码助手自己理清,分析出过程,逐一实现过程,这才叫完整的人工智能。

Amazon Q和Amazon CodeWhisperer的VS2022下首页里的链接Try Amazon Q with examples,需要开启Toolkit,不开启是试不出来Enter生成效果。我开始试了几次,按Enter没反应,猜可能需要开启Toolkit,因为里面要调用AWS接口。

在使用时,Amazon Q会有红色故障按钮出现在代码窗口状态栏里,这时候把Amazon Q的Option打开,设置,再关闭,就没有故障了。

下面是试用时的一些代码:

   //stl copy_if
std::vector<int> v1{ 1,2,3,4,5,6,7,8,9,10 };
std::vector<int> v2(10);
std::copy_if(v1.begin(), v1.end(), v2.begin(), [](int i) {return i > 4; });
std::cout << "v2: " << std::endl;
// openssl server
for (int n : v2)
std::cout << n << ' ';
std::cout << '\n';
std::cout << "v1: " << std::endl;
// tcp server
for (int n : v1)
std::cout << n << ' ';
std::cout << '\n';
std::cout << "v2: " << std::endl;
// tcp client
for (int n : v2)
std::cout << n << ' ';
//prepare a socket and connect 127.0.0.1,send "ok"
std::cout << '\n';
std::cout << "v1: " << std::endl;
// tcp client
for (int n : v1)
std::cout << n << ' ';
std::cout << '\n';

对copy_if最满意,因为这算是个入门者用不好的知识点。其它的功能测试就驴头不对马嘴了。

最开始测试的是“socket select”,如下图:

aws Amazon Q ai界面

socket select 输出比较满意。

Amazon Q和Amazon CodeWhisperer的安全检查功能调用后输出:

Initializing: Amazon Q Language Client
Launching Amazon Q Language Server v2.1.2 from local cache location: C:\Users\86138\AppData\Local\aws\toolkits\language-servers\AmazonQ\2.1.2 (Attribution notice for aws-lsp-codewhisperer can be found at: https://aws-language-servers.us-east-1.amazonaws.com/1eefd3f9-43a2-4984-84e8-38fabcba5b58/THIRD_PARTY_LICENSES)
Activating: Amazon Q Language Client
Initialized: Amazon Q Language Client
Reconnected to Amazon Q with awsBuilderId:amazonQ
Amazon Q security scan started
Amazon Q security scan failed: "aws-toolkit-c-cpp" is not supported for security scan.
Loading Amazon Q Chat UI: C:\Users\86138\AppData\Local\aws\toolkits\language-servers\AmazonQ\2.1.2\clients\amazonq-ui.js
Amazon Q security scan started
Amazon Q security scan failed: "aws-toolkit-c-cpp" is not supported for security scan.

免费的用不了,不过提示大家要多关注这个功能,非常有用。

Amazon Q和Amazon CodeWhisperer的聊天窗口如下:

amazon Q chat

聊天时用了stl function测试,输出的文章和代码非常标准。聊天时的"Explain selected code”命令能解释选中代码,目的和按F1效果差不多,但是实际不一样。比如解释下面这一段:

    unsigned short wrLen;
    unsigned short w1 = 5;
    wrLen = w1 << 8 + 5;

解释结果是:

The selected code is:

wrLen = w1 << 8 + 5;

Copy

Insert at cursor
cpp
This line of C++ code is performing bitwise and arithmetic operations to calculate a value for wrLen. Let's break it down step by step:

w1 is likely a variable holding some integer value.

<< is the left shift operator. It shifts the bits of w1 to the left by the number of positions specified on the right side of the operator.

8 is the number of positions to shift the bits of w1 to the left.

+ 5 is a simple addition operation.

The result of these operations is assigned to wrLen.

However, there's an important issue with this code that needs to be addressed. Due to operator precedence in C++, this line doesn't do what it might appear to do at first glance. Here's how it's actually interpreted:

wrLen = w1 << (8 + 5);

Copy

Insert at cursor
cpp
This means it's shifting w1 left by 13 bits (8 + 5), which is probably not the intended behavior.

If the intention was to shift w1 left by 8 bits and then add 5, the correct way to write this would be:

wrLen = (w1 << 8) + 5;

Copy

Insert at cursor
cpp
This version first shifts w1 left by 8 bits (which is equivalent to multiplying by 256) and then adds 5 to the result.

For example, if w1 is 3:

3 << 8 is 768 (3 * 256)

768 + 5 is 773

So wrLen would be assigned the value 773.

This kind of operation is often used in bit manipulation, such as when working with binary protocols or when packing multiple pieces of information into a single integer. However, it's important to use parentheses to ensure the operations are performed in the intended order.

这体现了AI助手对于直观代码的理解功能,非常强大。但是遗憾的是,都是英文的,需要再处理下。

友情链接
版权所有 Copyright(c)2004-2024 锐英源软件
统一社会信用代码:91410105098562502G 豫ICP备08007559号 最佳分辨率 1440*900
地址:郑州市金水区文化路97号郑州大学北区院内南门附近