# Refactoring Code Through Library Design

*Žiga Kovačič, Justin Chiu, Celine Lee, Wenting Zhao, Kevin Ellis*

[NeurIPS page](https://neurips.cc/virtual/2026/poster/151047) · [OpenReview](https://openreview.net/forum?id=dOkgsUfJSn) · [alphaXiv](https://www.alphaxiv.org/abs/2506.11058) · [Open on the map](../papers.html#p151047)

Category: [LLM Agents, Evals & Benchmarks](../pcat/17.md) › [Software Engineering Benchmarks](../pgroup/646.md) · Type: new method · Keywords: code refactoring, library generation, divide-and-conquer, sample-and-rerank, software maintainability, program size metrics

Areas: [Code & Coding Agents](../areas/codegen.md) › Code Verification › Verified code generation; [AI Agents](../areas/agents.md) › Agent Benchmarking › Agentic code and proof generation

## Summary
Librarian is a method that uses divide-and-conquer and sample-and-rerank to refactor code into reusable libraries, improving refactoring quality as measured by Minimum Description Length.

## Explained to a 5-year-old
People write computer code to make programs do things. Sometimes a piece of code solves a problem that happens often. It would be nice if that piece could be saved and used again later. Making code that can be saved is called refactoring. Refactoring means breaking big code into smaller, useful parts. A good refactoring makes the code easier to understand and change.

## Explained to a 5-year-old, longer
Computers need instructions called code to do things. Sometimes a piece of code solves a problem that happens often. It would be nice if that piece could be saved and used again later. Making code that can be saved is called refactoring. Refactoring means breaking big code into smaller, useful parts. A good refactoring makes the code easier to understand and change. Researchers looked at how to tell if a refactoring is good. They found that measuring how big the code is helps predict good refactorings. They also compared old ways of measuring code quality and found them less reliable. Then they created a new way to group code pieces using a divide-and-conquer idea. This new way also picks the best pieces to put into a library. The new method was tested on real-world Python programs and performed better than previous methods.

## For a technical reader
The paper addresses the challenge of turning ad-hoc code snippets into reusable libraries. It proposes a divide-and-conquer pipeline that first partitions code and then re-ranks candidate components to form libraries. Evaluation on real Python projects shows superior performance over existing library generation techniques. The work also validates the use of program size metrics like Minimum Description Length for assessing refactoring quality.

## Problem
Developers need to refactor specialized solutions into reusable components, and existing software engineering metrics often fail to predict which refactorings are most effective. This paper investigates how to evaluate refactoring quality, especially when automated code agents are used.

## Method
The approach decomposes code into smaller modules using a divide-and-conquer strategy and then selects and re-ranks candidate library components to form reusable libraries. It is evaluated on real-world Python programs and compared against existing library generation methods.

## Results
The approach shows that Minimum Description Length proxies predict refactoring preferences better than Maintainability Index, and it outperforms existing library generation methods on real-world Python programs.

## Contributions
The paper introduces a systematic evaluation of refactoring quality using program size proxies and presents a new method for generating reusable libraries via divide-and-conquer and sample-and-rerank.

## Practical relevance
The findings help developers create more maintainable and reusable code libraries, especially when using automated code agents.

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. [Suggest a correction](../feedback/?on=p/151047)
