Documentation
Coding Studio

Refactor Tool

Detect code smells, get safe refactoring plans, and see before/after diffs. Improve code quality without changing behavior.

Keyboard shortcut: Cmd/Ctrl + 3

What It Does

The Refactor tool analyzes your code for quality issues and provides safe, behavior-preserving improvements:

Code Smell Detection

Identifies long methods, deep nesting, duplicate code, magic numbers, poor naming, and other maintainability issues.

Best Practices

Applies language-specific best practices, SOLID principles, and clean code guidelines from industry standards.

Visual Diffs

See exactly what changes are proposed with syntax-highlighted, line-by-line comparisons before applying.

Safe Transformations

All refactoring suggestions preserve behavior. The tool explains why each change is safe and what it improves.

How to Use

1

Select Refactor Tool

Click the Refactor button (purple icon) or pressCmd/Ctrl + 3.

2

Paste Your Code

Enter code that you suspect could be improved. Functions, classes, or modules work best.

3

Click "Refactor Code"

Run the analysis. The tool uses high-quality models for architecture and pattern recognition.

4

Review Suggestions

Read the improvement suggestions in the Result tab. Each issue includes severity, explanation, and the proposed fix.

5

Check the Diff

Switch to the Diff tab to see a visual comparison of your original code vs. the refactored version.

6

Apply Changes

Click "Apply Changes" to update your code. Use "Revert" if you want to undo.

Example

Here's code with several code smells:

duplicates.pyPython
def find_duplicates(items):
    """Find all duplicate items in a list."""
    duplicates = []
    for i in range(len(items)):
        for j in range(i + 1, len(items)):
            if items[i] == items[j]:
                if items[i] not in duplicates:
                    duplicates.append(items[i])
    return duplicates

The Refactor tool would identify:

  • Issue: O(n²) complexity with nested loops
  • Issue: Using list for membership checks (O(n) per check)
  • Suggestion: Use Counter or defaultdict for O(n) solution
  • Suggestion: Use set for O(1) membership checks

Refactored version:

duplicates_refactored.pyPython
from collections import Counter

def find_duplicates(items):
    """Find all duplicate items in a list."""
    counts = Counter(items)
    return [item for item, count in counts.items() if count > 1]

Code Smells Detected

Code SmellDescription
Long MethodFunctions exceeding 20-30 lines that should be split
Deep NestingMore than 3 levels of indentation
Magic NumbersHard-coded values that should be named constants
Duplicate CodeSimilar code blocks that could be extracted
Poor NamingVariables like x, temp, data that lack clarity
God ObjectsClasses doing too much that should be split
Inefficient AlgorithmsCode with unnecessary complexity

Behavior Preservation

Refactoring should never change what your code does, only how it's structured. The tool prioritizes safe transformations and warns about any changes that might affect behavior.