Software Engineering
New Framework Predicts Which Lines of Code Are Most Likely to Be Deleted
Researchers use survival analysis to model deletion risk for individual source code statements, finding that code complexity and context determine lifespan.
Software maintainers face a persistent challenge: understanding which parts of a codebase are vulnerable to removal. A fresh approach applies survival analysis—a statistical technique typically used in medical research—to track the "lifespan" of individual lines of code and predict their risk of deletion.
The Problem with Existing Methods#
Traditional code health analysis operates at the file or method level, obscuring the fate of individual statements. This coarser granularity masks which specific lines are candidates for removal, complicating both code review prioritization and maintenance planning. Prior work attempted line-level prediction but failed to identify meaningful predictors, suggesting the problem needed a fundamentally different analytical approach.
Code Lifespan Survival Analysis (CLSA)#
Researchers at the Software Engineering initiative introduced CLSA, a framework that treats each source code line as a subject with a measurable survival duration. The approach extracts structural, contextual, and temporal features and applies Cox Proportional Hazards modeling—standard in medical survival studies—to estimate deletion risk.
The analysis draws from 32.5 million line birth events across 120 open-source TypeScript repositories. A carefully designed 5-stage matching pipeline filtered out refactoring noise, eliminating 8.3 million false positives that would otherwise skew predictions. This distinction between genuine deletion and code reorganization proved critical to model accuracy.
Key Findings#
The study reveals several interpretable patterns:
- Median lifespan: Code survives approximately 1,335–1,352 days (about 3.7 years) on average, though deleted lines typically persist for only 95.7 days.
- Line length as protection: Token count acts as a steady protective factor (hazard ratio = 0.87), suggesting longer, more substantial statements survive longer.
- Conditional branches: Code in conditional blocks shows no risk early on but becomes a liability after 90 days (hazard ratio = 1.23).
- Repository effects: Repo identity emerged as the largest predictor; a gamma frailty model increased predictive concordance from 0.587 to 0.676, implying project-specific coding culture and maintenance patterns drive deletion patterns more than syntax alone.