I used Fable to rewrite 65kLoC to Rust. It cost $400.

I used Fable to rewrite 65kLoC to Rust. It cost $400.

· 4 min

I kept joking that I would have learned Rust a long time ago, but C++ money is not enough for a decent fursuit. Moreover, I’m bald, so I cannot simply dye my hair blue.

But then two things happened at once.

First, I tried the /teach skill by Matt Pocock 1 to learn Rust, and it clicked: “Teach a C++ programmer idiomatic Rust, skip syntax and helloworld, only focus on main differences.”
This skill is like a personal trainer — overcoming the pleasant challenge keeps me engaged, and at the same time, the material never gets overwhelming. I recommend trying it.

Around the same time, I came across “Rewriting Bun in Rust” 2 and got curious about the method:

Each dynamic workflow was a loop like this – a workflow for:

  • Generate a porting guide mapping Zig patterns & types to Rust patterns & types
  • Mechanically port every .zig file to a .rs file, matching the PORTING.md and LIFETIMES.tsv
  • Fix every crate’s compiler errors
  • Get subcommands like bun test or bun build to work
  • Get every test in Bun’s entire test suite to pass
  • Several large refactors and cleanup passes

The cost of this project was 535496 lines for $165000.

I had an idea that a rewrite could be done much cheaper using some intermediate representation.

Show me your flowcharts and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won’t usually need your flowcharts; they’ll be obvious. — Fred Brooks

This applies to any LLM, but Fable 5 specifically traces the data flow with insane precision. If you can rephrase your problem as a data problem, it can autonomously do complex refactorings, rewrite from one language to another, extract or merge services — in other words, make fundamental changes.

The three steps

Ask the LLM to represent your code as any combination of:

  • graphs
  • ontologies
  • hierarchical state machines
  • UML process charts
  • constraints
  • math formulae

2. Operate on the representation

At this point, you can ask it to simplify the state machine by reducing the number of states, or to remove hidden channels of communication (e.g. via a shared table, or by sharing addresses in RAM).

3. Put the representation back into code

Now ask for the code — even in another programming language.

The secret sauce

For some time now, agents have excelled at tool use, and insofar as they are able to treat other agents as tool invocations. — a post by Anthropic 3

What it means on practice is, prohibit Fable read and write code, and instruct to orchestrate subagents instead. In that way Fable will spare its context window during tens-hours-long runs, and token cost will be also reasonable.

You can add to Fable’s prompt:

avoid extensive `Glob`/`Grep`/`WebSearch`/`Bash` - use `Explore` agents instead
avoid extensive `Edit`/`Bash` - use `general-purpose` sonnet or haiku subagents instead
use `Read` sparingly, to verify critical claims yourself

Glob, Grep, and WebSearch are names of Claude Code’s built-in tools.

I hope that helps. Happy coding.

P.S. The 65kLoC is rune — a terminal editor for the LLM era:

  • Obsidian × VSCode in your terminal, with ⌘ – keystrokes
  • The main focus is markdown and syntax highlight; language servers and debuggers are for agents
    • Markdown tables
    • Obsidian vaults, with [[wikilinks]]
    • - [x] buy the milk tasks
  • Auto-merge, crash data recovery, and much more…

···

Photo by Laura Rivera on Unsplash

Liked this? Grab the RSS feed to get notified.

Source link

Share:

Leave a Reply

3 latest news
News Archives
On Key

Related Posts