Skip to main content

GitHub Copilot๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง

Copilot ์ธ๊ณต ์ง€๋Šฅ์„ ํ™œ์šฉํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ๋น ๋ฅด๊ณ  ํšจ๊ณผ์ ์œผ๋กœ ๋ฆฌํŒฉํ„ฐ๋งํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์†Œ๊ฐœ

์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง์€ ๋™์ž‘์„ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๊ณ  ๊ธฐ์กด ์ฝ”๋“œ๋ฅผ ์žฌ๊ตฌ์„ฑํ•˜๋Š” ํ”„๋กœ์„ธ์Šค์ž…๋‹ˆ๋‹ค. ๋ฆฌํŒฉํ„ฐ๋ง์˜ ์ด์ ์€ ์ฝ”๋“œ ๊ฐ€๋…์„ฑ ํ–ฅ์ƒ, ๋ณต์žก์„ฑ ๊ฐ์†Œ, ๋” ๊ฐ„ํŽธํ•œ ์ฝ”๋“œ ์œ ์ง€ ๊ด€๋ฆฌ ๋ฐ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ๋” ์‰ฝ๊ฒŒ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ ๋“ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๋ฌธ์„œ์—์„œ๋Š” Copilot์„(๋ฅผ) ์‚ฌ์šฉํ•˜์—ฌ IDE์˜ ์ฝ”๋“œ๋ฅผ ๋ฆฌํŒฉํ„ฐ๋งํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ๋ช‡ ๊ฐ€์ง€ ์•„์ด๋””์–ด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ  ํ•ญ๋ชฉ

์˜ˆ์‹œ ์‘๋‹ต์€ ์ด ๋ฌธ์„œ์— ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. GitHub Copilot ์ฑ„ํŒ…์€ ์—ฌ๊ธฐ์— ํ‘œ์‹œ๋œ ์‘๋‹ต๊ณผ ๋‹ค๋ฅธ ์‘๋‹ต์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฝ”๋“œ ์ดํ•ด

๊ธฐ์กด ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•˜๊ธฐ ์ „์— ํ•ด๋‹น ์šฉ๋„์™€ ํ˜„์žฌ ์ž‘๋™ ๋ฐฉ์‹์„ ์ดํ•ดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Copilot๊ฐ€ ๋„์›€์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. IDE ํŽธ์ง‘๊ธฐ์—์„œ ๊ด€๋ จ ์ฝ”๋“œ๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  2. ์ธ๋ผ์ธ ์ฑ„ํŒ… ์—ด๊ธฐ:

    • VS Code์—์„œ: Command+i(Mac) ๋˜๋Š” Ctrl+i(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • Visual Studio์—์„œ Alt+/๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • JetBrains IDE์—์„œ: Control+Shift+i(Mac) ๋˜๋Š” Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
  3. ์ธ๋ผ์ธ ์ฑ„ํŒ…์˜ ์ž…๋ ฅ ์ƒ์ž์— ์Šฌ๋ž˜์‹œ(/)๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

  4. ๋“œ๋กญ๋‹ค์šด ๋ชฉ๋ก์—์„œ /explain์„ ์„ ํƒํ•˜๊ณ  Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

  5. Copilot์ด(๊ฐ€) ๋ฐ˜ํ™˜ํ•˜๋Š” ์„ค๋ช…์ด ๋ช‡ ์ค„ ์ด์ƒ์ธ ๊ฒฝ์šฐ ์ฑ„ํŒ…์—์„œ ๋ณด๊ธฐ๋ฅผ ํด๋ฆญํ•˜์—ฌ ์„ค๋ช…์„ ๋” ์‰ฝ๊ฒŒ ์ฝ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋น„ํšจ์œจ์ ์ธ ์ฝ”๋“œ ์ตœ์ ํ™”

Copilot๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ฝ”๋“œ๋ฅผ ๋” ๋น ๋ฅด๊ฒŒ ์‹คํ–‰ํ•˜๋Š” ๋“ฑ ์ฝ”๋“œ๋ฅผ ์ตœ์ ํ™”ํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์ œ ์ฝ”๋“œ

์•„๋ž˜ ๋‘ ์„น์…˜์—์„œ๋Š” ๋‹ค์Œ ์˜ˆ์ œ Bash ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋น„ํšจ์œจ์ ์ธ ์ฝ”๋“œ๋ฅผ ์ตœ์ ํ™”ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

#!/bin/bash

# Find all .txt files and count lines in each
for file in $(find . -type f -name "*.txt"); do
    wc -l "$file"
done

Copilot Chat ํŒจ๋„ ์‚ฌ์šฉ

Copilot์€(๋Š”) ์˜ˆ์ œ Bash ์Šคํฌ๋ฆฝํŠธ์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ตœ์ ํ™”ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ์•Œ๋ ค์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. for ๋ฃจํ”„ ๋˜๋Š” ํŒŒ์ผ์˜ ์ „์ฒด ์ฝ˜ํ…์ธ ๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  2. ํ™œ๋™ ํ‘œ์‹œ์ค„์—์„œ ์ฑ„ํŒ… ์•„์ด์ฝ˜์„ ํด๋ฆญํ•˜๊ฑฐ๋‚˜ ๋ฐ”๋กœ ๊ฐ€๊ธฐ ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Copilot Chat์„ ์—ฝ๋‹ˆ๋‹ค.

    • VS Code ๋ฐ Visual Studio: Control+Command+i(Mac) / Ctrl+Alt+i(Windows/Linux)
    • JetBrains: Control+Shift+c
  3. ์ฑ„ํŒ… ํŒจ๋„ ์•„๋ž˜์ชฝ์˜ ์ž…๋ ฅ ์ƒ์ž์— Can this script be improved?์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

    Copilot์€(๋Š”) ์ฝ”๋“œ๋ฅผ ๋ณด๋‹ค ํšจ์œจ์ ์œผ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ์ œ์•ˆ์œผ๋กœ ํšŒ์‹ ํ•ฉ๋‹ˆ๋‹ค.

  4. ์ œ์•ˆ๋œ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ ์šฉํ•˜๋ ค๋ฉด:

    • VS Code ๋ฐ JetBrains์—์„œ: ์ฑ„ํŒ… ํŒจ๋„์˜ ์ œ์•ˆ ์œ„๋กœ ๋งˆ์šฐ์Šค๋ฅผ ๊ฐ€์ ธ๊ฐ€์„œ ์ปค์„œ ์œ„์น˜์— ์‚ฝ์ž… ์•„์ด์ฝ˜์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

      Copilot Chat ํŒจ๋„์˜ 'Insert at cursor' ์•„์ด์ฝ˜ ์Šคํฌ๋ฆฐ์ƒท.

    • Visual Studio์—์„œ: ๋ฏธ๋ฆฌ ๋ณด๊ธฐ๋ฅผ ํด๋ฆญํ•œ ๋‹ค์Œ ๋น„๊ต ๋ณด๊ธฐ์—์„œ ์ˆ˜๋ฝ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

Copilot ์ธ๋ผ์ธ ์ฑ„ํŒ… ์‚ฌ์šฉ

๋˜๋Š” ์˜ˆ์ œ Bash ์Šคํฌ๋ฆฝํŠธ์™€ ๊ฐ™์€ ๊ธฐ์กด ์ฝ”๋“œ๊ฐ€ ๋น„ํšจ์œจ์ ์ด๋ผ๋Š” ๊ฒƒ์„ ์ด๋ฏธ ์•Œ๊ณ  ์žˆ๋Š” ๊ฒฝ์šฐ:

  1. for ๋ฃจํ”„ ๋˜๋Š” ํŒŒ์ผ์˜ ์ „์ฒด ์ฝ˜ํ…์ธ ๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  2. ์ธ๋ผ์ธ ์ฑ„ํŒ… ์—ด๊ธฐ:

    • VS Code์—์„œ: Command+i(Mac) ๋˜๋Š” Ctrl+i(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • Visual Studio์—์„œ Alt+/๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • JetBrains IDE์—์„œ: Control+Shift+i(Mac) ๋˜๋Š” Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
  3. optimize์„ ์ž…๋ ฅํ•˜๊ณ  Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

    Copilot๋Š” ์ˆ˜์ •๋œ ์ฝ”๋“œ๋ฅผ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์‹œ:

    find . -type f -name "*.txt" -exec wc -l {} +
    

    -exec ... +๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฐœ๊ฒฌ๋œ ๊ฐ *.txt ํŒŒ์ผ์— ๋Œ€ํ•ด wc๋ฅผ ํ•œ ๋ฒˆ ํ˜ธ์ถœํ•˜๋Š” ๋Œ€์‹  find๊ฐ€ ํ•œ ๋ฒˆ์— ์—ฌ๋Ÿฌ ํŒŒ์ผ์„ wc์— ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด ๋ฌธ์„œ์˜ ์•ž๋ถ€๋ถ„์— ํ‘œ์‹œ๋œ ์›๋ž˜ ์ฝ”๋“œ๋ณด๋‹ค ๋” ํšจ์œจ์ ์ž…๋‹ˆ๋‹ค.

  4. Copilot์˜ ์ œ์•ˆ์„ ํ‰๊ฐ€ํ•˜๊ณ  ๋ณ€๊ฒฝ์— ๋™์˜ํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    • VS Code ๋ฐ Visual Studio์—์„œ: ์ˆ˜๋ฝ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
    • JetBrains: ๋ฏธ๋ฆฌ ๋ณด๊ธฐ ์•„์ด์ฝ˜(์ด์ค‘ ํ™”์‚ดํ‘œ)์„ ํด๋ฆญํ•œ ๋‹ค์Œ ๋ชจ๋“  Diff ์ ์šฉ ์•„์ด์ฝ˜(์ด์ค‘ ๊บพ์‡  ๊ด„ํ˜ธ)์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

๋ชจ๋“  Copilot ์ œ์•ˆ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ˆ˜์ •๋œ ์ฝ”๋“œ๊ฐ€ ์˜ค๋ฅ˜ ์—†์ด ์‹คํ–‰๋˜๊ณ  ์˜ฌ๋ฐ”๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ์ƒ์„ฑํ•˜๋Š”์ง€ ํ•ญ์ƒ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋ฐ˜๋ณต ์ฝ”๋“œ ์ •๋ฆฌ

๋ฐ˜๋ณต์„ ๋ฐฉ์ง€ํ•˜๋ฉด ์ฝ”๋“œ๋ฅผ ๋ณด๋‹ค ์‰ฝ๊ฒŒ ์ˆ˜์ •ํ•˜๊ณ  ๋””๋ฒ„๊ทธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋™์ผํ•œ ๊ณ„์‚ฐ์ด ํŒŒ์ผ์˜ ๋‹ค๋ฅธ ์œ„์น˜์—์„œ ๋‘ ๋ฒˆ ์ด์ƒ ์ˆ˜ํ–‰๋˜๋Š” ๊ฒฝ์šฐ ๊ณ„์‚ฐ์„ ํ•จ์ˆ˜๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ์˜ ๋งค์šฐ ๊ฐ„๋‹จํ•œ JavaScript ์˜ˆ์ œ์—์„œ๋Š” ๋™์ผํ•œ ๊ณ„์‚ฐ(ํ•ญ๋ชฉ ๊ฐ€๊ฒฉ์— ํŒ๋งค๋œ ํ•ญ๋ชฉ ์ˆ˜๋ฅผ ๊ณฑํ•œ ๊ฐ’)์ด ๋‘ ์œ„์น˜์—์„œ ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค.

let totalSales = 0;

let applePrice = 3;
let applesSold = 100;
totalSales += applePrice * applesSold;

let orangePrice = 5;
let orangesSold = 50;
totalSales += orangePrice * orangesSold;

console.log(`Total: ${totalSales}`);

Copilot์—๊ฒŒ ๋ฐ˜๋ณต ๊ณ„์‚ฐ์„ ํ•จ์ˆ˜๋กœ ์ด๋™ํ•˜๋„๋ก ์š”์ฒญํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. ํŒŒ์ผ์˜ ์ „์ฒด ๋‚ด์šฉ์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  2. ์ธ๋ผ์ธ ์ฑ„ํŒ… ์—ด๊ธฐ:

    • VS Code์—์„œ: Command+i(Mac) ๋˜๋Š” Ctrl+i(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • Visual Studio์—์„œ Alt+/๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • JetBrains IDE์—์„œ: Control+Shift+i(Mac) ๋˜๋Š” Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
  3. move repeated calculations into functions์„ ์ž…๋ ฅํ•˜๊ณ  Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

    Copilot๋Š” ์ˆ˜์ •๋œ ์ฝ”๋“œ๋ฅผ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์‹œ:

    function calculateSales(price, quantity) {
      return price * quantity;
    }
    
    let totalSales = 0;
    
    let applePrice = 3;
    let applesSold = 100;
    totalSales += calculateSales(applePrice, applesSold);
    
    let orangePrice = 5;
    let orangesSold = 50;
    totalSales += calculateSales(orangePrice, orangesSold);
    
    console.log(`Total: ${totalSales}`);
    
  4. Copilot์˜ ์ œ์•ˆ์„ ํ‰๊ฐ€ํ•˜๊ณ  ๋ณ€๊ฒฝ์— ๋™์˜ํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    • VS Code ๋ฐ Visual Studio์—์„œ: ์ˆ˜๋ฝ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
    • JetBrains: ๋ฏธ๋ฆฌ ๋ณด๊ธฐ ์•„์ด์ฝ˜(์ด์ค‘ ํ™”์‚ดํ‘œ)์„ ํด๋ฆญํ•œ ๋‹ค์Œ ๋ชจ๋“  Diff ์ ์šฉ ์•„์ด์ฝ˜(์ด์ค‘ ๊บพ์‡  ๊ด„ํ˜ธ)์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

๋ชจ๋“  Copilot ์ œ์•ˆ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ˆ˜์ •๋œ ์ฝ”๋“œ๊ฐ€ ์˜ค๋ฅ˜ ์—†์ด ์‹คํ–‰๋˜๊ณ  ์˜ฌ๋ฐ”๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ์ƒ์„ฑํ•˜๋Š”์ง€ ํ•ญ์ƒ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ฝ”๋“œ๋ฅผ ๋ณด๋‹ค ๊ฐ„๊ฒฐํ•˜๊ฒŒ ๋งŒ๋“ค๊ธฐ

์ฝ”๋“œ๊ฐ€ ๋ถˆํ•„์š”ํ•˜๊ฒŒ ์ž์„ธํ•œ ์ •๋ณด ํ‘œ์‹œํ•˜๋ฉด ์ฝ๊ณ  ์œ ์ง€ ๊ด€๋ฆฌํ•˜๊ธฐ๊ฐ€ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Copilot์€(๋Š”) ์„ ํƒํ•œ ์ฝ”๋“œ์˜ ๋ณด๋‹ค ๊ฐ„๊ฒฐํ•œ ๋ฒ„์ „์„ ์ œ์•ˆํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ์˜ˆ์ œ์—์„œ ์ด Python ์ฝ”๋“œ๋Š” ์‚ฌ๊ฐํ˜• ์˜์—ญ๊ณผ ์›์„ ์ถœ๋ ฅํ•˜์ง€๋งŒ ๋” ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

def calculate_area_of_rectangle(length, width):
    area = length * width
    return area

def calculate_area_of_circle(radius):
    import math
    area = math.pi * (radius ** 2)
    return area

length_of_rectangle = 10
width_of_rectangle = 5
area_of_rectangle = calculate_area_of_rectangle(length_of_rectangle, width_of_rectangle)
print(f"Area of rectangle: {area_of_rectangle}")

radius_of_circle = 7
area_of_circle = calculate_area_of_circle(radius_of_circle)
print(f"Area of circle: {area_of_circle}")
  1. ํŒŒ์ผ์˜ ์ „์ฒด ๋‚ด์šฉ์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  2. ์ธ๋ผ์ธ ์ฑ„ํŒ… ์—ด๊ธฐ:

    • VS Code์—์„œ: Command+i(Mac) ๋˜๋Š” Ctrl+i(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • Visual Studio์—์„œ Alt+/๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • JetBrains IDE์—์„œ: Control+Shift+i(Mac) ๋˜๋Š” Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
  3. make this more concise์„ ์ž…๋ ฅํ•˜๊ณ  Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

    Copilot๋Š” ์ˆ˜์ •๋œ ์ฝ”๋“œ๋ฅผ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์‹œ:

    import math
    
    def calculate_area_of_rectangle(length, width):
      return length * width
    
    def calculate_area_of_circle(radius):
      return math.pi * (radius ** 2)
    
    print(f"Area of rectangle: {calculate_area_of_rectangle(10, 5)}")
    print(f"Area of circle: {calculate_area_of_circle(7)}")
    
  4. Copilot์˜ ์ œ์•ˆ์„ ํ‰๊ฐ€ํ•˜๊ณ  ๋ณ€๊ฒฝ์— ๋™์˜ํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    • VS Code ๋ฐ Visual Studio์—์„œ: ์ˆ˜๋ฝ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
    • JetBrains: ๋ฏธ๋ฆฌ ๋ณด๊ธฐ ์•„์ด์ฝ˜(์ด์ค‘ ํ™”์‚ดํ‘œ)์„ ํด๋ฆญํ•œ ๋‹ค์Œ ๋ชจ๋“  Diff ์ ์šฉ ์•„์ด์ฝ˜(์ด์ค‘ ๊บพ์‡  ๊ด„ํ˜ธ)์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

๋ชจ๋“  Copilot ์ œ์•ˆ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ˆ˜์ •๋œ ์ฝ”๋“œ๊ฐ€ ์˜ค๋ฅ˜ ์—†์ด ์‹คํ–‰๋˜๊ณ  ์˜ฌ๋ฐ”๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ์ƒ์„ฑํ•˜๋Š”์ง€ ํ•ญ์ƒ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋ณต์žกํ•œ ์ฝ”๋“œ ๋‹จ์œ„ ๋ถ„ํ• 

์—ฌ๋Ÿฌ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋Œ€๊ทœ๋ชจ ๋ฉ”์„œ๋“œ ๋˜๋Š” ํ•จ์ˆ˜๋Š” ํŠน์ • ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐ ์ค‘์ ์„ ๋‘๋Š” ๋” ์ž‘๊ณ  ๊ฐ„๋‹จํ•œ ํ•จ์ˆ˜์— ๋น„ํ•ด ์žฌ์‚ฌ์šฉ ๊ธฐํšŒ๊ฐ€ ์ ์„ ๊ฐ€๋Šฅ์„ฑ์ด ๋†’์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ์ดํ•ดํ•˜๊ณ  ๋””๋ฒ„๊ทธํ•˜๊ธฐ๊ฐ€ ๋” ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Copilot์€(๋Š”) ๋ณต์žกํ•œ ์ฝ”๋“œ ๋ธ”๋ก์„ ์žฌ์‚ฌ์šฉ์— ๋” ์ ํ•ฉํ•œ ๋” ์ž‘์€ ๋‹จ์œ„๋กœ ๋ถ„ํ• ํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ Python ์ฝ”๋“œ๋Š” ๋งค์šฐ ๊ฐ„๋‹จํ•œ ์˜ˆ์ œ์ด์ง€๋งŒ ๋‹จ์ผ ํ•จ์ˆ˜๋ฅผ ํŠน์ • ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋‘ ํ•จ์ˆ˜๋กœ ๋ถ„ํ• ํ•˜๋Š” ์›๋ฆฌ๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

import pandas as pd
from pandas.io.formats.style import Styler

def process_data(item, price):
    # Cleanse data
    item = item.strip()  # Strip whitespace from item
    price = price.strip()  # Strip whitespace from price
    price = float(price) # Convert price to a float
    # More cleansing operations here

    # Create and print a DataFrame
    data = {'Item': [item], 'Price': [price]}
    df = pd.DataFrame(data)
    print(df.to_string(index=False))

# Example usage
item = "   Apple "
price = " 1.25"
process_data(item, price)

process_data ํ•จ์ˆ˜๋ฅผ ๋ถ„ํ• ํ•˜๋ ค๋ฉด:

  1. ํ•จ์ˆ˜ ์ด๋ฆ„์— ์ปค์„œ๋ฅผ ๋†“์Šต๋‹ˆ๋‹ค.

  2. ์ธ๋ผ์ธ ์ฑ„ํŒ… ์—ด๊ธฐ:

    • VS Code์—์„œ: Command+i(Mac) ๋˜๋Š” Ctrl+i(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • Visual Studio์—์„œ Alt+/๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • JetBrains IDE์—์„œ: Control+Shift+i(Mac) ๋˜๋Š” Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
  3. split into 2 separate functions: one for cleansing data, the other for printing์„ ์ž…๋ ฅํ•˜๊ณ  Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

    Copilot๋Š” ์ˆ˜์ •๋œ ์ฝ”๋“œ๋ฅผ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์‹œ:

    def cleanse_data(item, price):
      # Cleanse data
      item = item.strip()  # Strip whitespace from item
      price = price.strip()  # Strip whitespace from price
      price = float(price)  # Convert price to a float
      return item, price
    
    def print_data(item, price):
      # Create and print a DataFrame
      data = {'Item': [item], 'Price': [price]}
      df = pd.DataFrame(data)
      print(df.to_string(index=False))
    
    def process_data(item, price):
      item, price = cleanse_data(item, price)
      print_data(item, price)
    

    ์ฐธ๊ณ  ํ•ญ๋ชฉ

    ์œ„์— ํ‘œ์‹œ๋œ ์ œ์•ˆ ์˜ˆ์‹œ๋Š” ๊ธฐ์กด ํ•จ์ˆ˜๋ฅผ ์„ธ ๊ฐœ์˜ ํ•จ์ˆ˜๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค. ์„ธ ๋ฒˆ์งธ ํ•จ์ˆ˜๋Š” ๋‹จ์ˆœํžˆ ๋‹ค๋ฅธ ๋‘ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๊ณ  process_data ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ธฐ์กด ์ฝ”๋“œ๋ฅผ ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค.

  4. Copilot์˜ ์ œ์•ˆ์„ ํ‰๊ฐ€ํ•˜๊ณ  ๋ณ€๊ฒฝ์— ๋™์˜ํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    • VS Code ๋ฐ Visual Studio์—์„œ: ์ˆ˜๋ฝ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
    • JetBrains: ๋ฏธ๋ฆฌ ๋ณด๊ธฐ ์•„์ด์ฝ˜(์ด์ค‘ ํ™”์‚ดํ‘œ)์„ ํด๋ฆญํ•œ ๋‹ค์Œ ๋ชจ๋“  Diff ์ ์šฉ ์•„์ด์ฝ˜(์ด์ค‘ ๊บพ์‡  ๊ด„ํ˜ธ)์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

๋ชจ๋“  Copilot ์ œ์•ˆ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ˆ˜์ •๋œ ์ฝ”๋“œ๊ฐ€ ์˜ค๋ฅ˜ ์—†์ด ์‹คํ–‰๋˜๊ณ  ์˜ฌ๋ฐ”๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ์ƒ์„ฑํ•˜๋Š”์ง€ ํ•ญ์ƒ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๊ฐ€๋…์„ฑ์„ ๋†’์ด๊ธฐ ์œ„ํ•ด ์กฐ๊ฑด๋ถ€ ์ฝ”๋“œ๋ฅผ ๋‹ค์‹œ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์–‘ํ•œ ์กฐ๊ฑด์— ๋”ฐ๋ผ ์‹คํ–‰๋˜๊ฑฐ๋‚˜ ์‹คํ–‰๋˜์ง€ ์•Š๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์—๋Š” ์—ฌ๋Ÿฌ ๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์ผ๋ถ€ ์กฐ๊ฑด๋ถ€ ๊ตฌ์กฐ๋Š” ๋‹ค๋ฅธ ์กฐ๊ฑด๋ถ€ ๊ตฌ์กฐ์ฒด๋ณด๋‹ค ํŠน์ • ์‚ฌ์šฉ ์‚ฌ๋ก€์— ๋” ์ ํ•ฉํ•˜๋ฉฐ, ๋Œ€์ฒด ์กฐ๊ฑด๋ถ€ ๊ตฌ์กฐ๋ฅผ ์„ ํƒํ•˜๋ฉด ์ฝ”๋“œ๋ฅผ ๋” ์‰ฝ๊ฒŒ ์ฝ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด Java ๋ฉ”์„œ๋“œ๋Š” ์ผ๋ จ์˜ if ๋ฌธ๊ณผ else if ๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ˆ˜ํ–‰ํ•  ์ž‘์—…์„ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

public String getSound(String animal) {
  if (animal == null) {
      System.out.println("Oops! A null animal?");
  } else if (animal.equalsIgnoreCase("Dog")) {
      return "Bark";
  } else if ( animal.equalsIgnoreCase("Cat")) {
      return "Meow";
  } else if ( animal.equalsIgnoreCase("Bird")) {
      return "Tweet";
  }
  return "Unknown";
}

switch ๋ฌธ์€ ๋™์ผํ•œ ๋…ผ๋ฆฌ๋ฅผ ์ ์šฉํ•˜๋Š” ๋” ๋‚˜์€ ๋ฐฉ๋ฒ•์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. ๋ฉ”์„œ๋“œ ์ด๋ฆ„์— ์ปค์„œ๋ฅผ ๋†“์Šต๋‹ˆ๋‹ค.

  2. ์ธ๋ผ์ธ ์ฑ„ํŒ… ์—ด๊ธฐ:

    • VS Code์—์„œ: Command+i(Mac) ๋˜๋Š” Ctrl+i(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • Visual Studio์—์„œ Alt+/๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • JetBrains IDE์—์„œ: Control+Shift+i(Mac) ๋˜๋Š” Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
  3. ์œ ํ˜•: rewrite the condition to use a switch and use Java 21 syntax with null case, but also add documentation and provide a better function name.

    ๋‹จ์ผ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Copilot์—๊ฒŒ ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ๋ณ€๊ฒฝ์„ ์š”์ฒญํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

  4. Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

    Copilot๋Š” ์ˆ˜์ •๋œ ์ฝ”๋“œ๋ฅผ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์‹œ:

    /**
     * Retrieves the sound made by a given animal.
     *
     * @param animal The name of the animal.
     * @return The sound made by the animal, or "Unknown" if the animal is not recognized.
     */
    public String getAnimalSound(String animal) {
        return switch (animal) {
            case null -> {
                System.out.println("Oops! A null animal?");
                yield "Unknown";
            }
            case String a when a.equalsIgnoreCase("Dog") -> "Bark";
            case String a when a.equalsIgnoreCase("Cat") -> "Meow";
            case String a when a.equalsIgnoreCase("Bird") -> "Tweet";
            default -> "Unknown";
        };
    }
    
  5. Copilot์˜ ์ œ์•ˆ์„ ํ‰๊ฐ€ํ•˜๊ณ  ๋ณ€๊ฒฝ์— ๋™์˜ํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    • VS Code ๋ฐ Visual Studio์—์„œ: ์ˆ˜๋ฝ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
    • JetBrains: ๋ฏธ๋ฆฌ ๋ณด๊ธฐ ์•„์ด์ฝ˜(์ด์ค‘ ํ™”์‚ดํ‘œ)์„ ํด๋ฆญํ•œ ๋‹ค์Œ ๋ชจ๋“  Diff ์ ์šฉ ์•„์ด์ฝ˜(์ด์ค‘ ๊บพ์‡  ๊ด„ํ˜ธ)์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

๋ชจ๋“  Copilot ์ œ์•ˆ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ˆ˜์ •๋œ ์ฝ”๋“œ๊ฐ€ ์˜ค๋ฅ˜ ์—†์ด ์‹คํ–‰๋˜๊ณ  ์˜ฌ๋ฐ”๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ์ƒ์„ฑํ•˜๋Š”์ง€ ํ•ญ์ƒ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค๋ฅธ ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ์ฝ”๋“œ ์„œ์‹ ๋‹ค์‹œ ์ง€์ •

JavaScript์— ์ด ํ•จ์ˆ˜๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

function listRepos(o, p) {
 return fetch(`https://api.github.com/orgs/${o}/repos?per_page=${parseInt(p)}`)
   .then((response) => response.json())
   .then( (data) => data);
}

์ฝ”๋”ฉ ํ‘œ์ค€์—์„œ ํ•จ์ˆ˜์— ํ™”์‚ดํ‘œ ํ‘œ๊ธฐ๋ฒ•๊ณผ ๋งค๊ฐœ ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ์„ค๋ช…์ด ํฌํ•จ๋œ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ Copilot์„(๋ฅผ) ์‚ฌ์šฉํ•˜์—ฌ ์ด๋Ÿฌํ•œ ๋ณ€๊ฒฝ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. ํ•จ์ˆ˜ ์ด๋ฆ„์— ์ปค์„œ๋ฅผ ๋†“์Šต๋‹ˆ๋‹ค.

  2. ์ธ๋ผ์ธ ์ฑ„ํŒ… ์—ด๊ธฐ:

    • VS Code์—์„œ: Command+i(Mac) ๋˜๋Š” Ctrl+i(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • Visual Studio์—์„œ Alt+/๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
    • JetBrains IDE์—์„œ: Control+Shift+i(Mac) ๋˜๋Š” Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.
  3. use arrow notation and better parameter names์„ ์ž…๋ ฅํ•˜๊ณ  Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

    Copilot๋Š” ์ˆ˜์ •๋œ ์ฝ”๋“œ๋ฅผ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์‹œ:

    const listRepos = (org, perPage) => {
      return fetch(`https://api.github.com/orgs/${org}/repos?per_page=${parseInt(perPage)}`)
        .then(response => response.json())
        .then(data => data);
    };
    

๊ธฐํ˜ธ ์ด๋ฆ„ ๊ฐœ์„ 

์ฐธ๊ณ  ํ•ญ๋ชฉ

  • VS Code ๋ฐ Visual Studio๋งŒ ํ•ด๋‹น๋ฉ๋‹ˆ๋‹ค.
  • ์ด ๊ธฐ๋Šฅ์˜ ์ง€์› ์—ฌ๋ถ€๋Š” ์‚ฌ์šฉ ์ค‘์ธ ์–ธ์–ด์— ์ ํ•ฉํ•œ ์–ธ์–ด ํ™•์žฅ ํ”„๋กœ๊ทธ๋žจ์ด IDE์— ์„ค์น˜๋˜์–ด ์žˆ๋Š”์ง€์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง‘๋‹ˆ๋‹ค. ๋ชจ๋“  ์–ธ์–ด ํ™•์žฅ์ด ์ด ๊ธฐ๋Šฅ์„ ์ง€์›ํ•˜๋Š” ๊ฒƒ์€ ์•„๋‹™๋‹ˆ๋‹ค.

์ด๋ฆ„์„ ์ž˜ ์„ ํƒํ•˜๋ฉด ์ฝ”๋“œ๋ฅผ ๋” ์‰ฝ๊ฒŒ ์œ ์ง€ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. VS Code์˜ Copilot ๋ฐ Visual Studio์—์„œ ๋ณ€์ˆ˜ ๋˜๋Š” ํ•จ์ˆ˜์™€ ๊ฐ™์€ ๊ธฐํ˜ธ์— ๋Œ€ํ•œ ๋Œ€์ฒด ์ด๋ฆ„์„ ์ œ์•ˆํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  1. ๊ธฐํ˜ธ ์ด๋ฆ„์— ์ปค์„œ๋ฅผ ๋†“์Šต๋‹ˆ๋‹ค.

  2. F2 ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

  3. Visual Studio๋งŒ ํ•ด๋‹น: Ctrl+Space๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

    Copilot์€(๋Š”) ๋Œ€์ฒด ์ด๋ฆ„์„ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค.

    ๊ธฐํ˜ธ ์ด๋ฆ„์— ๋Œ€ํ•œ ๋Œ€์•ˆ์„ ์ œ๊ณตํ•˜๋Š” VS Code์˜ ๋“œ๋กญ๋‹ค์šด ๋ชฉ๋ก ์Šคํฌ๋ฆฐ์ƒท.

  4. ๋“œ๋กญ๋‹ค์šด ๋ชฉ๋ก์—์„œ ์ œ์•ˆ๋œ ์ด๋ฆ„ ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

    ํ”„๋กœ์ ํŠธ๊ฐ€ ์ง„ํ–‰๋˜๋Š” ๋™์•ˆ ์ด๋ฆ„์ด ๋ณ€๊ฒฝ๋ฉ๋‹ˆ๋‹ค.