Uber has announced it is open-sourcing Piranha, an automated source-to-source code refactoring tool that automatically deletes stale code and feature flags when they become obsolete. Piranha is currently implemented for Objective-C, Swift, and Java programs so far. 

“These nonfunctional feature flags represent technical debt, making it difficult for developers to work on the codebase, and can bloat our apps, requiring unnecessary operations that impact performance for the end-user and potentially impact overall app reliability,” Uber wrote in a post. “We believe Piranha offers great utility for organizations that use feature flags in their app deployments, and so have open-sourced it.”

RELATED CONTENT: Waving the flag for feature experimentation

When feature flags become stale, they accumulate into unwanted technical debt. Also, the presence of code related to these unnecessary flags can affect software development across multiple dimensions. 

First, developers have to reason about the control flow related to these obsolete flags, and second, such code might still be made executable in unexpected cases. A lot of effort must be sent spent to maintain test coverage of these parts, according to Uber. 

To solve this, Piranha analyzes the abstract syntax trees (ASTs) of the program to generate appropriate refactorings which are packaged into a diff. The diff is assigned to the author of the flag for further inspection, who can then land (commit to master) as is, or perform any additional refactorings before landing it.

The cleanup includes deleting code that immediately surrounds the feature flag APIs, Delete code that becomes unreachable due to performing the previous step (also known as deep cleaning), and deleting tests related to feature flags.