Abstract:
Code refactoring, in which an existing module is modified for satisfying some property while maintaining the functionality, is often needed as software evolves. Since refactoring is tedious and error prone, it is sometimes ignored, even though reforming could improve code quality. In this paper we experimentally explore the effectiveness of using genAI, in particular ChatGPT, for refactoring of python code modules. From open source, we collected 14 python modules of 100-300 LOC. We then refactored them using ChatGPT for two different end-goals: improving performance and improving maintainability or understandability. Our findings indicate that ChatGPT is able to successfully refactor in most of the cases, and also improves the code for the stated refactoring goal. We also explored different prompt styles for improving refactoring performance, and shared our experience of the same.