Ideas from TPRC2022: Tools to help refactor large mature code bases
Every Perl gig I have ever had, and from most of the conversations I had at this years Perl and Raku Conference, was working on a large code based that is serving the business and it's customers very well such that the business is profitable (i.e. a mature code base).
This is an enviable position to be in but whilst this software is robust from the outside, there is often a reluctance to make dramatic changes. Unfortunately code that is perceived as too fragile to touch tends to be replaced and replaced in another language.
The PPI + Class::Inspector combination is already being used by people I've spoken too, in bespoke tools to refactor large code bases reliably.
We have frameworks for testing (Test:: etc) and linting (Perl::Critic) with suites of well established reusable polices, so why not a similar framework for refactoring?
Such a tool might have provided polices to assist replacing deprecated syntax, migrate between "Try" implementations, fixing up scalar vs list context, just to name a few.
Achieving a 100% successful transition on any given code base is probably unrealistic, being able to produce diffs that can be accepted by human review 80%+ of the time would present excellent value.
I see this as being very similar to unit testing - consider that whilst some functionality in a codebase may be extraordinarily challenging to write tests for, this shouldn't be an excuse to write no tests at all. Achieving an 80% test coverage might be considered outstanding and provide enormous value.
Perhaps folks already have something they can publish to CPAN or just throw up on Github to socialize ideas? What's your thoughts?
perlimports is a good tool for helping to rewrite some code and reduce dependencies:
https://metacpan.org/pod/perlimports
PerlNitpick is a promising tool which would allow you to write plugins to rewrite existing code. I think it still needs some love, but it's basically already set up to do this kind of refactoring.
https://metacpan.org/dist/App-PerlNitpick
Having said all that PPI itself still needs some significant work to keep up with modern Perl and it would be nice to see some additional help with that.