【GitHub Copilot】GitHub Copilot的特点,给出的结果并不是完全正确,需要人工修正
有时,人工智能可能会出现故障,或达不到人类的能力和准确性,仍然需要人工改进。
比如有如下例子,这是GitHub Copilot根据注释生成的代码,我都全部接受了。
public with sharing class DateUtility {
//月の最終日を取得
//dATE:日付
public static Date getLastDateOfMonth(Date dATE) {
Integer year = dATE.year();
Integer month = dATE.month();
Integer lastDay = Date.daysInMonth(year, month);
return Date.newInstance(year, month, lastDay);
}
//月の初日を取得
//dATE:日付
public static Date getFirstDateOfMonth(Date dATE) {
Integer year = dATE.year();
Integer month = dATE.month();
return Date.newInstance(year, month, 1);
}
}
然后我要上传代码到Salesforce上面,就发现了一个小问题。
有两处参数不符合Salesforce的变量规则。
Salesforce Apex 具有不区分变量名中大小写字母的特性,
这意味着 myVariable、myvariable 和 MyVariable 都被视为同一个变量。
原因很可能是,GitHub Copilot使用的是Java的代码来训练,所以才会发生这样的错误。
所以这里我们需要手动修改一下变量,我把变量从dATE修改成dateInput,就解决了问题。
public with sharing class DateUtility {
//月の最終日を取得
//dateInput:日付
public static Date getLastDateOfMonth(Date dateInput) {
Integer year = dateInput.year();
Integer month = dateInput.month();
Integer lastDay = Date.daysInMonth(year, month);
return Date.newInstance(year, month, lastDay);
}
//月の初日を取得
//dateInput:日付
public static Date getFirstDateOfMonth(Date dateInput) {
Integer year = dateInput.year();
Integer month = dateInput.month();
return Date.newInstance(year, month, 1);
}
}
所以我们要有一个意识,就是GitHub Copilot只是一个帮助我们提高效率的编程的智能助手,最终责任人,还是我们自己。