スキルを使う

Claude Code によるソフトウェア開発

Dani Zysman

AI Curriculum Manager @ DataCamp

リファクタリングとは?

Excalidraw: リファクタリングの概念 - コード構造は変わるが動作は同じまま

Claude Code によるソフトウェア開発

ユニットテストが安全なリファクタリングを可能にする

安全なリファクタリングの流れ: テスト実行、リファクタリングスキル適用、レビュー、再テスト、問題なければコミット

Claude Code によるソフトウェア開発

ここまでのプロジェクト

music-analytics-api/
  app.py
  routes.py
  test_routes.py     # <- Generated by unit-tests skill
  models.py
  CLAUDE.md
  .claude/
    agents/
    skills/
      unit-tests/    # From previous video
        SKILL.md
      refactor/      # NEW: safe refactoring
        SKILL.md
Claude Code によるソフトウェア開発

呼び出しの2つの方法

スキルを呼び出す2つの方法: スラッシュコマンドによる手動呼び出しと、Claudeが一致した際の自動呼び出し

Claude Code によるソフトウェア開発

スキルを使ったコードのリファクタリング

>/unit-tests @routes.py
Added unit tests:

Key Testing Patterns:
- Uses Flask test client for realistic HTTP testing
- Mocks external dependencies (music_store, analytics functions)
- Tests both happy paths and edge cases
- Includes validation of response formats and structure
- All tests are isolated with proper fixtures
The test file is ready to use and integrates with the project's existing pytest.
Claude Code によるソフトウェア開発

スキルを使ったコードのリファクタリング

> /refactor @routes.py
Refactoring Complete
Changes made:
- Extracted _prepare_albums_for_stats(). Eliminates 9-line 
  list comprehension, makes intent clear
- Extracted _prepare_albums_for_average(). Removes duplicated 
  album-to-dict conversion logic
Benefits:
- Less duplication
- Cleaner route handlers
- Centralized data preparation

All 21 tests pass: behavior fully preserved
Claude Code によるソフトウェア開発

スキルが一貫性を保証する

スキルなし: 一貫性がなくエラーが起きやすい。スキルあり: 一貫性があり信頼できる

Claude Code によるソフトウェア開発

練習しましょう!

Claude Code によるソフトウェア開発

Preparing Video For Download...