Webinar

Using AI to Refactor Legacy Code: A Practical Guide

With

Scott Wierschem

13 May 2025

Legacy code is everywhere—and often, it's a bottleneck to innovation. In this hands-on session, we’ll show how large language models like GPT can be leveraged to understand, document, and refactor outdated codebases. You’ll learn techniques for using AI to identify smells, suggest modern patterns, and generate tests, even without full context. Ideal for software engineers and technical leads, this talk brings practical workflows you can use immediately to breathe new life into old systems. Learn: What tools are available to help refactor legacy code, What their strengths and limitations are, Next steps in starting to use this technology on your code today

Embracing AI for Legacy Code Refactoring

Scott Wierschem, a seasoned Java expert with extensive industry experience, delivered an insightful talk on leveraging AI to tackle the often daunting task of refactoring legacy code. Wierschem opened with an acknowledgment that resonates with many developers: “the code you wrote last week is already legacy code.” This underscores the urgency of managing and improving the vast amounts of old code that underpin much of today's enterprise software.

Comparing AI Tools for Code Improvement

In a live demonstration, Wierschem evaluated several AI tools by submitting a common function found in many real-world codebases. His assessment included ChatGPT, Microsoft Copilot, Google Gemini, Grok, and Claude. Each tool’s performance was methodically summarized, highlighting their strengths and weaknesses:

  • ChatGPT excelled in identifying better stream idioms and potential Unicode uppercasing issues, while also pointing out vague function naming and the use of non-specific imports.

  • MS Copilot provided similar insights but added the recommendation to run filters before mapping transforms for improved code clarity.

  • Google Gemini focused on idiomatic Java practices but overlooked the Unicode length issue, a gap that ChatGPT was quick to notice.

  • Grok was highlighted as the standout tool, addressing non-idiomatic stream usage, Unicode pitfalls, and the non-thread-safe nature of ArrayLists. It also suggested handling null inputs more effectively.

  • Claude repeated warnings about Unicode handling but missed Java-specific style issues.

Wierschem's evaluation emphasized the importance of using multiple AI tools to provide a comprehensive review, akin to seeking feedback from colleagues.

AI in Debugging and Large-Scale Refactoring

Wierschem shared a personal anecdote about using an AI assistant named Juni to debug a legacy application. When faced with a method returning null, Juni quickly identified a missing override in a key method, saving him significant time. This example highlighted the potential of AI tools to provide crucial insights and speed up debugging processes.

Discussing large-scale refactoring, Wierschem praised tools like OpenRewrite, Codo, and Refact.ai for their ability to automate routine refactors. He cited a case study from the Approval Tests project, where Juni effectively refactored file path logic across numerous functions, revealing optimization opportunities that the team hadn’t initially considered.

Conclusion: A Pragmatic Multi-Tool Approach

Throughout his talk, Wierschem maintained a tone of cautious optimism regarding AI’s role in legacy code modernization. He acknowledged the limitations such as context issues and occasional AI insight gaps but advocated for a pragmatic approach that combines multiple tools. His key takeaway: "If we don’t nail [legacy code refactoring], anything else being built is probably going to be obsolete." Developers are encouraged to actively experiment, compare tools, and engage with the community to stay abreast of best practices in this rapidly evolving field.


About The Speaker

Scott Wierschem

Founder, Keep Calm and Refactor

With over 40 years of software development experience, Scott has seen a lot of tools and technologies come and go. He has learned which tools are helpful and which are a waste of time. Through his Keep Calm and Refactor project, he helps Java developers to get their unruly code under control so they can work on fun and rewarding projects.


Subscribe to our podcasts here

Welcome to the AI Native Dev Podcast, hosted by Guy Podjarny and Simon Maple. If you're a developer or dev leader, join us as we explore and help shape the future of software development in the AI era.

THE WEEKLY DIGEST

Subscribe

Sign up to be notified when we post.

Subscribe

JOIN US ON

Discord

Come and join the discussion.

Join