Skip to content

Instantly share code, notes, and snippets.

@hanshoglund
Last active March 2, 2018 09:40
Show Gist options
  • Save hanshoglund/092735b1aa4ed5f70288e351f6c75c02 to your computer and use it in GitHub Desktop.
Save hanshoglund/092735b1aa4ed5f70288e351f6c75c02 to your computer and use it in GitHub Desktop.

QuickRefact

QuickRefact is a heuristic refactoring tool inspired by QuickCheck

While QC generates random test cases to prove that your code has errors, QR generates random modifications to your source code and tries to prove that they don't break the code, using your standard compiler and test suite as the verifier. The changes are generated based on a Haskell DSL a la QuickCheck. Each random edit is a random change that will either improve the code without affecting its meaning (in which case it is merged), or break the build (in which case it is rejected).

Basic idea how QR works:

  • Start with some Git commit
  • Apply some randomly generated changes to the code, then run build/tests
  • If successful, commit (summarizing changes), if not, revert to the last successful state
  • Repeat until some threshold, or until no more changes can be successfully applied, then notify user (e.g. by doing a PR from the newly generated branch)
  • This could potentially be parallelized also branch out a tree of random changes, and when each branch halts, try various merge orders heuristically etc.

Example edits that could be described in the DSL:

  • Remove redundant language extensions
  • Remove unusued modules and functions
  • Remove redundant imports
  • Formatting, documentation stubs etc.
  • Minimize export/import lists
  • Remove code duplication, consolidate indentical or similar functions etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment