Code is there. Just in case. We might need it soon.
TL;DR: Don't leave code for future use.
-
Complexity
-
Coupling
-
Remove dead code.
-
Leave covered and real tested code.
<?
final class DatabaseQueryOptimizer {
public function selectWithCriteria($tableName, $criteria) {
// Make some optimizations manipulating criteria
}
private function sqlParserOptimization(SQLSentence $sqlSentence)
: SQLSentence {
// Parse the SQL converting it to a string
// and then working with their nodes as strings and lots of regex
// This was a very costly operation overcoming real SQL benefits.
// But since you made too much work you decide to keep the code.
}
}
<?
final class DatabaseQueryOptimizer {
public function selectWithCriteria($tableName, $criteria) {
// Make some optimizations manipulating criteria
}
}
Using some mutation testing variants we can remove the dead code and see if test fails.
We need to have good coverage to rely on this solution.
- YAGNI
[X] Intermediate
Dead code is always a problem.
We can use modern development techniques like TDD to ensure all code is alive.
How to Squeeze Test Driven Development on Legacy Systems
- Speculative Generality
Photo by Kris Mikael Krister on Unsplash
Thanks to @Apoorv Tyagi for pointing this out.
It is very hard to predict, especially the future.
Niels Bohr
Software Engineering Great Quotes
This article is part of the CodeSmell Series.