What You’ll Learn
- Request effective refactorings focused on outcomes, not implementation
- Refactor safely across multiple files with dependency management
- Request code quality improvements and optimization suggestions
- Handle large-scale refactoring projects with multi-phase approaches
- Optimize performance through algorithmic and architectural improvements
- Preserve code functionality during refactoring operations
Prerequisites
Before refactoring with Verdent:- Visual Studio Code with Verdent extension installed
- A codebase or project workspace open in VS Code
- Active Verdent subscription with available credits
- Version control (Git) recommended for safe rollback if needed
Requesting Effective Refactorings
Describe what you want to improve and why, rather than how to fix it. Let Verdent analyze the code and propose the best approach based on your project patterns. Effective Refactoring Requests: Focus on the outcome you want, not the implementation:- Analyze the code and identify all affected files
- Present a detailed refactoring plan before making changes
- Ask clarifying questions about implementation preferences
- Show exactly what will change and in what order
- Allow you to review and refine the approach
- Use Explorer to find all authentication code locations
- Identify patterns and inconsistencies
- Propose a unified authentication interface
- Show which files will be modified
- Explain the refactoring sequence
plan.md file for additional review and team discussion before execution.
Using Explorer for Comprehensive Searches:
For complex refactorings, explicitly ask Verdent to use the Explorer agent to search thoroughly:
Multi-File Refactoring
Verdent refactors across multiple files while maintaining imports, dependencies, and cross-file references. It identifies all affected files, updates them in the correct order, and ensures consistency throughout the codebase. How Multi-File Refactoring Works:- Discovery Phase: Verdent (using Explorer) finds all files that need changes
- Dependency Analysis: Identifies dependencies between files to determine update order
- Plan Creation: Shows all files to be modified and the sequence of changes
- Sequential Updates: Modifies files in dependency order (e.g., types before components that use them)
- Import Management: Automatically updates imports, exports, and cross-file references
- Verification: Checks that changes are consistent across all files
Multi-file refactoring preserves functionality through automated dependency tracking, Verdent updates all affected files atomically.
- Find all files importing or using
User - Identify type definitions, implementations, and usages
- Update type definitions first, then implementations, then usages
- Adjust all import statements
- Ensure consistency across the codebase
- Which files will be created (new AuthService)
- Which files will be modified (UserController and all importers)
- What code will move from UserController to AuthService
- How imports and dependencies will be updated
Requesting Code Quality Improvements
Verdent does not proactively suggest improvements without being asked. However, you can request code quality reviews and improvement suggestions at any time.- General Reviews
- Focused Reviews
Request broad code quality reviews:Verdent analyzes the code and provides specific suggestions for:
- Readability: Variable naming, function decomposition, comment clarity
- Performance: Algorithm complexity, redundant operations, caching opportunities
- Maintainability: Code duplication, coupling, separation of concerns
- Best Practices: Design patterns, error handling, testing coverage
- Security: Input validation, authentication checks, data exposure
Large-Scale Refactoring Projects
For large-scale refactoring, use Plan Mode with a multi-phase approach to get the most reliable results. Verdent breaks down the refactoring into manageable stages, allowing you to review and approve each phase before proceeding. Multi-Phase Refactoring Workflow:Phase 1: Initial Analysis
Use Plan Mode with the Explorer agent to identify all affected files and dependencies:- Identifies all authentication-related code
- Maps dependencies and integration points
- Assesses complexity and risk areas
- Proposes phase breakdown
Phase 2: Phase Planning
Verdent creates a multi-phase plan for review: Example Plan:- Phase 1: Add OAuth library and configure endpoints
- Phase 2: Update user model and database schema
- Phase 3: Migrate existing authentication logic
- Phase 4: Remove deprecated authentication code
- Phase 5: Update tests and documentation
- Files to be modified
- Estimated complexity
- Dependencies on previous phases
- Risk assessment
Phase 3: Phase-by-Phase Execution
Execute one phase at a time, testing between phases:- Approve Phase 1 in Plan Mode
- Switch to Agent Mode and execute
- Test thoroughly to verify Phase 1 works
- Return to Plan Mode for Phase 2
- Repeat until all phases complete
Phase 4: Iterative Refinement
Review results after each phase. If issues arise:- Adjust the plan for remaining phases
- Add corrective phases if needed
- Refine approach based on discoveries
Large-scale refactoring should always be done with version control. Commit after each phase so you can roll back if problems emerge without losing all progress.
Performance Optimization
Verdent analyzes code for performance bottlenecks and suggests optimizations including algorithm complexity improvements, efficient data structures, and resource usage reduction.- Algorithm Optimization
- Component Optimization
- API & Database Optimization
Improve algorithmic complexity:What Verdent Identifies:Verdent analyzes the function, identifies the inefficiency (nested loops or repeated linear searches), and proposes specific improvements:
- Algorithm Complexity: O(n²) loops, nested iterations, inefficient searches
- Redundant Computations: Repeated calculations, unnecessary operations
- Memory Issues: Memory leaks, excessive allocations, large object retention
- Replace nested loop with hash map for O(n) lookup
- Use binary search after sorting for O(log n) complexity
- Cache computed results to avoid redundant calculations
- Implement memoization for expensive operations
- Current complexity: Explanation of why current code is slow
- Proposed solution: Specific algorithm or data structure change
- Performance gain: Estimated improvement (e.g., O(n²) → O(n log n))
- Trade-offs: Memory usage, code complexity, maintainability considerations
Preserving Functionality During Refactoring
Verdent aims to preserve code functionality during refactoring by maintaining the same inputs, outputs, and behavior while improving the internal implementation. How Verdent Preserves Functionality:- Input/Output Analysis: Identifies function signatures, API contracts, and expected behaviors
- Test Awareness: Considers existing tests as behavioral specifications
- Conservative Changes: Makes minimal changes to achieve the refactoring goal
- Verification: Can generate or run tests to verify functionality is preserved
- Always test refactored code - Even with Verdent’s analysis, manual or automated testing verifies functionality is preserved, especially for complex refactorings
- Use version control - Commit before refactoring so you can roll back if issues emerge
- Refactor incrementally - Break large refactorings into smaller steps, testing after each change
- Review changes carefully - Examine the diff to understand what changed and why
- Use Plan Mode for complex refactorings - Review the approach before execution to catch potential issues
- Analyze current implementation and edge cases
- Propose refactored structure
- Explain why the refactored version is equivalent
- Suggest test cases to verify equivalence
Best Practices
Describe the problem, not the solution
Describe the problem, not the solution
Let Verdent analyze the code and propose the best refactoring approach rather than prescribing specific changes.
Always use Plan Mode for refactoring
Always use Plan Mode for refactoring
Review the complete plan before execution. This prevents surprises and allows you to refine the approach based on architectural considerations.
Explicitly use Explorer for comprehensive searches
Explicitly use Explorer for comprehensive searches
For thorough refactoring, ask Verdent to use Explorer to find all instances: “Use Explorer to find all manual error handling, then refactor to use our error utility.”
Break large refactorings into phases
Break large refactorings into phases
Multi-phase approaches with testing between phases are safer and more manageable than attempting everything at once.
Test between phases
Test between phases
Verify each phase works before proceeding to the next. This isolates issues and prevents compounding problems.
Commit frequently
Commit frequently
Use version control to create checkpoints after each phase or major change. This allows safe rollback without losing all progress.
Save plans for team review
Save plans for team review
For significant refactorings, request Verdent to save the plan to
plan.md for team discussion before execution.Provide context for optimization
Provide context for optimization
When requesting performance improvements, include information about data sizes, performance constraints, and acceptable trade-offs.