Back to results

Chalmers University of Technology

Enhancing Code Refactoring in Python: Leveraging Large Language Models

Abstract

dc:description.abstract

Software engineering is evolving rapidly, involving tasks in creating new reliable features. The challenges of maintaining the existing features are challenging due to the existence of code smells, resulting in technical debt and thus reducing the overall quality of the product. At the same time, manual refactoring is error-prone and time-consuming. LLMs are becoming increasingly prevalent across various parts of the software development life cycle. The study aims to improve code refactoring suggestions in Python using Large Language Models (LLMs) such as ChatGPT and GitHub Copilot. Code refactoring is an important aspect of software engineering to address code smells, which improves the code quality. The research aims to investigate the refactoring suggestions provided by LLMs compared to those provided by humans, specifically focusing on Python programming language. To determine this objective, qualitative research methods are incorporated, semi-structural interviews with developers to identify the prioritized and ignored code smells and challenges faced during the refactoring process in the industry. The result was analyzed using narrative analysis, pre-study on prompt engineering to get an optimized prompt comparing and analyzing code refactoring suggestions between two LLMs, the study also conducts a controlled experiment to compare refactoring suggestions between LLM’s and developers, the study identifies common refactoring patterns the ability of LLMs to offer correct and understandable refactoring solutions. The research further demonstrates that LLMs can assist in giving refactoring suggestions but human developers are better than LLMs when it comes to understanding complex code smells and addressing code structure. On the other hand, LLMs are capable of enhancing code structure consequently enhancing the process of refactoring. The results show the merits and demerits of code refactoring using LLMs and how they can be adopted in Python development code refactoring.

Degree

thesis:*
Level thesis:degree_level
H
Department dc:contributor.department
Chalmers tekniska högskola / Institutionen för data och informationsteknik
Year dc:date.issued
2024

Author and committee

dc:creator, dc:contributor.*
Authors dc:creator
  • Naik, Arpita
  • Rajan Shylaja, Rithika
Advisor dc:contributor.supervisor
  • Fotrousi, Farnaz
Committee member dc:contributor.committeemember
  • Heyn, Hans-Martin

Subjects

dc:subject × 1

Rights

Language dc:language.iso
eng

Identifiers

dc:identifier.*
Dc Identifier Coursecode
DATX05

Chain of custody

source
Harvested from
Chalmers University of Technology
Base URL
odr.chalmers.se/oai/request
Last updated
2026-11-19
Source record
OAI-PMH GetRecord
citation

Naik, Arpita; Rajan Shylaja, Rithika. Enhancing Code Refactoring in Python: Leveraging Large Language Models. H thesis, 2024. https://hdl.handle.net/20.500.12380/310455