Grep and AST Disagree on Dead Code Detection, Both Miss Framework-Invoked Functions
A developer compared a regex-based grep heuristic with Python's ast module to find unused functions across several files in a personal repository. The regex approach falsely matched a call-like string inside a docstring, hiding one genuinely unused function, while AST parsing avoided that error. Both tools wrongly flagged five server.py functions as dead, even though they are MCP tools invoked at runtime through the framework's dispatch table. Timing measurements showed grep running roughly three to four times faster than AST parsing, though both finished in milliseconds on these files. The author concludes grep suits quick first-pass sweeps, while decisions like deletion require more careful verification.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in