# Rewriting Code With AI

> Source: <https://www.dotnetperls.com/2026_7_13_rewriting-code-ai>
> Published: 2026-07-13 07:00:00+00:00

It has become **trendy** to **rewrite code** using **AI agents**. In my ongoing quest to become more trendy myself, I decided to try to fix a nagging issue in my Rust code base. I had written the Rust code without doc-comments; for some reason I just used inline comments instead.

I tried to use Gemma 4 12B and Qwen 3.6 35B to **rewrite** the code **directly**. With recent changes in `llama-cpp`

, this worked fairly well, but files were too large and the AI agents made mistakes.

Eventually, I changed my approach.

• I had Qwen 3.6 generate a Python script that would perform all the rewrites.

• The script, as Qwen 3.6 wrote it, used line-by-line parsing of Rust files to move comments and edit them.

• The script worked correctly on all 43 Rust files, although it missed about 20 multi-line function cases.

This task made me realize that using an LLM to **rewrite code directly** is not always the best approach. Instead, it might be better to have the LLM write a **Python script** that rewrites code files. This may be more reliable, and much faster.
