@TOC
本文正在参加豆包MarsCode上新Apply体验活动
前言
在当今快节奏的编程开发领域,效率无疑是开发者们追求的核心目标之一。豆包MarsCode新上线的“一键Apply”功能,正是瞄准了这一痛点,力求为开发者带来全新的高效编程体验。我们可以在vscode中进行豆包MarsCode插件的下载,如果你需要体验Apply的功能的话,插件版本一定要到达1.1.40 ,插件安装地址
功能亮点
随着人工智能技术的飞速发展,编程领域也正经历着深刻变革。近期,豆包推出的 AI 编程工具 MarsCode 在开发者社区引发广泛关注。这是一款支持 C++、Java、Python、HTML 等多种主流编程语言的强大助手,集成了 AI 代码生成、代码解释、单元测试生成等丰富功能,为开发者带来全新编程体验。我们可以直接去官网进行功能的申请
1. 告别重复操作
在项目开发中,代码的复用与修改是常见场景。以往,将相同功能代码应用到不同模块,需重复复制粘贴与调试,令人苦不堪言。而“一键Apply”功能可将AI生成的代码片段自动应用到项目对应文件位置并形成Diff,无需手动打开文件等繁琐操作,极大简化了流程。
我们直接让编程小助手找到对应的错误,并且我们是不需要将正确的代码进行复制粘贴的操作,我们直接一键采纳就可以将正确的代码镶嵌到我们的源代码中去了
我们还能生成一个函数,然后插入到我们光标的位置
2. 精准问题解决
无论是代码修改、错误修复、函数名称修改,还是代码注释生成等,该功能都表现出色。例如,在代码修改场景中,它能自动识别文件路径,按需求完成代码插入/修改;通过/fix指令可快速定位并修复代码错误,差异清晰呈现,一处修改处处应用;修改函数名称时,MarsCode能自动完成查找与替换,避免连锁错误。
在这里我们一键点击Apply,豆包编程小助手快速锁定我们的错误代码并且询问我们是否需要进行采纳
#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include"list.h"
#include<iostream>
using namespace std;
class Pos
{
public:
int _row;
int _col;
Pos(int row = 0, int col = 0)
:_row(row)
, _col(col)
{
std::cout << "Pos(int row, int col)" << std::endl;
}
Pos(const Pos& p)
:_row(p._row)
, _col(p._col)
{
std::cout << "Pos(const Pos& p)" << std::endl;
}
};
int main()
{
/*kai::list<int> lt1;
lt1.push_back(1);
lt1.push_back(2);
lt1.push_back(3);
lt1.push_back(4);*/
//const kai::list<int> lt1(10, 1);//const得用const迭代器进行遍历
//kai::list<int>::const_iterator it1 = lt1.begin();
//while (it1 != lt1.end())
//{
// //*it1 = 2;//我们这里是const迭代器是不能进行修改的操作的
// std::cout<< *it1 << " ";
// ++it1;
//}
//std::cout << std::endl;
//for (auto e : lt1)
//{
// std::cout << e << " ";
//}
//std::cout << std::endl;
//kai::list<Pos> lt3;
//Pos p1(1, 1);
//lt3.push_back(p1);
//lt3.push_back(Pos(2, 2));
//lt3.push_back({ 3,3 });
kai::list<int> lt1;
lt1.push_back(1);
lt1.push_back(2);
lt1.push_back(3);
lt1.push_back(4);
lt1.push_front(0);
lt1.push_front(-1);
// auto it1 = lt1.begin();
kai::list<int>:: iterator it1 = lt1.begin();
while (it1 != lt1.end())
{
std::cout << *it1 << " ";
++it1;
}
std::cout << std::endl;
lt1.pop_front();
lt1.pop_back();
for (auto e:lt1 )
{
std::cout << e <<" ";
}
std::cout << std::endl;
kai::list<int> lt2(lt1);//拷贝构造---没有写构造函数的话那么仅仅只是浅拷贝,而且一个对象修改会影响另一个对象
for (auto e : lt2)
{
std::cout << e << " ";
}
cout << std::endl;
kai::list<int> lt3(10, 1);
lt2=lt3;
return 0;
}
这个就是我们原先的代码经过豆包编程小助手Apply之后的代码,代码整体没有问题,并且代码的风格很新颖,并且我是只点击了Apply以及采纳,完全没有进行复制粘贴的操作,豆包编程小助手可以快速找到我们代码中错误的地方以及老旧不合适的地方,然后快速进行正确代码的更替操作
3. 助力新项目开发
在创建新项目时,“一键Apply”同样给力。以初始化React项目为例,MarsCode可提供初始化和安装依赖等功能,一键运行完成初始化,自动识别新增文件路径,创建新文件与代码,大幅提升开发起始阶段的效率。
可以快速进行对应文件的创建,并且可以放上对应正确的代码
这里我们让编程小助手帮我生成一个.c文件,文件中存放的是快排的代码
随后我们就可以看到小助手给我们生成的代码
#include <stdio.h>
// 交换两个元素的函数
void swap(int* a, int* b) {
int t = *a;
*a = *b;
*b = t;
}
// 划分函数,将数组划分为两部分,一部分小于基准元素,一部分大于基准元素
int partition(int arr[], int low, int high) {
int pivot = arr[high]; // 选择最后一个元素作为基准
int i = (low - 1); // 小于基准元素的子数组的索引
for (int j = low; j <= high - 1; j++) {
// 如果当前元素小于或等于基准
if (arr[j] <= pivot) {
i++; // 增加小于基准元素的子数组的索引
swap(&arr[i], &arr[j]); // 交换 arr[i] 和 arr[j]
}
}
swap(&arr[i + 1], &arr[high]); // 将基准元素放到正确的位置
return (i + 1); // 返回基准元素的索引
}
// 快速排序函数
void quickSort(int arr[], int low, int high) {
if (low < high) {
// 划分索引,arr[p] 现在在正确的位置
int pi = partition(arr, low, high);
// 分别对划分后的两部分进行排序
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
// 打印数组的函数
void printArray(int arr[], int size) {
for (int i = 0; i < size; i++)
printf("%d ", arr[i]);
printf("\n");
}
// 主函数,用于测试快速排序
int main() {
int arr[] = {10, 7, 8, 9, 1, 5};
int n = sizeof(arr) / sizeof(arr[0]);
printf("原始数组: \n");
printArray(arr, n);
quickSort(arr, 0, n - 1);
printf("排序后的数组: \n");
printArray(arr, n);
return 0;
}
4.代码快速切换
在我们的日常编程中,可能会出现一个函数名的错误,我们需要将全局的这个函数名都进行修改的操作,但是一个个改的话会显得十分麻烦,稍有失误的话还会导致整个文件出现代码问题,但是我们的豆包编程小助手就可以完美解决这个问题,直接将我们代码中我们想要进行修改的函数名称进行修改的操作
这里我们只需要点击这个Apply就能直接将更改的代码直接贴到源代码中,将我们对应的代码进行修改的操作
下面是修改的代码
#include <stdio.h>
// 交换两个元素的函数
void swap(int* a, int* b) {
int t = *a;
*a = *b;
*b = t;
}
// 划分函数,将数组划分为两部分,一部分小于基准元素,一部分大于基准元素
int partition(int arr[], int low, int high) {
int pivot = arr[high]; // 选择最后一个元素作为基准
int i = (low - 1); // 小于基准元素的子数组的索引
for (int j = low; j <= high - 1; j++) {
// 如果当前元素小于或等于基准
if (arr[j] <= pivot) {
i++; // 增加小于基准元素的子数组的索引
swap(&arr[i], &arr[j]); // 交换 arr[i] 和 arr[j]
}
}
swap(&arr[i + 1], &arr[high]); // 将基准元素放到正确的位置
return (i + 1); // 返回基准元素的索引
}
// 快速排序函数
void qs(int arr[], int low, int high) {
if (low < high) {
// 划分索引,arr[p] 现在在正确的位置
int pi = partition(arr, low, high);
// 分别对划分后的两部分进行排序
qs(arr, low, pi - 1);
qs(arr, pi + 1, high);
}
}
// 打印数组的函数
void printArray(int arr[], int size) {
for (int i = 0; i < size; i++)
printf("%d ", arr[i]);
printf("\n");
}
// 主函数,用于测试快速排序
int main() {
int arr[] = {10, 7, 8, 9, 1, 5};
int n = sizeof(arr) / sizeof(arr[0]);
printf("原始数组: \n");
printArray(arr, n);
qs(arr, 0, n - 1);
printf("排序后的数组: \n");
printArray(arr, n);
return 0;
}
5.注释快速生成,一键Apply直接粘贴
我们在平常写代码的时候都会出现没注释看不懂代码的情况,那么我们这里将代码给豆包小助手,那么我们的豆包就可以直接进行注释的是生成,并且我们还可以让豆包小助手调整我们注释的详细程度,我们生成的注释可以直接通过Apply键呈现在我们的源代码中
我们这里让豆包小助手为当前的代码生成英文的注释,我们无序复制粘贴的操作,点击Apply就能改变原先的代码
#include <stdio.h>
// Function to swap two elements
void swap(int* a, int* b) {
// Temporary variable to hold the value of *a
int t = *a;
// Assign the value of *b to *a
*a = *b;
// Assign the value of t (original *a) to *b
*b = t;
}
// Function to partition the array into two parts, one with elements less than the pivot and the other with elements greater than the pivot
int partition(int arr[], int low, int high) {
// Choose the last element as the pivot
int pivot = arr[high];
// Index of the smaller element
int i = (low - 1);
// Iterate through the array from low to high-1
for (int j = low; j <= high - 1; j++) {
// If the current element is less than or equal to the pivot
if (arr[j] <= pivot) {
// Increment the index of the smaller element
i++;
// Swap the current element with the element at the index of the smaller element
swap(&arr[i], &arr[j]);
}
}
// Swap the pivot element with the element at the index of the smaller element + 1
swap(&arr[i + 1], &arr[high]);
// Return the index of the pivot element
return (i + 1);
}
// Function to perform quick sort on the array
void qs(int arr[], int low, int high) {
// If the low index is less than the high index
if (low < high) {
// Partition the array and get the pivot index
int pi = partition(arr, low, high);
// Recursively sort the elements before the pivot
qs(arr, low, pi - 1);
// Recursively sort the elements after the pivot
qs(arr, pi + 1, high);
}
}
// Function to print the array
void printArray(int arr[], int size) {
// Iterate through the array and print each element
for (int i = 0; i < size; i++)
printf("%d ", arr[i]);
// Print a new line after the array
printf("\n");
}
// Main function to test the quick sort algorithm
int main() {
// Array to be sorted
int arr[] = {10, 7, 8, 9, 1, 5};
// Calculate the size of the array
int n = sizeof(arr) / sizeof(arr[0]);
// Print the original array
printf("Original array: \n");
printArray(arr, n);
// Sort the array using quick sort
qs(arr, 0, n - 1);
// Print the sorted array
printf("Sorted array: \n");
printArray(arr, n);
// Return 0 to indicate successful execution
return 0;
}
使用体验
在实际使用中,安装豆包MarsCode编程助手后,在VSCode问答区域与AI对话,生成代码后点击Apply按钮,整个过程流畅自然。代码应用准确迅速,在多个项目场景测试中,均有效节省了开发时间,降低了手动操作带来的错误风险。如豆包自己的话来说,总体有以下几点
作为一个AI编程助手,我有以下优点:
- 准确性:我可以提供准确的编程建议和解决方案,帮助用户解决各种编程问题。
- 高效性:我可以快速响应用户的问题,并提供高效的代码实现和优化建议。
- 专业性:我具备丰富的编程知识和经验,可以提供专业的编程指导和建议。
- 灵活性:我可以根据用户的需求和要求,提供灵活的编程解决方案和建议。
- 易用性:我可以通过简单的交互方式,帮助用户快速解决编程问题,提高编程效率。
- 总的来说,我可以帮助用户提高编程效率,解决各种编程问题,是一个非常有用的编程助手。
总结
豆包MarsCode的“一键Apply”功能是一款极具实用性的编程辅助工具,它凭借强大的自动化能力,有效解决了开发者日常工作中的诸多难题,显著提升了编程效率。无论是经验丰富的资深开发者,还是初入行业的新手,都能从这一功能中获益。期待未来豆包MarsCode能带来更多创新功能,持续为编程开发领域注入新的活力。