编程工具您现在的位置是:首页 > 工具箱 > 编程工具

GitHub Copilot 有多神奇(英文)

<a href='mailto:'>微wx笑</a>的头像微wx笑 2023-02-07编程工具 2 0关键字: GitHub  Copilot  

GitHub Copilot 是一个 AI 编程辅助工具,会自动生成代码。

最近,它推出了"代码刷"功能(code brush),用户可以选择不同的刷子处理代码,本文演示这个功能多么神奇。

GitHub Copilot 是一个 AI 编程辅助工具,会自动生成代码。A3g无知

最近,它推出了"代码刷"功能(code brush),用户可以选择不同的刷子处理代码,本文演示这个功能多么神奇。A3g无知


A3g无知

Github Next now showed a new feature in GitHub Copilot labs that allows you to change code you write to make it cleaner, more robust and document it automatically.A3g无知

GitHub Copilot is incredible, and if you check what’s happening in the preview released as the Copilot Labs extension it will only get more amazing.A3g无知

Check this out:A3g无知

Code brushes applied to a simple JavaScriptA3g无知

Let’s start with a basic JavaScript that checks a string length and reports when it is empty. One with an obvious mistake, as we use a single `=` instead of the type safe `===`. This will always report the string as empty.A3g无知


A3g无知

if (str.length = 0) {
    console.error('String is empty');}


A3g无知

Using the `Fix bugs` brush, this is rectified.A3g无知


A3g无知

if (str.length === 0) {
    console.error('String is empty');}


A3g无知

Using the `Clean` brush also adds reporting when the string is not empty.A3g无知


A3g无知

if (str.length === 0) {
    console.error('String is empty');} else {
    console.log('String is not empty');}


A3g无知

Using the `List steps` brush adds comments for step (sure, this is redundant, but it also works for much more complex code).A3g无知


A3g无知

// check the length of the stringif (str.length === 0) {
    // if length is 0, print 'String is empty' 
    console.error('String is empty');} else {
    // if length is not 0, print 'String is not empty'
    console.log('String is not empty');}


A3g无知

Using `Make robust` adds error reporting instead of logging and an extra check to make sure that `str` is really a String and not an empty Array.A3g无知


A3g无知

function test(str) {
    if (str.length === 0) {
        throw new Error('String is empty');
    } else if (typeof str !== 'string') {
        throw new Error('It is not a string');
    } else {
        console.log('String is not empty');
    }}


A3g无知

The `Add types` brush does exactly that.A3g无知


A3g无知

/**
 * @param {string} str
 * @returns {string}
 */function test(str) {
    if (str.length === 0) {
        throw new Error('String is empty');
    } else if (typeof str !== 'string') {
        throw new Error('It is not a string');
    } else {
        console.log('String is not empty');
    }}


A3g无知

You can also define custom brushes and there are more to come.A3g无知


A3g无知

转自:https://christianheilmann.com/2022/12/13/code-brushes-for-github-copilot/ A3g无知


A3g无知

本文为转载文章,版权归原作者所有,不代表本站立场和观点。

很赞哦! () 有话说 ()