Scripted disciplined refactoring for legacy code
Working in "mends" means breaking down large remodeling into tiny auditable steps.
- A Mend is a series of Steps starting from a known state
- A Step is an invocation of exactly one known Recipe
- A Recipe is an executable script taking zero or more arguments
- A Run leaves a trail of source code changes with one Step per commit, with tests run after each
These tiny steps can often increase the effectiveness of humans working on legacy code. Moreover, this may currently be the only reliable way for Large Language Models (LLMs) to edit code.
Recipes are just scripts, they can do anything that can be reliably automated. For many languages, this includes formatting, lint auto-fixes, renames, extract, move, and others.
Most of this functionality has historically been coupled to IDEs. However, there are a few good command line tools available - such as clang-rename for C/C++, Eclim for Java, good old-fashioned sed - and we should build more of them!
The sister project Untangler is an effort to build the first multi-language automation-friendly refactoring CLI.
Beta testing, looking for feedback.
Here we run mend
on Yusuke Endoh's 2020 IOCCC winner
using the steps in examples/mend.toml.
- Building:
- Rust (tested with 1.71.1)
- Running
- git
- sh on path (usually bound to bash or zsh)
Make sure ~/.cargo/bin is on you path:
export PATH="$PATH:$HOME/.cargo/bin"
Then clone the project and run cargo install:
git clone [email protected]:craftvscruft/mend.git
cd mend
cargo install --path .
Then you can run with mend
mend -f mend.toml
More info on creating mend.toml coming soon, in the meantime checkout examples/mend.toml.
cd mend
cargo run -- <ARGS>
cargo test
If the approval test results have changed, review them with:
cargo insta review
👤 Ray Myers
- YouTube: Craft vs Cruft
- Twitter: @lambdapocalypse
- GitHub: @raymyers
- LinkedIn: @cadrlife
- Martin Fowler's Refactoring book and catalog
- Kent Beck's TCR == Test && Commit || Revert
- Marianne Bellotti's Kill It With Fire book
- Arlo Belshee's Commit Notation
- IOCCC - International Obfuscated C Code Contest
Copyright © 2023 Ray Myers.
This project is Apache 2 licensed.