[Paper Review] How Propense Are Large Language Models at Producing Code Smells? A Benchmarking Study
This paper introduces CodeSmellEval, a benchmark that measures the propensity of large language models (LLMs) to generate code smells using a novel metric, Propensity Smelly Score (PSC), which analyzes model logits. The study reveals that CodeLlama and Mistral frequently generate smells like consider-merging-isinstance and chained-comparison, highlighting a critical gap in code quality beyond accuracy.
Large Language Models (LLMs) have shown significant potential in automating software engineering tasks, particularly in code generation. However, current evaluation benchmarks, which primarily focus on accuracy, fall short in assessing the quality of the code generated by these models, specifically their tendency to produce code smells. To address this limitation, we introduce CodeSmellEval, a benchmark designed to evaluate the propensity of LLMs for generating code smells. Our benchmark includes a novel metric: Propensity Smelly Score (PSC), and a curated dataset of method-level code smells: CodeSmellData. To demonstrate the use of CodeSmellEval, we conducted a case study with two state-of-the-art LLMs, CodeLlama and Mistral. The results reveal that both models tend to generate code smells, such as simplifiable-condition and consider-merging-isinstance. These findings highlight the effectiveness of our benchmark in evaluating LLMs, providing valuable insights into their reliability and their propensity to introduce code smells in code generation tasks.
Motivation & Objective
- To address the lack of evaluation metrics that assess code quality beyond accuracy, particularly the tendency of LLMs to introduce code smells during code generation.
- To develop a model-agnostic benchmark that enables systematic evaluation of LLMs' propensity to generate method-level code smells.
- To provide a new dataset, CodeSmellData, comprising 142k curated Python method-level code smells from GitHub, to support rigorous benchmarking.
- To demonstrate the utility of the benchmark through a case study on two state-of-the-art LLMs, CodeLlama and Mistral, to reveal their smell-generation tendencies.
- To promote interpretability and reliability in LLM-based code generation by identifying which code smells are most likely to be introduced by current models.
Proposed method
- Propose the Propensity Smelly Score (PSC), a metric that computes the average log-probability of tokens associated with specific code smells using logits from the final transformer layer.
- Design a protocol to extract and align model-generated tokens with known code smell types using static analysis (Pylint) and a custom alignment function.
- Construct CodeSmellData, a dataset of 142,000 unique method-level code smells from public GitHub repositories, manually validated for type and location.
- Use bootstrapped sampling (100 instances per sample) to estimate PSC distributions and assess statistical significance, with a 0.5 threshold for error detection.
- Apply the benchmark to two LLMs—CodeLlama-7b-Instruct-hf and Mistral-7B-v0.3—by generating code from prompts and computing PSC for each code smell type.
- Visualize and compare PSC distributions across models and smell types to identify high-propensity smells, using statistical differences to infer model behavior.

Experimental results
Research questions
- RQ1What is the propensity of LLMs to generate specific types of code smells during code generation?
- RQ2Which code smell types are most frequently generated by current LLMs, and how do their PSC scores compare across models?
- RQ3How does the PSC metric differentiate between high- and low-propensity code smells, and what insights does it provide into model behavior?
- RQ4To what extent do LLMs trained on public codebases inherit and reproduce code smells present in their training data?
- RQ5Can the PSC metric serve as a reliable, interpretable, and model-agnostic indicator of code quality beyond standard generation metrics?
Key findings
- Both CodeLlama and Mistral exhibit a high propensity to generate code smells, particularly R1701 (consider-merging-isinstance), R1716 (chained-comparison), and W0718 (broad-exception-caught), with PSC scores significantly above the 0.5 threshold.
- The PSC score for consider-merging-isinstance (R1701) is nearly double that of disallowed-name (C0104), indicating a strong model bias toward generating this specific smell.
- Smells like disallowed-name (C0104), too-many-arguments (R0913), and non-ascii-name (C2401) fall below the PSC threshold, suggesting lower generation propensity, likely due to their specificity and context dependency.
- The benchmark successfully identifies that LLMs are more likely to generate structural or syntactic smells (e.g., redundant conditionals, chained comparisons) than semantic or naming-related ones.
- The PSC metric demonstrates interpretability by linking model logits to specific code smell types, offering a black-box method to assess code quality without ground-truth code.
- The case study confirms that LLMs trained on public codebases inherit and reproduce common code quality issues, suggesting that training data quality directly influences generated code quality.

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.