Naming Methods Automatically after Refactoring Operations

Juan Carlos Recio Abad · 2023

In Object-oriented Programming (OOP), the Cognitive Complexity (CC) of software is a metric of the difficulty associated with understanding and maintaining the source code. This is usually measured at the method level, taking into account the number of control flow sentences and their nesting level. One way to reduce the CC associated to a method is by extracting code into new methods without altering any existing functionality. However, this involves deciding on new names that are representative of the functionality of the extracted code. This work focuses on large language models to automate the process of assigning new methods names after refactoring operations in software projects. We use the OpenAI Chat API with the text-davinci-003 model in orer to perform coding tasks. This work studies the capability of this technique for assigning names to new extracted methods during the evolution of a code base. Such evolution comprises continuous extraction operations to study how the method name semantics stability evolves. We found the precision of the model to be highly acceptable, achieving in many cases a level similar to that of a human. However, there are also a few cases in which it fails to provide appropriate names or does not even provide a name inside the indicated standards.

Read the paper · More papers on PaperTik