Tutorial: Coding Assistance
Goal: Explain and refactor a complex piece of legacy code. Level: Advanced Time: 3 minutes
Scenario
You are looking at a confusing C# function in Visual Studio and don't understand what it does.
Step 1: Select Code
Highlight the function in your IDE:
public void P(int a) {
if (a > 10) Console.WriteLine("X");
else Console.WriteLine("Y");
// ... more spaghetti code ...
}
Step 2: Trigger Rephlo
Press Ctrl+Shift+Alt+C.
Step 3: Run "Explain Code"
Execute a command with the prompt: "Explain this code step-by-step and suggest improvements."
Step 4: Review Explanation
Rephlo provides a breakdown:
- Explanation: "The function
Ptakes an integer... It prints X if..." - Issues: "Variable names are non-descriptive. Logic is nested too deeply."
Step 5: Refactor
Now run a second command on the same selection: "Refactor Code".
Prompt: "Rename variables to be descriptive and simplify logic."
Output:
public void ProcessThreshold(int thresholdValue)
{
string message = thresholdValue > 10 ? "X" : "Y";
Console.WriteLine(message);
}
Step 6: Copy
Click Copy and paste the clean code back into Visual Studio.