看看 Claude Code 的實際應用

使用 Claude Code 進行軟體開發

Dani Zysman

AI Curriculum Manager @ DataCamp

使用 Claude Code 進行軟體開發

Claude Code 的定位

Claude 產品層級:Web Chat、Desktop App、Terminal CLI

  • Claude.ai:聊天介面,一般任務
  • Claude Desktop:具檔案存取的 App
  • Claude Code:終端機介面,為程式開發打造
使用 Claude Code 進行軟體開發

開始使用

$ curl -fsSL https://claude.ai/install.sh | bash

更多資訊請參考:{https://code.claude.com/docs/en/overview}

$ cd /path/to/your/project
$ claude

常用指令:

  • /clear 清除對話紀錄
  • /exit 或 Ctrl + C 結束工作階段
  • /help 顯示可用指令
使用 Claude Code 進行軟體開發

面對難讀的程式碼

def process_data(records, threshold=0.5):
    result = []
    for r in records:
        if r.get('value') and r['value'] > threshold:
            x = r['value'] * 1.1 if r.get('premium') else r['value']
            result.append({'id': r['id'], 'adjusted': x, 'flag': x > 1})
    return sorted(result, key=lambda d: d['adjusted'], reverse=True)[:10]
  • 變數為單字母
  • 無註解
  • 邏輯過度壓縮
使用 Claude Code 進行軟體開發

Claude 的說明與文件化

> What does process_data() do?
process_data(): 篩選、調整與排序

Filter:保留 value > threshold(預設:0.5)
Adjust:若 premium=True,提升 10%
Transform:輸出 id、adjusted 值,以及 flag(若 adjusted > 1)
Sort:依 adjusted 遞減取前 10 筆
> Add a docstring to process_data()
"""篩選超過門檻的紀錄,對 premium 加成 10%,並回傳 adjusted 值最高的前 10 筆。"""
使用 Claude Code 進行軟體開發

找出程式錯誤

def add_item(item, item_list=[]):
    item_list.append(item)
    return item_list

你看出問題了嗎?

使用 Claude Code 進行軟體開發

Claude 找到並修好錯誤

> Find the bug in add_item() and fix it
已找到並修正:問題在可變動的預設參數。

使用 item_list=[] 代表所有未提供 list 參數的 add_item() 呼叫
會共用同一個預設 list 物件,導致項目在多次呼叫間累積。

def add_item(item, item_list=None): if item_list is None: item_list = [] item_list.append(item) return item_list
使用 Claude Code 進行軟體開發

疑難排解

問題 解法
「Context window exceeded」 使用 /clear 重設
觸發速率限制 稍候再試
結果不佳 將提示聚焦於單一任務
使用 Claude Code 進行軟體開發

回饋循環

開發循環:Describe、Generate、Review、Refine

使用 Claude Code 進行軟體開發

一起來練習吧!

使用 Claude Code 進行軟體開發

Preparing Video For Download...