---
title: Advances in Code Smell Detection
url: https://www.emergentmind.com/topics/code-smell-detection
type: topic
---

# Advances in Code Smell Detection

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 [2012.08842]. 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 [2605.20675].

**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 [2502.05012]. 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 [2306.00038].

## 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:
\[
\text{GodClass}\ :=\ \mathrm{WMC} > 50\ \wedge\ \mathrm{TCC} < 0.2
\]
where WMC is Weighted Methods per Class, and TCC is Tight Class Cohesion [2605.20675]. 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 [1902.03222].

**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 [2012.08842].

**d) Prompt Learning for LLMs:**  
PromptSmell recasts detection as masked-token prediction using cloze-style prompts in large language models (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 [2402.10398].

## 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:
\[
\mathrm{Score}(C,S) = \alpha \cdot \mathrm{MetricScore}(C,S) + \beta \cdot \mathrm{ContextWeight}(C,S)
\]
where contextual weights adjust prioritization according to team priorities or project phase, supporting targeted, actionable feedback [2605.20675].

**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 [2308.09458]. 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 [2506.17948].

**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%) [2509.20491].

**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) [2012.12590]. 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 [2205.07535].

## 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 [2605.20675].
- EnseSmells: F1 improvements of 5.98–28.26% over baselines, especially for Data Class and Feature Envy [2502.05012].
- PyExamine: recall 91.4% (code-level), 89.3% (structural), 80.6% (architectural), prevalence study over 183 Python projects [2501.18327].
- ML ensembles (AdaBoost, RF, XGBoost): 97–100% accuracy/F1 on six canonical Java smells [2510.05835].
- 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 [2601.09873].

## 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 [2012.08842].
- **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) [2306.00038].
- **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 language models with hybrid symbolic/statistical strategies and prompt-based learning (PromptSmell) to model label dependencies and capture natural code-language interaction [2402.10398].
- 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 [2605.20675][2205.07535].
- 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 [1902.03222][2402.10398].
- 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 [2308.09458][2509.20491][2506.17948].
- Maintain updated and shared, manually validated datasets (oracles) to support replicability, benchmarking, and cross-project validation.

---

**References**

- Context-Aware, Event-Driven Detection: [2605.20675]
- Deep Structural+Semantic Ensembles: [2502.05012]
- Federated Learning Methods: [2306.00038]
- ML and Ensemble Baselines: [2510.05835]
- Prompt-Based Multi-Label LLM Detection: [2402.10398]
- Crowd-Labeled Approaches: [2012.12590]
- Review-Centric Analysis: [2205.07535]
- Build-System Smell Detection: [2506.17948]
- Infrastructure as Code: [2308.09458]
- Python-Specific Multi-Layer Detection: [2501.18327]
- Systematic Literature Survey: [2012.08842]
- AI-Specific Smell DSLs: [2509.20491]

Source: https://www.emergentmind.com/topics/code-smell-detection