Implémentation incrémentale

VérifiéSûr

Guide structuré pour implémenter des fonctionnalités de manière incrémentale, en respectant les conventions et les modèles existants pour garantir la qualité et la cohérence du code.

Spar Skills Guide Bot
DeveloppementIntermédiaire
23/07/2026
Claude CodeCursorWindsurfCopilotCodex
#incremental-development#code-conventions#pattern-matching#code-consistency#code-quality

Recommandé pour

Synthèse automatique

Guide un agent pour implémenter des changements de code de façon incrémentale, en respectant les conventions du projet et les motifs existants par couche, avec des commentaires explicatifs.

Points forts

  • Impose la lecture des conventions et de 2 à 3 fichiers existants avant d’écrire du code.
  • Montre comment aligner le nouveau code sur les motifs de la même couche architecturale, avec des exemples corrects et incorrects.
  • Couvre plusieurs langages et illustre les conventions de nommage, de typage, de gestion d’erreurs et d’injection de dépendances.
  • Recommande de commenter uniquement la logique non évidente, en expliquant le pourquoi plutôt que le quoi.

Limites

  • Le SKILL.md s’arrête au début de l’étape 3, donc la partie sur les commentaires et les étapes suivantes est incomplète.
  • Dépend de l’existence d’un fichier de conventions ou d’un équivalent projet pour être pleinement applicable.
  • Ne fournit pas de procédure de vérification, de tests ou de retour arrière après l’implémentation.
Quand l'utiliser

À utiliser lorsqu’on ajoute une fonctionnalité, corrige un bug ou refactorise du code dans une base existante où la cohérence avec les conventions et motifs établis est importante.

Quand l'éviter

À éviter pour un projet entièrement nouveau sans conventions établies, ou lorsque la tâche exige d’introduire volontairement un nouveau motif architectural.

Analyse de sécurité

Sûr
Score qualité85/100

This is a pure instructional document describing coding conventions, pattern-matching, and commenting practices. It declares only edit/write/read tools and contains no bash execution, network calls, secret access, obfuscation, or destructive instructions. The examples are illustrative code snippets, not actions to execute. No meaningful execution risk.

Aucun point d'attention détecté

Comment cette analyse est faite

Exemples

Add an API endpoint
Add an endpoint to fetch a single order by ID. Read core-conventions.md and two existing route files first, then implement it matching the existing route pattern.
Refactor a service
Refactor the user service to use the same dependency injection style as the other services. Do not introduce new patterns.
Implement pagination
Implement pagination for the /products list endpoint, following the project conventions and adding comments only for non-obvious logic.

name: incremental-implementation description: Comprehensive guide for implementing code incrementally following established patterns, conventions, and quality standards languages: [python, typescript, javascript, go, rust, java, csharp, php, ruby] subagents: [code/feature, code/bug-fix, code/refactor] tools_needed: [edit, write, read]

Instructions

When implementing features or changes, follow this incremental, quality-focused approach:

Step 1: Follow Core Conventions Exactly

Purpose: Maintain codebase consistency and avoid introducing technical debt.

How:

  • Read core-conventions.md (or equivalent project conventions) before starting
  • Check language-specific conventions (Python, TypeScript, etc.)
  • Follow established patterns for:
    • Naming (variables, functions, classes, files)
    • Error handling (throw vs return, typed errors)
    • Imports (ordering, absolute vs relative)
    • Testing (framework, coverage, structure)
    • Database (ORM, migrations, queries)

Why this matters:

  • Inconsistent code confuses maintainers
  • Deviations from conventions create review friction
  • Following patterns reduces cognitive load when reading code

Example:

# ✅ Good - follows Python conventions
def calculate_total_price(items: list[Item]) -> Decimal:
    """Calculate total price including tax."""
    subtotal = sum(item.price for item in items)
    return subtotal * Decimal("1.08")  # 8% tax

# ❌ Bad - violates conventions
def calcTotalPrice(items):  # camelCase (wrong for Python), no types
    sub = 0  # unclear variable name
    for i in items:
        sub = sub + i.price  # verbose when comprehension works
    return sub * 1.08  # magic number, float instead of Decimal

Step 2: Match Existing Patterns in the Same Layer

Purpose: Keep similar code similar; don't introduce new patterns without reason.

How:

  1. Read 2-3 existing files in the same layer before writing new code
    • Same layer = same part of architecture (e.g., all API routes, all services, all models)
  2. Identify patterns:
    • How are functions/classes organized?
    • How are dependencies injected?
    • How are errors handled?
    • What naming patterns are used?
  3. Copy patterns, don't invent:
    • If existing routes use @router.get("/resource"), use that
    • If existing services use constructor injection, use that
    • If existing models use created_at/updated_at, use that

Why this matters:

  • Consistency makes code easier to navigate
  • New patterns increase maintenance burden
  • Patterns embody past decisions and domain knowledge

Example:

If existing API routes look like this:

# Existing pattern in routes/user_routes.py
@router.get("/users/{user_id}")
async def get_user(
    user_id: str,
    user_service: UserService = Depends(get_user_service),
) -> UserResponse:
    user = await user_service.get_by_id(user_id)
    if not user:
        raise HTTPException(status_code=404, detail="User not found")
    return UserResponse.from_model(user)

Then new routes should match:

# ✅ Good - matches existing pattern
@router.get("/orders/{order_id}")
async def get_order(
    order_id: str,
    order_service: OrderService = Depends(get_order_service),
) -> OrderResponse:
    order = await order_service.get_by_id(order_id)
    if not order:
        raise HTTPException(status_code=404, detail="Order not found")
    return OrderResponse.from_model(order)

# ❌ Bad - introduces new pattern without justification
@router.route("/orders/<order_id>", methods=["GET"])  # Different decorator style
def get_order_sync(order_id):  # Not async when others are
    service = OrderService()  # Direct instantiation, not dependency injection
    result = service.find(order_id)  # Different method name (find vs get_by_id)
    return jsonify(result)  # Different response pattern

Step 3: Add Inline Comments for Non-Obvious Logic

Purpose: Explain the WHY, not the WHAT. Help future readers (including yourself) understand intent.

When to add comments:

  • ✅ Complex algorithms - explain the approach
  • ✅ Magic numbers - explain what they represent
  • ✅ Workarounds - explain why the workaround is needed
  • ✅ Invariants - explain assumptions callers must maintain
  • ✅ Performance optimizations - explain why optimization is needed
  • ✅ External dependencies - explain API quirks or limitations

When NOT to add comments:

  • ❌ Restating what the code does (redundant)
  • ❌ Explaining obvious standard library functions
  • ❌ Translating code to English line-by-line

Examples:

# ✅ Good comments (explain WHY)

# Use exponential backoff to avoid overwhelming the API during rate limit recovery
for attempt in range(max_retries):
    delay = 2 ** attempt  # 1s, 2s, 4s, 8s, 16s
    await asyncio.sleep(delay)
    
# 86400 = seconds in a day (cache expires daily at midnight)
cache_ttl = 86400

# Intentionally not awaited - fire and forget analytics event
asyncio.create_task(track_user_action(user_id, "login"))

# WORKAROUND: API returns 200 with error in body instead of 4xx/5xx
# Remove this check when API v2 is deployed (see JIRA-1234)
if response.status == 200 and "error" in response.json():
    raise APIError(response.json()["error"])
# ❌ Bad comments (restate code)

# Get user by ID
user = await user_service.get_by_id(user_id)

# Check if user is None
if user is None:
    # Raise 404 error
    raise HTTPException(status_code=404)

# Return user response
return UserResponse.from_model(user)

Step 4: Add TODO Comments for Judgment Calls

Purpose: Flag decisions that need user review or future attention.

When to add TODOs:

  • ✅ Temporary workarounds - "This will break if X happens"
  • ✅ Incomplete implementations - "Add validation for edge case Y"
  • ✅ Performance concerns - "This is O(n²), optimize if dataset grows"
  • ✅ Missing error handling - "Handle timeout case"
  • ✅ Unclear requirements - "Confirm with user if this behavior is correct"
  • ✅ Technical debt - "Refactor to use repository pattern"

Format:

# TODO: [Category] Description (Owner, Date)
# TODO: Performance - Cache this query result (Alice, 2026-04-10)
# TODO: Security - Add rate limiting to this endpoint (Bob, 2026-04-10)
# TODO: Validation - Handle case where email is None (Charlie, 2026-04-10)

Categories:

  • TODO: Incomplete - Feature not fully implemented
  • TODO: Bug - Known issue to fix
  • TODO: Performance - Optimization needed
  • TODO: Security - Security concern
  • TODO: Refactor - Code quality improvement
  • TODO: Validation - Missing input validation
  • TODO: Testing - Missing test coverage
  • TODO: Documentation - Missing docs

Examples:

def process_payment(amount: Decimal, card_token: str) -> PaymentResult:
    # TODO: Security - Add fraud detection check before processing (Alice, 2026-04-10)
    # TODO: Performance - This calls payment API synchronously; make async (Bob, 2026-04-10)
    
    result = payment_gateway.charge(amount, card_token)
    
    # TODO: Incomplete - Handle gateway timeout (returns None currently) (Charlie, 2026-04-10)
    if result is None:
        return PaymentResult(status="failed", error="Gateway error")
    
    return result

Step 5: Implement One File at a Time

Purpose: Reduce context switching, make reviews easier, minimize merge conflicts.

How:

  1. Complete one file fully before moving to the next
    • Write the implementation
    • Add inline comments
    • Add TODOs if needed
    • Verify it compiles/passes type checks
  2. Commit frequently (optional, but recommended)
    • One commit per file or logical change
    • Makes rollback easier if needed
  3. Don't jump between files during implementation
    • Finish what you started
    • Reduces mental context switching

Why this matters:

  • Easier to review: Reviewers can focus on one file at a time
  • Fewer merge conflicts: Changes are localized
  • Better focus: Less context switching improves code quality
  • Easier rollback: If one file has issues, only that file needs rework

Anti-pattern:

# ❌ Bad - jumping between files
1. Start implementing user_service.py
2. Realize you need UserRepository, switch to user_repository.py
3. Realize repository needs User model, switch to models.py
4. Go back to user_service.py, half-implement
5. Switch to user_routes.py to add API endpoint
6. Back to user_service.py to finish

Good pattern:

# ✅ Good - one file at a time
1. Implement models.py (User model) - COMPLETE
2. Implement user_repository.py (UserRepository) - COMPLETE
3. Implement user_service.py (UserService) - COMPLETE
4. Implement user_routes.py (API routes) - COMPLETE
5. Implement tests/test_user_service.py - COMPLETE

Common Mistakes

❌ Mistake 1: Ignoring Existing Patterns

Problem: Introducing a new pattern when an existing one works.

Example:

# Existing pattern (constructor injection)
class UserService:
    def __init__(self, repo: UserRepository):
        self.repo = repo

# ❌ New code introduces different pattern (property injection)
class OrderService:
    @property
    def repo(self) -> OrderRepository:
        return get_repository()  # Global lookup instead of injection

Fix: Match the existing pattern (constructor injection).


❌ Mistake 2: Over-Commenting

Problem: Commenting what the code already says.

Example:

# ❌ Bad
# Loop through items
for item in items:
    # Add item price to total
    total += item.price

# ✅ Good (no comment needed - code is self-explanatory)
for item in items:
    total += item.price

# ✅ Good (comment explains WHY, not WHAT)
# Sum prices excluding items marked as promotional (they're free)
for item in items:
    if not item.is_promotional:
        total += item.price

❌ Mistake 3: Implementing Multiple Files in Parallel

Problem: Jumping between files before completing any.

Why it's bad:

  • Half-finished files are harder to review
  • Increases merge conflict risk
  • Harder to track progress
  • More mental context switching

Fix: Finish one file completely before starting the next.


❌ Mistake 4: Not Reading Existing Code First

Problem: Writing code without understanding existing patterns.

Example:

  • Writing sync code in an async codebase
  • Using different error handling than the rest of the codebase
  • Naming variables differently than existing conventions

Fix: Read 2-3 similar files before writing new code.


❌ Mistake 5: TODOs Without Context

Problem: Writing vague TODOs that don't explain what needs to be done.

Bad:

# TODO: fix this
# TODO: improve
# TODO: check

Good:

# TODO: Performance - Cache this query result to avoid N+1 problem (Alice, 2026-04-10)
# TODO: Security - Add rate limiting to prevent brute force (Bob, 2026-04-10)
# TODO: Validation - Check that email is not already registered (Charlie, 2026-04-10)

Examples

Example 1: Implementing a New Service

Context: Adding OrderService to an existing codebase

Step 1: Read existing services

# Read 2-3 existing services to understand patterns
cat services/user_service.py
cat services/product_service.py
cat services/payment_service.py

Step 2: Match pattern

# ✅ Good - matches existing pattern
class OrderService:
    """Service for managing orders."""
    
    def __init__(self, repo: OrderRepository):
        """Initialize with repository dependency."""
        self.repo = repo
    
    async def create_order(self, user_id: str, items: list[OrderItem]) -> Order:
        """Create new order for user.
        
        Args:
            user_id: ID of user placing order
            items: List of items in order
            
        Returns:
            Created order
            
        Raises:
            ValidationError: If items list is empty
            UserNotFoundError: If user doesn't exist
        """
        if not items:
            raise ValidationError("Order must have at least one item")
        
        # TODO: Validation - Check that all items are in stock (Alice, 2026-04-10)
        
        # Calculate total (excluding promotional items per business rules)
        total = sum(item.price for item in items if not item.is_promotional)
        
        order = Order(
            user_id=user_id,
            items=items,
            total=total,
            status=OrderStatus.PENDING,
        )
        
        return await self.repo.create(order)

Example 2: Adding Inline Comments

Without comments (unclear intent):

def calculate_discount(price: Decimal, user: User) -> Decimal:
    if user.created_at < datetime.now() - timedelta(days=365):
        return price * Decimal("0.9")
    return price

With good comments (intent is clear):

def calculate_discount(price: Decimal, user: User) -> Decimal:
    """Apply loyalty discount for long-term users.
    
    Users who joined > 1 year ago get 10% discount as loyalty reward.
    This is a business requirement from Product (see PRD-2024-Q3-05).
    """
    one_year_ago = datetime.now() - timedelta(days=365)
    
    if user.created_at < one_year_ago:
        return price * Decimal("0.9")  # 10% discount
    
    return price

Summary

Key Principles:

  1. Consistency over cleverness - Match existing patterns
  2. Explain why, not what - Comment intent, not implementation
  3. One thing at a time - Complete files before moving on
  4. Flag uncertainties - Use TODOs for judgment calls
  5. Read before writing - Understand context first

Benefits:

  • Easier code reviews
  • Fewer merge conflicts
  • Better maintainability
  • Higher code quality
  • Reduced cognitive load

Next Steps:

  • After implementing, use post-implementation-checklist skill
  • Before implementing, use feature-planning skill

Du fichier au premier essai

Le téléchargement contient exactement le contenu affiché sur cette fiche. Cette copie peut différer de la dernière version du dépôt source.

Consulter la source et ses fichiers annexes

Ce téléchargement contient uniquement SKILL.md. Les scripts, références, modèles et dépendances éventuels ne sont pas inclus. Récupérez les fichiers nécessaires depuis la source en conservant leur arborescence avant de poursuivre.

1. Télécharger le fichier

Télécharger SKILL.md

Depuis la racine d’un projet de test, enregistrez le fichier sous .skill-downloads/incremental-implementation-mrx3xyui/SKILL.md, ou utilisez la commande suivante. Ce dossier sert à examiner la skill avant son installation.

Commande pour macOS/Linux ou WSL : un shell POSIX et curl sont nécessaires. Sous Windows sans WSL, utilisez le bouton de téléchargement et créez le dossier manuellement.

mkdir -p '.skill-downloads/incremental-implementation-mrx3xyui' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/incremental-implementation-mrx3xyui/download' --output '.skill-downloads/incremental-implementation-mrx3xyui/SKILL.md.part' && mv '.skill-downloads/incremental-implementation-mrx3xyui/SKILL.md.part' '.skill-downloads/incremental-implementation-mrx3xyui/SKILL.md'

2. Vérifier les prérequis

Lisez SKILL.md avant de l’utiliser. Si le fichier cite des scripts ou services externes, examinez-les et préparez les accès nécessaires dans votre environnement de test.

Aucune section de prérequis reconnue dans ce fichier. Cela ne signifie pas qu’il est autonome : les bibliothèques, outils et accès peuvent être cités ailleurs dans le contenu ou dans le dépôt source.

Les plateformes de la fiche sont des indications du catalogue. Les chemins ci-dessous suivent la documentation des outils ; ils ne prouvent pas que cette skill y a été exécutée. Aucune version minimale de ces outils n’est attestée pour cette fiche.

3. Charger la skill

Après vérification, copiez le dossier complet dans le projet avec l’une des commandes ci-dessous, puis ouvrez une nouvelle session de l’outil. La commande s’arrête si un dossier du même nom existe déjà : comparez les fichiers avant de le remplacer.

Claude Code
test -f '.skill-downloads/incremental-implementation-mrx3xyui/SKILL.md' && test -s '.skill-downloads/incremental-implementation-mrx3xyui/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/incremental-implementation' && cp -R '.skill-downloads/incremental-implementation-mrx3xyui' '.claude/skills/incremental-implementation'

Cursor
test -f '.skill-downloads/incremental-implementation-mrx3xyui/SKILL.md' && test -s '.skill-downloads/incremental-implementation-mrx3xyui/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/incremental-implementation' && cp -R '.skill-downloads/incremental-implementation-mrx3xyui' '.cursor/skills/incremental-implementation'

Codex
test -f '.skill-downloads/incremental-implementation-mrx3xyui/SKILL.md' && test -s '.skill-downloads/incremental-implementation-mrx3xyui/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/incremental-implementation' && cp -R '.skill-downloads/incremental-implementation-mrx3xyui' '.agents/skills/incremental-implementation'

OpenSkills

OpenSkills doit déjà être installé. La procédure locale install/read est contrôlée avec OpenSkills 1.5.0, qui exige Node.js ≥ 20.6.0. Aucun slug du catalogue n’est résolu automatiquement.

Installation officielle d’OpenSkills
openskills install './.skill-downloads/incremental-implementation-mrx3xyui'

openskills read 'incremental-implementation-mrx3xyui'

La lecture doit afficher le contenu du fichier installé et son dossier de base. Elle ne lance ni la skill ni ses dépendances.

Pour un agent qui lit AGENTS.md, synchronisez ensuite l’index. Cette commande modifie AGENTS.md : relisez le diff avant de l’utiliser.

openskills sync

Mode manuel ou autre outil : joignez SKILL.md à une conversation, ou ouvrez-le dans un agent capable de lire les fichiers. Ajoutez les ressources annexes nécessaires. Il n’existe pas de dossier universel reconnu par tous les outils.

4. Faire un premier essai

Utilisez une entrée courte et fictive : un endpoint d’API, un petit document ou un brief d’interface. Dans une nouvelle conversation, joignez le fichier ou donnez son chemin à l’agent, puis adaptez cette demande :

Lis .skill-downloads/incremental-implementation-mrx3xyui/SKILL.md et applique ses instructions à cet exemple : [décrire une entrée de test]. Indique les fichiers, dépendances ou accès qui manquent. Produis le résultat demandé par la skill sans inventer de données ni exécuter de script non examiné.

Résultat attendu : une sortie correspondant aux instructions de la skill, ou une liste précise des prérequis manquants. Une simple confirmation de lecture ne valide pas le premier usage. Si une ressource externe est indisponible, ce parcours reste à tester.

Skills similaires