AI 搭載の IDE は、開発の高速化、定型文の煩わしさの軽減、即時の提案など、コーディング方法を変えています。しかし、対処する必要がある技術的な現実があります。 AI は だけでなく、 。💥 コーディングを加速する バグも加速します さまざまな環境で を使用した結果、AI は通常「間違った」コードを生成しないことに気づきました。その代わりに、重要なビジネス コンテキストとドメイン知識が欠落している技術的に正しいソリューションを生成します。 Cursor、Copilot、Windsurf AI コーディング アシスタントが一般的に間違える点は次のとおりです。 1. AIは微妙で発見しにくいパフォーマンスの問題を引き起こす ❌ AI提案: 効率的に見えるが、微妙なN+1クエリの問題がある const getUsersWithOrders = async (): Promise<UserWithOrders[]> => { // Fetch all users - seems reasonable const users = await prisma.user.findMany({ where: { status: 'ACTIVE' } }); // For each user, get their orders - the subtle N+1 query issue const usersWithOrders = await Promise.all( users.map(async (user) => { const orders = await prisma.order.findMany({ where: { userId: user.id }, orderBy: { createdAt: 'desc' }, take: 5 // Just get recent orders }); return { ...user, orders }; }) ); return usersWithOrders; }; ✅ より良い解決策: 適切な関係を持つ単一の効率的なクエリ const getUsersWithOrders = async (): Promise<UserWithOrders[]> => { // One efficient query with proper inclusion of related data const users = await prisma.user.findMany({ where: { status: 'ACTIVE' }, include: { orders: { orderBy: { createdAt: 'desc' }, take: 5, } } }); // Server-side data transformation if needed return users.map(user => ({ ...user, orders: user.orders, // Transform any data if required totalSpent: user.orders.reduce((sum, order) => sum + order.total, 0) })); }; 2. AIは既存のコードベースと統合する際にコンテキスト制約を無視する interface User { id: string; name: string; email: string; } const getUserDetails = async (userId: string): Promise<User> => { const response = await fetch(`/api/users/${userId}`); if (!response.ok) throw new Error('Failed to fetch user'); return await response.json(); }; ✅ より良い解決策: 確立されたアプリケーションパターンに従う import { ApiService } from '@/services/api'; import { User } from '@/types/user'; import { handleApiError } from '@/utils/error-handling'; export const getUserDetails = async (userId: string): Promise<User> => { try { return await ApiService.get<User>(`users/${userId}`); } catch (error) { return handleApiError(error, 'Failed to fetch user details'); } }; 3. AIは合理的な仮定を立てるが、ドメイン固有の要件を満たさない ❌ AI提案: 技術的に正しい割引計算 const calculateDiscount = (price: number, discountPercent: number): number => { const discountAmount = price * (discountPercent / 100); return price - discountAmount; }; ✅ より良い解決策: ビジネスルールとフォーマットを組み込む const calculateDiscount = (price: number, discountPercent: number): number => { // Company policy: Maximum discount is 40% unless approved const effectiveDiscount = Math.min(discountPercent, 40); // Business rule: Discounts are calculated after tax in our system const priceWithTax = addTax(price); const discountAmount = priceWithTax * (effectiveDiscount / 100); // Format to company standard: always round to nearest cent return Number((priceWithTax - discountAmount).toFixed(2)); }; 🚀 真実は? AI は悪いコードを書くのではなく、ただあなたの心を読むことができないだけ パターンは明らかです。AI は、構文的に正しく、アルゴリズム的に健全なコードを生成することに優れています。一貫して欠けているのは次の点です。 - 特定の企業ポリシーを知ることはできません ビジネスコンテキストとドメインルール - コードベースのパターンの理解が限られている プロジェクト固有の慣習 - システム全体ではなく、手元の機能に焦点を当てる アーキテクチャ上の意味合い - 実稼働環境で重要な最適化 大規模なパフォーマンス ✅ AIツールを効果的に使う方法 1. 。AI は反復パターンの生成に優れていますが、大規模なシステムでコンポーネントがどのように接続されるかを見逃してしまうことがよくあります。 AI は定型文用に確保しますが、統合ポイントを慎重に確認します 2. – 文脈に沿った正確なプロンプトを作成する 🚫 「データ取得用の TypeScript React フックを生成する」 ✅ 「既存のエラー処理パターンに従い、アンマウント時のクリーンアップを含み、古いリクエストを処理するデータ取得用の TypeScript React フックを生成する」 3. AI が見逃す可能性のあるエッジケースを検証します。 describe('calculateDiscount', () => { it('correctly calculates a 20% discount on $100', () => { expect(calculateDiscount(100, 20)).toBe(80); }); it('handles zero price', () => { expect(calculateDiscount(0, 15)).toBe(0); }); it('handles zero discount', () => { expect(calculateDiscount(50, 0)).toBe(50); }); it('handles decimal precision correctly', () => { expect(calculateDiscount(9.99, 10)).toBe(8.99); }); it('rejects negative prices', () => { expect(() => calculateDiscount(-10, 20)).toThrow(); }); it('rejects invalid discount percentages', () => { expect(() => calculateDiscount(100, 101)).toThrow(); expect(() => calculateDiscount(100, -5)).toThrow(); }); }); これらは従来の意味での「バグ」ではなく、むしろ根本的な制限です。AI は、熟練したチーム メンバーのように、ビジネス ドメイン、会社の標準、またはアプリケーション アーキテクチャの完全なコンテキストを理解することはできません。 🚀 AI は強力なツールですが、CTO ではありません。 結論は? 批判的に考え、積極的にレビューし、スマートにコードを記述してください。 📢 「エンジニアのログ」では、AI、Web3、ソフトウェア エンジニアリングの世界を、くだらない話抜きで解き明かします。詳細な分析、コーディングのベスト プラクティス、実際のデバッグ ストーリーをご覧になりたい方は、ぜひご登録ください。 🛠 ニュースレターに登録する → エンジニアのログ