Skip to content
Notifications
Clear all

My results after asking 5 assistants to refactor the same messy function.

6 Posts
6 Users
0 Reactions
3 Views
(@lisa_m_revops)
Trusted Member
Joined: 3 months ago
Posts: 42
Topic starter   [#5861]

I keep seeing claims about AI assistants being able to "refactor" and "clean up" code. I decided to put that to a real, messy test. I took an actual, convoluted Salesforce Apex function from a legacy org—think nested loops, magic strings, and side effects—and gave the same prompt to five different assistants.

The prompt was: "Refactor this Apex function for clarity and performance. Maintain all functionality."

Here's what I got back across Claude 3.5 Sonnet, GPT-4o, Gemini 1.5 Pro, an enterprise-grade coding assistant we're testing, and the much-hyped new open-source one.

* **Claude:** Best overall. It extracted constants, broke the monster loop into two separate methods, and added sensible comments. It actually understood the Salesforce context of the SOQL query.
* **GPT-4o:** Aggressive and "clever." It tried to introduce a map for lookups that changed the logic slightly. It failed to preserve functionality, which is a critical fail in my book.
* **Gemini:** Surface-level only. It just renamed some variables and formatted the code. The core structural problems remained untouched.
* **Enterprise Assistant:** Safe and corporate. It followed our team's specific style guide to the letter but was afraid to change the nested if-statement logic, missing the biggest performance gain.
* **Open-Source Model:** Hallucinated a non-existent Apex method. The code looked cleaner but wouldn't compile.

The takeaway? Most of them are just advanced syntax formatters right now. Only one out of five delivered a correct, improved refactor. The others either broke it, barely touched it, or made up capabilities.

If you're looking at these tools for actual refactoring work, you need to watch out for:
* Logic changes disguised as optimizations.
* Ignorance of platform-specific limits (like SOQL in loops).
* Style over substance.

Show me the workflow.


Lisa M.


   
Quote
(@lizzieb)
Eminent Member
Joined: 1 week ago
Posts: 18
 

That's fascinating, especially the part about GPT-4o changing the logic. I think that's the scariest possible outcome for us - getting a "cleaner" version that just breaks things.

I've found Claude is usually best with Salesforce-specific stuff too. It seems to know Governor Limits without being told. Can I ask what the enterprise one got wrong by being too safe? Did it just not go far enough?



   
ReplyQuote
(@jordanp)
Trusted Member
Joined: 1 week ago
Posts: 44
 

Totally agree on Claude getting the Salesforce context. That SOQL governor limit awareness is huge.

On the enterprise assistant being too safe, that's exactly it. In my tests, they often just apply rigid formatting rules - like standardizing variable casing - and call it a day. They won't touch a problematic nested loop structure if there's any chance, however small, that the change could be questioned in a code review. It ends up being a very expensive linter.

What was the open-source model's result like? I've found they can be wildly inconsistent, sometimes brilliant, sometimes introducing bizarre syntax.


Comparing tools one review at a time.


   
ReplyQuote
(@martech_wanderer)
Eminent Member
Joined: 3 months ago
Posts: 25
 

Oh, the open-source one was a total mixed bag, just like you said. It gave me two completely different versions between runs. One was oddly elegant, using a map for deduplication in a way I hadn't considered. The other introduced a syntax error by trying to use a Java-style stream operation that doesn't exist in Apex. It felt like it was pulling from multiple language contexts without a strong filter.

That inconsistency is exactly why I can't trust them for anything mission-critical yet. It's like getting advice from a savant who occasionally just starts speaking in tongues.

You're spot on about the "expensive linter" problem with the enterprise tools. They're optimized for zero risk, which means they miss the whole point of a refactor, which is to improve the design, not just the whitespace.


automate the boring stuff


   
ReplyQuote
(@larryh)
Trusted Member
Joined: 1 week ago
Posts: 42
 

Exactly right on the enterprise one being too safe. It was like watching someone dust a burning building. It fixed the variable naming and formatted the SOQL query nicely, but completely ignored the seven-layer nested if-statement that was the actual problem. It left a comment saying "complex logic preserved." Thanks, pal.

The logic change from GPT is the silent killer. Claude might miss an edge case, but it won't rewrite your business rules. GPT sometimes decides it knows a "better" way to calculate a commission tier and just... implements it. Terrifying.

You get what you pay for, I guess. The expensive one promises it won't break anything, and it delivers by barely touching anything at all.



   
ReplyQuote
(@crm_hopper_2026)
Reputable Member
Joined: 3 months ago
Posts: 164
 

Your point about the open-source model's inconsistency is what makes them a non-starter for production refactoring, in my view. That "bizarre syntax" you mention often comes from them conflating language paradigms. I've seen one try to implement a Python-style list comprehension inside Apex, which just created a compile-time error and wasted an hour of debugging.

The occasional brilliance is tantalizing, but it's not reliable. It's like having a junior dev who sometimes has a flash of architectural genius but can't consistently write a working SOQL query. For any serious Salesforce work, that unpredictability is a greater liability than the enterprise tool's excessive caution. At least the cautious one leaves a functioning, if ugly, codebase.



   
ReplyQuote