DEV Community

Maxim Saplin
Maxim Saplin

Posted on • Updated on

"Smart" Refactoring with AI 〉beyond Old School Refactors

What is particularly useful in modern AI coding assistants is doing small but distracting things.

Flutter text widget refactored with AI

Traditional refactoring tools in our IDEs have long helped improve code structure and readability. But they can be rigid and tedious to use through menus and dialogs.

Code refactoring is getting smarter. Today AI assistants are taking refactoring to the next level with natural language commands. Instead of picking from predefined options, you can describe changes in your own few words.

Why do they work so great? Small tasks limit the scope for hallucinations by Large Language Models and are easy to verify by the developer. They also help focus and avoid doing the irritating small things.

In the video above, I spent 10 seconds adding text styles to the Text widget. Something requiring remembering how that must be done, scrolling through autocomplete, picking all the fields (I don't keep those things in my head and rely on IntelliSense/hints from IDE), and typing in multiple lines. My ballpark is I saved ~80% of my time on this small task.

P.S.:
There are plenty of tools with that kind of feature. They are similar and use some chat completion API (e.g. OpenAI or Azure). I use this VSCode extension, which is tailored to making fewer clicks and getting the result applied to the editor instantly.

P.P.S.:
What I also found extremely satisfying with that kind of "smart" refactoring is creating a set of dark styles. By putting a cursor in .css or .dart (file with styles defined) and prompting "please add dark theme" I usually received a 95% working set of styles with minor adjustments required. Though it might not work in complicated setups (e.g. Tailwind and multiple files)

Top comments (0)