Advances in Code Smell Detection
- Code Smell Detection is the process of identifying surface indicators of deeper design flaws and technical debt, impacting maintainability and software quality.
- Recent advances merge DSL-driven pipelines, deep learning ensembles, and federated learning to achieve high precision in detecting canonical smells like God Class and Long Method.
- Integrating context-aware mechanisms and human-in-the-loop feedback has enhanced actionable insights and real-time analysis within modern development environments.
Code smells are surface-level indicators of deeper design or implementation defects that compromise the maintainability, extensibility, or quality of software systems. Their detection is critical in managing technical debt, prioritizing refactoring, and preserving long-term code health. Research over the last two decades has produced an expansive spectrum of algorithms, tools, and methodologies for code smell detection, encompassing metrics-based, machine learning-based, search-based, human-in-the-loop, and context-aware approaches. This article systematizes these developments, with a focus on recent architectural advances, formal detection strategies, empirical best practices, multi-paradigm frameworks, and the interplay of automation and human feedback.
1. Architectural and Methodological Evolution
The archetype of code smell detection was the static metric-based rule, as found in seminal strategies where thresholds on coupling, cohesion, cyclomatic complexity, and lines of code are employed to detect canonical smells such as God Class, Long Method, or Feature Envy (Reis et al., 2020). While these rules remain foundational, subjectivity in thresholding and the lack of contextualization led to the development of more sophisticated methods.
Recent advances exemplify three major architectural trends:
a) Domain-Specific Languages (DSLs) with Event-Driven Pipelines:
SmellHunter introduces an event-driven pipeline where code smell definitions are declaratively specified using SmellDSL. The system orchestrates detection via asynchronous events—validation, interpretation, and persistence—across validation, interpretation, and storage services. SmellHunter’s architecture decouples detection logic from context enrichment, seamlessly integrating both static code metrics and contextual metadata (e.g., team, project phase, geolocation). This model enables continuous, non-intrusive analysis in integrated development environments (Eclipse plugin) and collaborative visualization on mobile platforms (Viegas et al., 20 May 2026).
b) Structural, Semantic, and Ensemble Deep Learning:
Hybrid deep-learning frameworks such as EnseSmells combine structural features (70+ static metrics) and statistical semantics (embeddings from CodeBERT, CuBERT, or code2vec) through parallel deep neural pipelines. These embeddings are fused and subject to classification via a deep, imbalanced neural network (Ho et al., 7 Feb 2025). The architectural principle is that "white-box" design information and "black-box" code embeddings provide complementary and independent signals, especially when handling diverse smoke types.
c) Federated and Privacy-Preserving Approaches:
FedCSD leverages federated learning, allowing decentralized entities (e.g., companies) to collaboratively train smell detectors without sharing raw code or metrics. Each client trains a local LSTM-based binary classifier on OO metrics and shares only model weights for server-side aggregation using FedAvg, achieving near-centralized accuracy (98.34%) while preserving data privacy (Alawadi et al., 2023).
2. Formalization of Detection Strategies
Detection strategies fall into several rigorously formalized paradigms:
a) Metric-Based Rules:
Smells are defined by boolean expressions over metrics and calibrated thresholds. For example, a God Class can be detected via: where WMC is Weighted Methods per Class, and TCC is Tight Class Cohesion (Viegas et al., 20 May 2026). SmellDSL supports custom rules over arbitrary metrics with compositional logic.
b) Machine Learning and Multilabel Classification:
ML methods transform code elements into high-dimensional metric (or feature) vectors and train binary/multiclass classifiers such as Random Forests, SVMs, AdaBoost, or neural architectures. For multilabel detection, problem transformation methods like Classifier Chains and Label Powerset encode label dependencies (e.g., simultaneous Long Method and Feature Envy). Hamming Loss, Exact Match, and Jaccard indices are used for evaluation, achieving >91% exact match in dual-smell cases (Guggulothu, 2019).
c) Search-Based and Optimization Methods:
Search-based detection leverages genetic algorithms, particle swarm, or multi-objective evolutionary algorithms to discover optimal threshold sets for metric-based rules, explicitly balancing tradeoffs between precision, recall, and rule interpretability (Reis et al., 2020).
d) Prompt Learning for LLMs:
PromptSmell recasts detection as masked-token prediction using cloze-style prompts in LLMs (PLMs). Multi-label problems are solved by mapping the set of observed smells onto finitely many verbalized classes, which the PLM predicts under a constrained answer space; this yields substantial increases in weighted precision and F1 even in low-data regimes (Liu et al., 2024).
3. Multi-Domain and Context-Enriched Detection
Contemporary tools expand smell detection beyond classical OO code and integrate context-aware mechanisms.
a) Program and Developer Context:
SmellHunter's pipeline considers developer IDs, team affiliation, project stage, and geographic data, blending metric-based detection with weighted context scoring: where contextual weights adjust prioritization according to team priorities or project phase, supporting targeted, actionable feedback (Viegas et al., 20 May 2026).
b) Infrastructure as Code and Build Scripts:
GLITCH introduces a polyglot intermediate representation to detect 18 design and security smells across Ansible, Chef, Docker, Puppet, and Terraform infrastructure scripts (e.g., Hard-Coded Secret, Duplicate Block, Long Resource), achieving precision 0.82 and recall 0.85 by abstracting language heterogeneity (Saavedra et al., 2023). Build It Clean’s Sniffer analyzes Maven, Gradle, CMake, and Make scripts, detecting thirteen specific build-system smells (e.g., Hardcoded URLs, Insecure URLs, Outdated Dependencies) tied to reliability and maintainability (Tamanna et al., 22 Jun 2025).
c) AI-Specific and Domain-Specific Smells:
SpecDetect4AI enables specification of 22 AI-specific smells (e.g., Data Leakage, Hyperparameter Not Explicitly Set) via a dedicated DSL with semantic predicates (isMLMethodCall, usedBeforeTrainTestSplit), evaluated at scale (20M LOC, precision 88.66%, recall 88.89%) (Mahmoudi et al., 24 Sep 2025).
d) Human-in-the-Loop and Crowd-Driven Detection:
CrowdSmelling aggregates and calibrates detection models with crowd-labeled oracles from software-engineering teams, achieving performance on par with expert-defined tools for Long Method and God Class, but revealing the limitations of crowdsourcing for subtle smells (e.g., Feature Envy) (Reis et al., 2020). Code review-based studies confirm that reviewers identify contextually nuanced smells (0.35% of comments), most arising from violated coding conventions, and that human validation remains crucial for complex or non-local smells (Han et al., 2022).
4. Tooling Ecosystem and Empirical Performance
Beyond research prototypes, mature static and ML-based tools have reached industrial adoption:
| Tool/Framework | Domain/Language | Detection Modality | Representative Smells |
|---|---|---|---|
| SmellHunter | Java (Eclipse, Mobile) | DSL + Context/Metrics | God Class, Long Method, DataClump |
| PyExamine | Python | Multi-layer Rule/Metric | 49 metrics: code/structural/design |
| Sniffer | Build Scripts (Polyglot) | Rule-based Regex/XPath | 13 build-script smells |
| EnseSmells | Java | Deep Ensemble (Struct+Sem) | LM, FE, DC, GC |
| FedCSD | Java | Federated Deep Learning | God Class (mainly) |
| GLITCH | IaC (Polyglot) | IR + Rule Visitor | 18 security/design smells |
| SpecDetect4AI | Python (AI/ML) | DSL + Semantic Predicates | 22 AI/ML-specific smells |
Reported empirical results include:
- SmellHunter: sub-500 ms turnaround, 85% perceived actionability over baseline, >78% developer acceptance (Viegas et al., 20 May 2026).
- EnseSmells: F1 improvements of 5.98–28.26% over baselines, especially for Data Class and Feature Envy (Ho et al., 7 Feb 2025).
- PyExamine: recall 91.4% (code-level), 89.3% (structural), 80.6% (architectural), prevalence study over 183 Python projects (Shivashankar et al., 30 Jan 2025).
- ML ensembles (AdaBoost, RF, XGBoost): 97–100% accuracy/F1 on six canonical Java smells (Bhuiyan et al., 7 Oct 2025).
- LLM-based ensemble/voting: hybrid best-of tools + LLMs yields F1>0.90 on Large Class, Long Method; context-dependent smells still require manual review (Souza et al., 14 Jan 2026).
5. Challenges, Subjectivity, and Future Trends
The field faces persistent challenges:
- Subjectivity and Ground Truth: Definitions remain informally specified, with thresholds varying across organizations. Standardized oracles are rare (<12% of studies publish datasets), impeding meaningful replication and generalization (Reis et al., 2020).
- Complex, Contextual, and Multi-Smell Scenarios: Many detectors excel at "structurally straightforward" smells but underperform on phenomena requiring semantic, architectural, or inter-component reasoning (e.g., Refused Bequest, Shotgun Surgery).
- Threshold Calibration and Generalization: Search-based and ML methods automate threshold tuning, but cross-project generalization remains imperfect, with accuracy drops on out-of-domain data (e.g., >30% in cross-dataset experiments) (Alawadi et al., 2023).
- Integration, Scalability, and Usability: CI/CD integration, multi-channel feedback, and IDE-level support (real-time, mobile, batch) are increasingly standard (see SmellHunter, PyExamine, Sniffer).
Future directions highlighted in the data include:
- Expansion to new and evolving smell taxonomies (e.g., AI/ML, build systems, infrastructure), cross-language detectors, and comprehensive visualization support.
- Leveraging deep LLMs with hybrid symbolic/statistical strategies and prompt-based learning (PromptSmell) to model label dependencies and capture natural code-language interaction (Liu et al., 2024).
- More extensive crowdsourcing and human-in-the-loop validation, balancing automation with expert oversight.
- Privacy-preserving collaborative models enabling industry-wide learning without data leakage, as shown by federated frameworks (FedCSD).
6. Best Practices and Research-Backed Recommendations
- Employ hybrid detection: combine static metric rules with contextual, semantic, and, where available, crowd- or developer-provided feedback to reduce false positives and negatives (Viegas et al., 20 May 2026, Han et al., 2022).
- Calibrate metric-based thresholds for local codebase characteristics, automate tuning via search/ML, but supplement with human oversight (especially for non-trivial smells).
- For multi-label/multi-smell scenarios, utilize classifier chains or prompt-based LLM frameworks to capture label dependencies and co-occurrences (Guggulothu, 2019, Liu et al., 2024).
- Integrate detection tooling directly into developer workflows (IDE, CI/CD, dashboards) with actionable, contextualized outputs and visualization support.
- For domain-specific code (build scripts, AI/ML, infrastructure), prefer tools that generalize via IRs, DSLs, or modular semantic frameworks for extensibility and cross-technology applicability (Saavedra et al., 2023, Mahmoudi et al., 24 Sep 2025, Tamanna et al., 22 Jun 2025).
- Maintain updated and shared, manually validated datasets (oracles) to support replicability, benchmarking, and cross-project validation.
References
- Context-Aware, Event-Driven Detection: (Viegas et al., 20 May 2026)
- Deep Structural+Semantic Ensembles: (Ho et al., 7 Feb 2025)
- Federated Learning Methods: (Alawadi et al., 2023)
- ML and Ensemble Baselines: (Bhuiyan et al., 7 Oct 2025)
- Prompt-Based Multi-Label LLM Detection: (Liu et al., 2024)
- Crowd-Labeled Approaches: (Reis et al., 2020)
- Review-Centric Analysis: (Han et al., 2022)
- Build-System Smell Detection: (Tamanna et al., 22 Jun 2025)
- Infrastructure as Code: (Saavedra et al., 2023)
- Python-Specific Multi-Layer Detection: (Shivashankar et al., 30 Jan 2025)
- Systematic Literature Survey: (Reis et al., 2020)
- AI-Specific Smell DSLs: (Mahmoudi et al., 24 Sep 2025)