์๊ฐ
์ฝ๋ ๋ฆฌํฉํฐ๋ง์ ๋์์ ๋ณ๊ฒฝํ์ง ์๊ณ ๊ธฐ์กด ์ฝ๋๋ฅผ ์ฌ๊ตฌ์ฑํ๋ ํ๋ก์ธ์ค์ ๋๋ค. ๋ฆฌํฉํฐ๋ง์ ์ด์ ์ ์ฝ๋ ๊ฐ๋ ์ฑ ํฅ์, ๋ณต์ก์ฑ ๊ฐ์, ๋ ๊ฐํธํ ์ฝ๋ ์ ์ง ๊ด๋ฆฌ ๋ฐ ์๋ก์ด ๊ธฐ๋ฅ์ ๋ ์ฝ๊ฒ ์ถ๊ฐํ ์ ์๋ ๊ฒ ๋ฑ์ด ์์ต๋๋ค.
์ด ๋ฌธ์์์๋ Copilot์(๋ฅผ) ์ฌ์ฉํ์ฌ IDE์ ์ฝ๋๋ฅผ ๋ฆฌํฉํฐ๋งํ๋ ๋ฐฉ๋ฒ์ ๋ํ ๋ช ๊ฐ์ง ์์ด๋์ด๋ฅผ ์ ๊ณตํฉ๋๋ค.
์ฐธ๊ณ ํญ๋ชฉ
์์ ์๋ต์ ์ด ๋ฌธ์์ ํฌํจ๋์ด ์์ต๋๋ค. GitHub Copilot ์ฑํ ์ ์ฌ๊ธฐ์ ํ์๋ ์๋ต๊ณผ ๋ค๋ฅธ ์๋ต์ ์ ๊ณตํ ์ ์์ต๋๋ค.
์ฝ๋ ์ดํด
๊ธฐ์กด ์ฝ๋๋ฅผ ์์ ํ๊ธฐ ์ ์ ํด๋น ์ฉ๋์ ํ์ฌ ์๋ ๋ฐฉ์์ ์ดํดํด์ผ ํฉ๋๋ค. Copilot๊ฐ ๋์์ด ๋ ์ ์์ต๋๋ค.
-
IDE ํธ์ง๊ธฐ์์ ๊ด๋ จ ์ฝ๋๋ฅผ ์ ํํฉ๋๋ค.
-
์ธ๋ผ์ธ ์ฑํ ์ด๊ธฐ:
- VS Code์์: Command+i(Mac) ๋๋ Ctrl+i(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
- Visual Studio์์ Alt+/๋ฅผ ๋๋ฆ ๋๋ค.
- JetBrains IDE์์: Control+Shift+i(Mac) ๋๋ Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
-
์ธ๋ผ์ธ ์ฑํ ์ ์ ๋ ฅ ์์์ ์ฌ๋์(
/
)๋ฅผ ์ ๋ ฅํฉ๋๋ค. -
๋๋กญ๋ค์ด ๋ชฉ๋ก์์ /explain์ ์ ํํ๊ณ Enter ํค๋ฅผ ๋๋ฆ ๋๋ค.
-
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 ์คํฌ๋ฆฝํธ์ ๊ฐ์ ์ฝ๋๋ฅผ ์ต์ ํํ ์ ์๋์ง ์ฌ๋ถ๋ฅผ ์๋ ค์ค ์ ์์ต๋๋ค.
-
for
๋ฃจํ ๋๋ ํ์ผ์ ์ ์ฒด ์ฝํ ์ธ ๋ฅผ ์ ํํฉ๋๋ค. -
ํ๋ ํ์์ค์์ ์ฑํ ์์ด์ฝ์ ํด๋ฆญํ๊ฑฐ๋ ๋ฐ๋ก ๊ฐ๊ธฐ ํค๋ฅผ ์ฌ์ฉํ์ฌ Copilot Chat์ ์ฝ๋๋ค.
- VS Code ๋ฐ Visual Studio: Control+Command+i(Mac) / Ctrl+Alt+i(Windows/Linux)
- JetBrains: Control+Shift+c
-
์ฑํ ํจ๋ ์๋์ชฝ์ ์ ๋ ฅ ์์์
Can this script be improved?
์ ์ ๋ ฅํฉ๋๋ค.Copilot์(๋) ์ฝ๋๋ฅผ ๋ณด๋ค ํจ์จ์ ์ผ๋ก ๋ง๋ค ์ ์๋ ์ ์์ผ๋ก ํ์ ํฉ๋๋ค.
-
์ ์๋ ๋ณ๊ฒฝ ์ฌํญ์ ์ ์ฉํ๋ ค๋ฉด:
-
VS Code ๋ฐ JetBrains์์: ์ฑํ ํจ๋์ ์ ์ ์๋ก ๋ง์ฐ์ค๋ฅผ ๊ฐ์ ธ๊ฐ์ ์ปค์ ์์น์ ์ฝ์ ์์ด์ฝ์ ํด๋ฆญํฉ๋๋ค.
-
Visual Studio์์: ๋ฏธ๋ฆฌ ๋ณด๊ธฐ๋ฅผ ํด๋ฆญํ ๋ค์ ๋น๊ต ๋ณด๊ธฐ์์ ์๋ฝ์ ํด๋ฆญํฉ๋๋ค.
-
Copilot ์ธ๋ผ์ธ ์ฑํ ์ฌ์ฉ
๋๋ ์์ Bash ์คํฌ๋ฆฝํธ์ ๊ฐ์ ๊ธฐ์กด ์ฝ๋๊ฐ ๋นํจ์จ์ ์ด๋ผ๋ ๊ฒ์ ์ด๋ฏธ ์๊ณ ์๋ ๊ฒฝ์ฐ:
-
for
๋ฃจํ ๋๋ ํ์ผ์ ์ ์ฒด ์ฝํ ์ธ ๋ฅผ ์ ํํฉ๋๋ค. -
์ธ๋ผ์ธ ์ฑํ ์ด๊ธฐ:
- VS Code์์: Command+i(Mac) ๋๋ Ctrl+i(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
- Visual Studio์์ Alt+/๋ฅผ ๋๋ฆ ๋๋ค.
- JetBrains IDE์์: Control+Shift+i(Mac) ๋๋ Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
-
optimize
์ ์ ๋ ฅํ๊ณ Enter ํค๋ฅผ ๋๋ฆ ๋๋ค.Copilot๋ ์์ ๋ ์ฝ๋๋ฅผ ์ ์ํฉ๋๋ค. ์์:
find . -type f -name "*.txt" -exec wc -l {} +
-exec ... +
๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฐ๊ฒฌ๋ ๊ฐ*.txt
ํ์ผ์ ๋ํดwc
๋ฅผ ํ ๋ฒ ํธ์ถํ๋ ๋์find
๊ฐ ํ ๋ฒ์ ์ฌ๋ฌ ํ์ผ์wc
์ ์ ๋ฌํ ์ ์๊ธฐ ๋๋ฌธ์ ์ด ๋ฌธ์์ ์๋ถ๋ถ์ ํ์๋ ์๋ ์ฝ๋๋ณด๋ค ๋ ํจ์จ์ ์ ๋๋ค. -
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์๊ฒ ๋ฐ๋ณต ๊ณ์ฐ์ ํจ์๋ก ์ด๋ํ๋๋ก ์์ฒญํ ์ ์์ต๋๋ค.
-
ํ์ผ์ ์ ์ฒด ๋ด์ฉ์ ์ ํํฉ๋๋ค.
-
์ธ๋ผ์ธ ์ฑํ ์ด๊ธฐ:
- VS Code์์: Command+i(Mac) ๋๋ Ctrl+i(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
- Visual Studio์์ Alt+/๋ฅผ ๋๋ฆ ๋๋ค.
- JetBrains IDE์์: Control+Shift+i(Mac) ๋๋ Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
-
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}`);
-
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}")
-
ํ์ผ์ ์ ์ฒด ๋ด์ฉ์ ์ ํํฉ๋๋ค.
-
์ธ๋ผ์ธ ์ฑํ ์ด๊ธฐ:
- VS Code์์: Command+i(Mac) ๋๋ Ctrl+i(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
- Visual Studio์์ Alt+/๋ฅผ ๋๋ฆ ๋๋ค.
- JetBrains IDE์์: Control+Shift+i(Mac) ๋๋ Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
-
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)}")
-
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
ํจ์๋ฅผ ๋ถํ ํ๋ ค๋ฉด:
-
ํจ์ ์ด๋ฆ์ ์ปค์๋ฅผ ๋์ต๋๋ค.
-
์ธ๋ผ์ธ ์ฑํ ์ด๊ธฐ:
- VS Code์์: Command+i(Mac) ๋๋ Ctrl+i(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
- Visual Studio์์ Alt+/๋ฅผ ๋๋ฆ ๋๋ค.
- JetBrains IDE์์: Control+Shift+i(Mac) ๋๋ Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
-
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
ํจ์๋ฅผ ํธ์ถํ๋ ๊ธฐ์กด ์ฝ๋๋ฅผ ํ์ฉํฉ๋๋ค. -
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
๋ฌธ์ ๋์ผํ ๋
ผ๋ฆฌ๋ฅผ ์ ์ฉํ๋ ๋ ๋์ ๋ฐฉ๋ฒ์ด ๋ ์ ์์ต๋๋ค.
-
๋ฉ์๋ ์ด๋ฆ์ ์ปค์๋ฅผ ๋์ต๋๋ค.
-
์ธ๋ผ์ธ ์ฑํ ์ด๊ธฐ:
- VS Code์์: Command+i(Mac) ๋๋ Ctrl+i(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
- Visual Studio์์ Alt+/๋ฅผ ๋๋ฆ ๋๋ค.
- JetBrains IDE์์: Control+Shift+i(Mac) ๋๋ Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
-
์ ํ:
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์๊ฒ ์ฌ๋ฌ ๊ฐ์ง ๋ณ๊ฒฝ์ ์์ฒญํ ์ ์๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค.
-
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"; }; }
-
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์(๋ฅผ) ์ฌ์ฉํ์ฌ ์ด๋ฌํ ๋ณ๊ฒฝ์ ์ํํ ์ ์์ต๋๋ค.
-
ํจ์ ์ด๋ฆ์ ์ปค์๋ฅผ ๋์ต๋๋ค.
-
์ธ๋ผ์ธ ์ฑํ ์ด๊ธฐ:
- VS Code์์: Command+i(Mac) ๋๋ Ctrl+i(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
- Visual Studio์์ Alt+/๋ฅผ ๋๋ฆ ๋๋ค.
- JetBrains IDE์์: Control+Shift+i(Mac) ๋๋ Ctrl+Shift+g(Windows/Linux)๋ฅผ ๋๋ฆ ๋๋ค.
-
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์์ ๋ณ์ ๋๋ ํจ์์ ๊ฐ์ ๊ธฐํธ์ ๋ํ ๋์ฒด ์ด๋ฆ์ ์ ์ํ ์ ์์ต๋๋ค.
-
๊ธฐํธ ์ด๋ฆ์ ์ปค์๋ฅผ ๋์ต๋๋ค.
-
F2 ํค๋ฅผ ๋๋ฆ ๋๋ค.
-
Visual Studio๋ง ํด๋น: Ctrl+Space๋ฅผ ๋๋ฆ ๋๋ค.
Copilot์(๋) ๋์ฒด ์ด๋ฆ์ ์ ์ํฉ๋๋ค.
-
๋๋กญ๋ค์ด ๋ชฉ๋ก์์ ์ ์๋ ์ด๋ฆ ์ค ํ๋๋ฅผ ์ ํํฉ๋๋ค.
ํ๋ก์ ํธ๊ฐ ์งํ๋๋ ๋์ ์ด๋ฆ์ด ๋ณ๊ฒฝ๋ฉ๋๋ค.