[Paper Review] Refining ChatGPT-Generated Code: Characterizing and Mitigating Code Quality Issues
The paper systematically evaluates 4,066 ChatGPT-generated Java and Python programs for 2,033 LeetCode tasks to characterize code quality issues, analyze factors affecting correctness, and test prompt-based self-repair guided by static analysis and runtime feedback.
We systematically study the quality of 4,066 ChatGPT-generated code implemented in two popular programming languages, i.e., Java and Python, for 2,033 programming tasks. The goal of this work is three folds. First, we analyze the correctness of ChatGPT on code generation tasks and uncover the factors that influence its effectiveness, including task difficulty, programming language, time that tasks are introduced, and program size. Second, we identify and characterize potential issues with the quality of ChatGPT-generated code. Last, we provide insights into how these issues can be mitigated. Experiments highlight that out of 4,066 programs generated by ChatGPT, 2,756 programs are deemed correct, 1,082 programs provide wrong outputs, and 177 programs contain compilation or runtime errors. Additionally, we further analyze other characteristics of the generated code through static analysis tools, such as code style and maintainability, and find that 1,930 ChatGPT-generated code snippets suffer from maintainability issues. Subsequently, we investigate ChatGPT's self-repairing ability and its interaction with static analysis tools to fix the errors uncovered in the previous step. Experiments suggest that ChatGPT can partially address these challenges, improving code quality by more than 20%, but there are still limitations and opportunities for improvement. Overall, our study provides valuable insights into the current limitations of ChatGPT and offers a roadmap for future research and development efforts to enhance the code generation capabilities of AI models like ChatGPT.
Motivation & Objective
- Assess ChatGPT's correctness on code generation across task difficulty, language, and task age.
- Characterize prevalent code quality issues in ChatGPT-generated code using static analysis and runtime data.
- Explore prompting strategies that leverage static analysis and runtime feedback to repair code quality issues.
Proposed method
- Construct a time-sensitive benchmark of 2,033 LeetCode tasks with Python and Java templates and public test suites.
- Generate code with ChatGPT (zero-shot, temperature 0) for each task and language.
- Evaluate correctness via pass@1 against LeetCode test suites.
- Apply static analysis tools (Python: Pylint, Flake8; Java: PMD, Checkstyle) to classify code quality issues.
- Use open card sorting to categorize issues into themes: compilation/runtime errors, wrong outputs, code style/maintainability, and performance/efficiency.
- Test repair prompts that request fixes with or without static analysis/runtime feedback to assess self-repair capability.
Experimental results
Research questions
- RQ1RQ1: How effective is ChatGPT on code generation for programming tasks?
- RQ2RQ2: What are the common issues in ChatGPT-generated code?
- RQ3RQ3: Can ChatGPT fix the code quality issues with prompting?
Key findings
- 66% of Python and 69% of Java ChatGPT-generated programs are functionally correct (pass all test cases).
- Code quality issues appear even among passing code, with 53% of Java and 37% of Python passing code showing style/maintainability problems.
- ChatGPT can partially repair issues using feedback from static analysis and runtime errors, with effectiveness varying by language and issue type.
- Static analysis shows 47% of Java and 63% of Python passed tasks have clean code, and cleanliness declines with task difficulty.
- Overall, 1,930 of 4,066 generated snippets exhibit code style/maintainability issues, and 1,082 exhibit wrong outputs.
- The study provides a roadmap for improving AI-driven code generation and releases dataset and replication package.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.