Refactoring Programs Using Large Language Models with Few-Shot Examples
Not on the map. Why?
Abstract (arXiv)
A less complex and more straightforward program is a crucial factor that enhances its maintainability and makes writing secure and bug-free programs easier. However, due to its heavy workload and the risks of breaking the working programs, programmers are reluctant to do code refactoring, and thus, it also causes the loss of potential learning experiences. To mitigate this, we demonstrate the application of using a large language model (LLM), GPT-3.5, to suggest less complex versions of the user-written Python program, aiming to encourage users to learn how to write better programs. We propose a method to leverage the prompting with few-shot examples of the LLM by selecting the best-suited code refactoring examples for each target programming problem based on the prior evaluation of prompting with the one-shot example. The quantitative evaluation shows that 95.68% of programs can be refactored by generating 10 candidates each, resulting in a 17.35% reduction in the average cyclomatic complexity and a 25.84% decrease in the average number of lines after filtering only generated programs that are semantically correct. Furthermore, the qualitative evaluation shows outstanding capability in code formatting, while unnecessary behaviors such as deleting or translating comments are also observed.
Key facts. Cited by 28 papers in the map (data through 14 Oct 2026). Builds on 29 of its 46 references that are in the map. First posted on arXiv 20 Nov 2023.
Builds on
29 of 46 references.
References · 29
- 2020Language Models are Few-Shot Learnerscited by 32,419
- 2023GPT-4 Technical Reportcited by 18,396
- 2022Training language models to follow instructions with human feedbackcited by 15,971
- 2023LLaMA: Open and Efficient Foundation Language Modelscited by 14,132
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2022PaLM: Scaling Language Modeling with Pathwayscited by 5,326
- 2023Self-Refine: Iterative Refinement with Self-Feedbackcited by 3,442
- 2022Competition-Level Code Generation with AlphaCodecited by 1,462
- 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 885
- 2023StarCoder: may the source be with you!cited by 799
- 2023WizardCoder: Empowering Code Large Language Models with Evol-Instructcited by 733
- 2022InCoder: A Generative Model for Code Infilling and Synthesiscited by 498
17 more
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 431
- 2023CodeGeeX: A Pre-Trained Model for Code Generation with Multilingual Benchmarking on HumanEval-Xcited by 300
- 2020IntelliCode Compose: Code Generation Using Transformercited by 227
- 2021CodeNet: A Large-Scale AI for Code Dataset for Learning a Diversity of Coding Taskscited by 200
- 2022Automatic Generation of Programming Exercises and Code Explanations using Large Language Modelscited by 126
- 2023Learning Performance-Improving Code Editscited by 106
- 2022Repair Is Nearly Generation: Multilingual Program Repair with LLMscited by 68
- 2023ChatGPT Prompt Patterns for Improving Code Quality, Refactoring, Requirements Elicitation, and Software Designcited by 66
- 2022PanGu-Coder: Program Synthesis with Function-Level Language Modelingcited by 48
- 2022CoditT5: Pretraining for Source Code and Natural Language Editingcited by 45
- 2021In-IDE Code Generation from Natural Language: Promise and Challengescited by 42
- 2018CODIT: Code Editing with Tree-Based Neural Modelscited by 40
- 2022Repairing Bugs in Python Assignments Using Large Language Modelscited by 28
- 2022CodeEditor: Learning to Edit Source Code with Pre-trained Modelscited by 12
- 2021ProtoTransformer: A Meta-Learning Approach to Providing Student Feedbackcited by 8
- 2023Program Repair with Minimal Edits Using CodeT5cited by 2
- 2021Improving Readability of Scratch Programs with Search-based Refactoringcited by 1
Built on by
Citing papers per year: 2024: 6; 2025: 15; 2026: 7.
28 papers.
Sort:
By area:
- 2024A Survey on Large Language Models for Code Generationcited by 658
- 2024Lingma SWE-GPT: An Open Development-Process-Centric Language Model for Automated Software Improvementcited by 61
- 2025Agentic Refactoring: An Empirical Study of AI Coding Agentscited by 18
- 2024VerMCTS: Synthesizing Multi-Step Programs using a Verifier, a Large Language Model, and Tree Searchcited by 14
- 2024What can Large Language Models Capture about Code Functional Equivalence?cited by 14
- 2025Migrating Code At Scale With LLMs At Googlecited by 14
- 2024LLMs: A Game-Changer for Software Engineers?cited by 11
- 2025MANTRA: Enhancing Automated Method-Level Refactoring with Contextual RAG and Multi-Agent LLM Collaborationcited by 10
- 2026CodeTaste: Can LLMs Generate Human-Level Code Refactorings?cited by 8
- 2026Are Coding Agents Generating Over-Mocked Tests? An Empirical Studycited by 6
- 2025Evaluating the Effectiveness of LLMs in Fixing Maintainability Issues in Real-World Projectscited by 4
- 2025EditLord: Learning Code Transformation Rules for Code Editingcited by 4
16 more
- 2025What Were You Thinking? An LLM-Driven Large-Scale Study of Refactoring Motivations in Open-Source Projectscited by 4
- 2026Skill-as-Pseudocode: Refactoring Skill Libraries to Pseudocode for LLM Agentscited by 4
- 2025AuPair: Golden Example Pairs for Code Repaircited by 3
- 2025LLM-based Multi-Agent System for Intelligent Refactoring of Haskell Codecited by 3
- 2024CODECLEANER: Elevating Standards with A Robust Data Contamination Mitigation Toolkitcited by 2
- 2025Towards Secure Program Partitioning for Smart Contracts with LLM's In-Context Learningcited by 2
- 2025Generating High-Quality Datasets for Code Editing via Open-Source Language Modelscited by 2
- 2025Refactoring with LLMs: Bridging Human Expertise and Machine Understandingcited by 2
- 2025Leveraging LLMs, IDEs, and Semantic Embeddings for Automated Move Method Refactoringcited by 1
- 2025Exploring the Security Threats of Retriever Backdoors in Retrieval-Augmented Code Generationcited by 1
- 2026TimeMachine-bench: A Benchmark for Evaluating Model Capabilities in Repository-Level Migration Taskscited by 1
- 2026RefactorAssist: Agentic Refinement for Reliable Code Refactoringcited by 1
- 2025Automated Harmfulness Testing for Code Large Language Modelscited by 0
- 2025Do AI Models Dream of Faster Code? An Empirical Study on LLM-Proposed Performance Improvements in Real-World Softwarecited by 0
- 2026AI-Assisted Unit Test Writing and Test-Driven Code Refactoring: A Case Studycited by 0
- 2026An Exploratory Case Study of LLM-Assisted Refactoring and Gameplay Feature Generation in an Endless Runner Gamecited by 0
- 2026RefactorAssist: Agentic Refinement for Reliable Code Refactoring2 Aug 2026
- 2026An Exploratory Case Study of LLM-Assisted Refactoring and Gameplay Feature Generation in an Endless Runner Game19 Jun 2026
- 2026Skill-as-Pseudocode: Refactoring Skill Libraries to Pseudocode for LLM Agents27 May 2026
- 2026AI-Assisted Unit Test Writing and Test-Driven Code Refactoring: A Case Study3 Apr 2026
- 2026CodeTaste: Can LLMs Generate Human-Level Code Refactorings?4 Mar 2026
- 2026Are Coding Agents Generating Over-Mocked Tests? An Empirical Study30 Jan 2026
- 2026TimeMachine-bench: A Benchmark for Evaluating Model Capabilities in Repository-Level Migration Tasks30 Jan 2026
- 2025Exploring the Security Threats of Retriever Backdoors in Retrieval-Augmented Code Generation25 Dec 2025
- 2025Agentic Refactoring: An Empirical Study of AI Coding Agents6 Nov 2025
- 2025Do AI Models Dream of Faster Code? An Empirical Study on LLM-Proposed Performance Improvements in Real-World Software17 Oct 2025
- 2025Refactoring with LLMs: Bridging Human Expertise and Machine Understanding4 Oct 2025
- 2025Generating High-Quality Datasets for Code Editing via Open-Source Language Models19 Sep 2025
16 more
- 2025What Were You Thinking? An LLM-Driven Large-Scale Study of Refactoring Motivations in Open-Source Projects9 Sep 2025
- 2025LLM-based Multi-Agent System for Intelligent Refactoring of Haskell Code24 Jun 2025
- 2025Migrating Code At Scale With LLMs At Google13 Apr 2025
- 2025Leveraging LLMs, IDEs, and Semantic Embeddings for Automated Move Method Refactoring26 Mar 2025
- 2025Automated Harmfulness Testing for Code Large Language Models20 Mar 2025
- 2025MANTRA: Enhancing Automated Method-Level Refactoring with Contextual RAG and Multi-Agent LLM Collaboration18 Mar 2025
- 2025EditLord: Learning Code Transformation Rules for Code Editing10 Mar 2025
- 2025Towards Secure Program Partitioning for Smart Contracts with LLM's In-Context Learning20 Feb 2025
- 2025AuPair: Golden Example Pairs for Code Repair12 Feb 2025
- 2025Evaluating the Effectiveness of LLMs in Fixing Maintainability Issues in Real-World Projects4 Feb 2025
- 2024CODECLEANER: Elevating Standards with A Robust Data Contamination Mitigation Toolkit16 Nov 2024
- 2024LLMs: A Game-Changer for Software Engineers?1 Nov 2024
- 2024Lingma SWE-GPT: An Open Development-Process-Centric Language Model for Automated Software Improvement1 Nov 2024
- 2024What can Large Language Models Capture about Code Functional Equivalence?20 Aug 2024
- 2024A Survey on Large Language Models for Code Generation1 Jun 2024
- 2024VerMCTS: Synthesizing Multi-Step Programs using a Verifier, a Large Language Model, and Tree Search13 Feb 2024
- 2024Lingma SWE-GPT: An Open Development-Process-Centric Language Model for Automated Software Improvementcited by 61
- 2025Agentic Refactoring: An Empirical Study of AI Coding Agentscited by 18
- 2025MANTRA: Enhancing Automated Method-Level Refactoring with Contextual RAG and Multi-Agent LLM Collaborationcited by 10
- 2026CodeTaste: Can LLMs Generate Human-Level Code Refactorings?cited by 8
- 2026Are Coding Agents Generating Over-Mocked Tests? An Empirical Studycited by 6
- 2026Skill-as-Pseudocode: Refactoring Skill Libraries to Pseudocode for LLM Agentscited by 4
- 2025LLM-based Multi-Agent System for Intelligent Refactoring of Haskell Codecited by 3
- 2026RefactorAssist: Agentic Refinement for Reliable Code Refactoringcited by 1
- 2026RefactorAssist: Agentic Refinement for Reliable Code Refactoring2 Aug 2026
- 2026Skill-as-Pseudocode: Refactoring Skill Libraries to Pseudocode for LLM Agents27 May 2026
- 2026CodeTaste: Can LLMs Generate Human-Level Code Refactorings?4 Mar 2026
- 2026Are Coding Agents Generating Over-Mocked Tests? An Empirical Study30 Jan 2026
- 2025Agentic Refactoring: An Empirical Study of AI Coding Agents6 Nov 2025
- 2025LLM-based Multi-Agent System for Intelligent Refactoring of Haskell Code24 Jun 2025
- 2025MANTRA: Enhancing Automated Method-Level Refactoring with Contextual RAG and Multi-Agent LLM Collaboration18 Mar 2025
- 2024Lingma SWE-GPT: An Open Development-Process-Centric Language Model for Automated Software Improvement1 Nov 2024
- 2025Automated Harmfulness Testing for Code Large Language Models20 Mar 2025
- 2024A Survey on Large Language Models for Code Generationcited by 658
- 2024What can Large Language Models Capture about Code Functional Equivalence?cited by 14
- 2025Migrating Code At Scale With LLMs At Googlecited by 14
- 2024LLMs: A Game-Changer for Software Engineers?cited by 11
- 2025Evaluating the Effectiveness of LLMs in Fixing Maintainability Issues in Real-World Projectscited by 4
- 2025EditLord: Learning Code Transformation Rules for Code Editingcited by 4
- 2025What Were You Thinking? An LLM-Driven Large-Scale Study of Refactoring Motivations in Open-Source Projectscited by 4
- 2024CODECLEANER: Elevating Standards with A Robust Data Contamination Mitigation Toolkitcited by 2
- 2025Towards Secure Program Partitioning for Smart Contracts with LLM's In-Context Learningcited by 2
- 2025Generating High-Quality Datasets for Code Editing via Open-Source Language Modelscited by 2
- 2025Refactoring with LLMs: Bridging Human Expertise and Machine Understandingcited by 2
- 2025Leveraging LLMs, IDEs, and Semantic Embeddings for Automated Move Method Refactoringcited by 1
12 most cited of 16 All 16 (JSON)
- 2026An Exploratory Case Study of LLM-Assisted Refactoring and Gameplay Feature Generation in an Endless Runner Game19 Jun 2026
- 2026AI-Assisted Unit Test Writing and Test-Driven Code Refactoring: A Case Study3 Apr 2026
- 2026TimeMachine-bench: A Benchmark for Evaluating Model Capabilities in Repository-Level Migration Tasks30 Jan 2026
- 2025Do AI Models Dream of Faster Code? An Empirical Study on LLM-Proposed Performance Improvements in Real-World Software17 Oct 2025
- 2025Refactoring with LLMs: Bridging Human Expertise and Machine Understanding4 Oct 2025
- 2025Generating High-Quality Datasets for Code Editing via Open-Source Language Models19 Sep 2025
- 2025What Were You Thinking? An LLM-Driven Large-Scale Study of Refactoring Motivations in Open-Source Projects9 Sep 2025
- 2025Migrating Code At Scale With LLMs At Google13 Apr 2025
- 2025Leveraging LLMs, IDEs, and Semantic Embeddings for Automated Move Method Refactoring26 Mar 2025
- 2025EditLord: Learning Code Transformation Rules for Code Editing10 Mar 2025
- 2025Towards Secure Program Partitioning for Smart Contracts with LLM's In-Context Learning20 Feb 2025
- 2025Evaluating the Effectiveness of LLMs in Fixing Maintainability Issues in Real-World Projects4 Feb 2025
12 newest of 16 All 16 (JSON)