Comment Consistency Detection Algorithm Based on Code Change History
Wei Zhu · International Journal of Emerging Technologies and Advanced Applications · 2025
During software evolution, frequent code modifications often lead to inconsistencies between comments and actual code logic, creating technical debt and increasing maintenance costs. Existing comment consistency detection methods primarily rely on static analysis and lack systematic analysis of code evolution history, making it difficult to accurately identify outdated comment issues caused by code changes. This paper proposes a comment consistency detection algorithm based on code change history that identifies potential inconsistencies where code has been modified but comments remain unchanged by analyzing commit records in version control systems. The algorithm first constructs a code-comment association graph, establishing mapping relationships between functions, classes, variables, and their corresponding comments. Next, it detects the semantic impact scope of code changes using differential algorithms to determine whether related comments remain valid. It then employs natural language processing techniques to calculate semantic similarity between comment content and modified code. Finally, it combines factors such as change frequency and modification complexity to compute consistency risk scores. Validation on five large-scale open-source projects demonstrates that the algorithm can accurately identify 89.2% of comment inconsistency issues with a false positive rate of only 5.9% and a recall rate of 91.9%, significantly outperforming existing baseline methods and providing effective technical support for automated code quality management.