{"id":17291,"date":"2026-08-01T00:32:45","date_gmt":"2026-08-01T00:32:45","guid":{"rendered":"https:\/\/techtrendfeed.com\/?p=17291"},"modified":"2026-08-01T00:32:46","modified_gmt":"2026-08-01T00:32:46","slug":"the-financial-good-thing-about-refactoring","status":"publish","type":"post","link":"https:\/\/techtrendfeed.com\/?p=17291","title":{"rendered":"The Financial Good thing about Refactoring"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<p>As a part of attending to grips with the brand new world of agentic engineering,<br \/>\nI constructed an utility to help my work. It\u2019s a classy app:<br \/>\nhigh-quality internet UI with dynamic refresh and look-up, modals and<br \/>\nauto-save, integrations to exterior methods, machine studying and textual content<br \/>\nevaluation, background jobs, and a correct atmosphere setup with totally<br \/>\nautomated deployment. It\u2019s roughly 150,000 strains of code,<br \/>\nprimarily in Rust (~120 kLoC) with the rest in TypeScript and<br \/>\nTerraform.<\/p>\n<p>This was totally written by brokers. Largely Claude Code, and a few use<br \/>\nof Cursor. I didn\u2019t learn or evaluate any of the code, besides<br \/>\noften, out of curiosity.<\/p>\n<p>Whereas constructing the applying, I may see some issues going<br \/>\nawry. After watching an edit to line 4,000 of a file scroll by within the<br \/>\nterminal, I had a more in-depth look. The info entry layer had grown to over<br \/>\n6,000 strains. As extra options landed, this continued to<br \/>\ndevelop. Each question, learn or write, repeated the identical HTTP request<br \/>\nsetup, the identical JSON encoding and decoding. Finally, it reached 17,155<br \/>\nstrains. In a single Rust file.<\/p>\n<h2 id=\"an-experiment-in-refactoring\">An experiment in refactoring<\/h2>\n<p>The 17,155 line file was your entire knowledge entry layer. A single,<br \/>\nself-contained module. Reviewing the code, there was no<br \/>\nde-duplication, no inner language, restricted extraction of capabilities,<br \/>\nand little or no extraction of lessons. It did have a transparent boundary<br \/>\nwith an interface to protect. It was an important goal for refactoring.<\/p>\n<p>The aim of refactoring an agentic code base is to spend tokens now in<br \/>\nrefactoring to make token consumption for future work decrease. An<br \/>\nexperiment ought to be capable to present that as this file was refactored the<br \/>\ntoken value of creating separate characteristic implementations on this code<br \/>\nbase would lower.<\/p>\n<p>Exactly as a result of brokers by no means be taught this was now doable to run as<br \/>\nan experiment. I may immediate a recent agent to make precisely the identical<br \/>\nchange after each refactoring stage. In contrast to a human engineer, the<br \/>\nexperiment wouldn&#8217;t be tainted by studying from earlier steps.<\/p>\n<ol>\n<li>Create an general refactoring plan, following strict refactoring<br \/>\nself-discipline.<\/li>\n<li>Craft a consultant change, described in a single immediate.<\/li>\n<li>Set up a baseline value of change: in a sub-agent, execute that<br \/>\nimmediate, together with asking the sub-agent to report token consumption.<\/li>\n<li>Throw away the change.<\/li>\n<li>In a loop:\n<ol>\n<li>Apply a single step of the general refactoring.<\/li>\n<li>In a sub-agent, execute <em>precisely<\/em> the identical change receiving the<br \/>\ntoken value of the change.<\/li>\n<li>Throw away the change.<\/li>\n<\/ol>\n<\/li>\n<li>Report all token prices, time to execute the change, and features of<br \/>\ncode after every step of the refactoring, together with the baseline.<\/li>\n<\/ol>\n<p>The immediate used for the consultant change and the refactoring<br \/>\nsteps utilized are proven within the appendices, under.<\/p>\n<p>One caveat: Claude doesn\u2019t present dependable strategies for counting<br \/>\ntokens reside regardless of exhibiting token counts, reporting tokens consumed<br \/>\nper session, and <strong>billing<\/strong> for tokens. I\u2019m assuming it is a<br \/>\nnon permanent problem that can enhance over time. As an alternative, the sub-agent<br \/>\nreported the variety of characters obtained and despatched and used<br \/>\n<a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/github.com\/openai\/tiktoken\">tiktoken<\/a> to approximate tokens, by dividing character rely by<br \/>\n4.<\/p>\n<h2 id=\"results\">Outcomes<\/h2>\n<table>\n<thead>\n<tr>\n<th>Step<\/th>\n<th>Information Entry Layer LoC<\/th>\n<th>Largest file LoC<\/th>\n<th>Complete Rust LoC<\/th>\n<th>Enter tokens per change<\/th>\n<th>Output tokens per change<\/th>\n<th>Time per change (s)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Baseline<\/td>\n<td>17,155<\/td>\n<td>17,155<\/td>\n<td>50,359<\/td>\n<td>159,564<\/td>\n<td>1,705<\/td>\n<td>342<\/td>\n<\/tr>\n<tr>\n<td>Step 1 (FirestoreClient)<\/td>\n<td>16,706<\/td>\n<td>16,706<\/td>\n<td>49,910<\/td>\n<td>155,205<\/td>\n<td>1,723<\/td>\n<td>530<\/td>\n<\/tr>\n<tr>\n<td>Step 2 (extract_doc_id, new_link)<\/td>\n<td>16,562<\/td>\n<td>16,562<\/td>\n<td>49,766<\/td>\n<td>159,227<\/td>\n<td>2,105<\/td>\n<td>574<\/td>\n<\/tr>\n<tr>\n<td>Step 3 (link-query helpers)<\/td>\n<td>16,567<\/td>\n<td>16,567<\/td>\n<td>49,771<\/td>\n<td>154,054<\/td>\n<td>2,105<\/td>\n<td>524<\/td>\n<\/tr>\n<tr>\n<td>Step 4 (FakeStore predicates)<\/td>\n<td>16,577<\/td>\n<td>16,577<\/td>\n<td>49,781<\/td>\n<td>154,146<\/td>\n<td>2,060<\/td>\n<td>654<\/td>\n<\/tr>\n<tr>\n<td>Step 5 (worth ctors)<\/td>\n<td>16,469<\/td>\n<td>16,469<\/td>\n<td>49,673<\/td>\n<td>171,251<\/td>\n<td>2,036<\/td>\n<td>1,353<\/td>\n<\/tr>\n<tr>\n<td>Step 6 (FieldsBuilder)<\/td>\n<td>16,469<\/td>\n<td>16,469<\/td>\n<td>49,673<\/td>\n<td>171,251<\/td>\n<td>2,036<\/td>\n<td>1,353<\/td>\n<\/tr>\n<tr>\n<td>Step 7 (queries.rs)<\/td>\n<td>16,474<\/td>\n<td>15,670<\/td>\n<td>49,678<\/td>\n<td>151,850<\/td>\n<td>1,800<\/td>\n<td>587<\/td>\n<\/tr>\n<tr>\n<td>Step 8 (traits.rs)<\/td>\n<td>16,508<\/td>\n<td>13,845<\/td>\n<td>49,712<\/td>\n<td>132,558<\/td>\n<td>1,723<\/td>\n<td>446<\/td>\n<\/tr>\n<tr>\n<td>Step 9 (traits\/ break up)<\/td>\n<td>16,508<\/td>\n<td>13,845<\/td>\n<td>49,712<\/td>\n<td>132,558<\/td>\n<td>1,723<\/td>\n<td>446<\/td>\n<\/tr>\n<tr>\n<td>Step 10 (codec.rs)<\/td>\n<td>16,521<\/td>\n<td>12,846<\/td>\n<td>49,725<\/td>\n<td>131,871<\/td>\n<td>1,750<\/td>\n<td>540<\/td>\n<\/tr>\n<tr>\n<td>Step 11 (fake_store.rs)<\/td>\n<td>16,535<\/td>\n<td>11,122<\/td>\n<td>49,739<\/td>\n<td>133,016<\/td>\n<td>2,460<\/td>\n<td>600<\/td>\n<\/tr>\n<tr>\n<td>Step 12 (retailer\/ break up)<\/td>\n<td>16,550<\/td>\n<td>9,269<\/td>\n<td>49,754<\/td>\n<td>104,080<\/td>\n<td>2,050<\/td>\n<td>490<\/td>\n<\/tr>\n<tr>\n<td>Step 13 (co-locate assessments)<\/td>\n<td>16,550<\/td>\n<td>9,269<\/td>\n<td>49,754<\/td>\n<td>104,080<\/td>\n<td>2,050<\/td>\n<td>490<\/td>\n<\/tr>\n<tr>\n<td>Step 14 (full fake_store.rs)<\/td>\n<td>16,553<\/td>\n<td>7,225<\/td>\n<td>49,757<\/td>\n<td>107,205<\/td>\n<td>2,453<\/td>\n<td>523<\/td>\n<\/tr>\n<tr>\n<td>Step 15 (retailer\/ break up)<\/td>\n<td>16,608<\/td>\n<td>3,695<\/td>\n<td>49,812<\/td>\n<td>27,360<\/td>\n<td>2,113<\/td>\n<td>454<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The attention-grabbing metrics listed here are the full strains of code within the knowledge<br \/>\nentry layer, the full strains of code within the <em>largest single file<\/em> in<br \/>\nthe information entry layer and the enter tokens consumed whereas producing<br \/>\nthe change.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/martinfowler.com\/articles\/exploring-gen-ai\/steps-chart.png\" class=\"full\" \/><\/p>\n<p>This chart exhibits 4 issues. The primary level is the baseline, step 0,<br \/>\nafter which the identical metrics are repeated <em>after<\/em> every refactoring step<br \/>\nhas been utilized.<\/p>\n<ol>\n<li>The entire strains of code within the knowledge entry layer as a<br \/>\ncomplete. Initially, that is simply the only file I began with. This<br \/>\nturns into many recordsdata as refactorings are utilized. By the tip there<br \/>\nare 19 Rust recordsdata.<\/li>\n<li>The strains of code within the single largest file within the knowledge entry<br \/>\nlayer. This began because the entirety of the information layer within the single<br \/>\npreliminary file.  By the tip, the only largest file is a take a look at<br \/>\nlibrary. Additional refactoring passes may apply the identical strategy<br \/>\nto this.<\/li>\n<li>The entire enter tokens consumed by the sub-agent whereas making use of the<br \/>\nconsultant change.<\/li>\n<li>The entire output tokens produced by the sub-agent whereas making use of<br \/>\nthe consultant change.<\/li>\n<\/ol>\n<h2 id=\"refactoring-reduces-token-consumption\">Refactoring reduces token consumption<\/h2>\n<p>The outcomes are clear. Enter tokens keep pretty flat till the biggest<br \/>\nfile begins to fall, after which they drop earlier than, within the phrases of<br \/>\nClaude, falling off a cliff.<\/p>\n<p>Between the bottom line and the ultimate refactoring, enter tokens for the<br \/>\nidentical activity diminished from <strong>159,564<\/strong> to <strong>27,360<\/strong>. A saving of<br \/>\n<strong>132,204<\/strong> tokens, or <strong>83%<\/strong>. And that saving is just not a one-off. Each single<br \/>\nchange that touches the information entry layer from this level ahead now<br \/>\nprices considerably much less.<\/p>\n<p>How a lot of a saving? Assuming Sonnet 5 pricing on the time of writing<br \/>\nof $3\/MTok, 39.7 cents. Not quite a bit. Does it multiply? How will this<br \/>\nplay out throughout debugging? Extra sophisticated options? That is<br \/>\nrefactoring just one portion of the code base, can the entire code base<br \/>\nbe aggressively refactored to seek out financial savings in every single place? How a lot would<br \/>\nthese refactorings <em>value?<\/em><\/p>\n<p>This saving is as a result of the agent has to learn much less code. However it isn&#8217;t<br \/>\nas a result of there may be much less code to learn. The general code within the knowledge<br \/>\nentry layer as an entire has stayed pretty fixed. Due to this fact to be<br \/>\nin a position to financial institution this saving, the agent should be capable to efficiently<br \/>\ndetermine the smallest subset of recordsdata essential to learn. The outcomes<br \/>\nmake it seem this was taking place. Studying the Claude Code considering<br \/>\noutput and file learn summaries because the change was being utilized additionally<br \/>\nsignifies the sub-agent was efficiently studying smaller and smaller<br \/>\nsections of code every time.<\/p>\n<p>In different phrases, randomly chopping the file into smaller recordsdata is<br \/>\nunlikely to assist as a lot: even when every file have been smaller, the agent<br \/>\ncan be compelled to learn via many recordsdata in search of the related<br \/>\ncode. Whereas the step with the most important impact occurs on the finish, the<br \/>\nearlier steps have been refactorings to arrange this saving. This was not<br \/>\ndeliberate. It was merely a results of how refactoring sometimes proceeds:<br \/>\nnative file adjustments to extract duplication, earlier than breaking down into<br \/>\nsmaller recordsdata as soon as a repeating core emerges.<\/p>\n<p>The refactoring didn&#8217;t make the consultant change smaller. The<br \/>\nvariety of tokens produced when writing code was largely unaffected:<br \/>\nthe output tokens don&#8217;t transfer very a lot. These tokens are 5 instances<br \/>\nthe value of the enter tokens. However, there are quite a bit much less of them. Are<br \/>\nthere refactorings that may very well be utilized to scale back output token<br \/>\nmanufacturing? I would like a extra advanced pattern change to discover these<br \/>\nquestions. The noise of the non-deterministic code technology course of<br \/>\nis hiding any variance brought on by adjustments within the factoring of the code.<\/p>\n<h2 id=\"notes-on-the-process\">Notes on the method<\/h2>\n<p>Claude was not good at refactoring. If you happen to learn the immediate and the<br \/>\nrefactoring steps under, it\u2019s clear that the refactorings produced<br \/>\nhave been instantly in response to the immediate. Claude is unable to have a look at<br \/>\ncode, take a look at refactorings typically and work out that are appropriate<br \/>\nto use: a human must actively information it. This marries with wider<br \/>\nexpertise on this app. The event harness consists of an express<br \/>\nrefactoring step. That refactoring step didn&#8217;t immediate Claude into<br \/>\nenhancing this file. Extra anecdotally, Claude.ai was higher than<br \/>\nClaude Code. I used each interfaces to create the refactoring<br \/>\nplan. Claude Code noticed extract operate as the primary<br \/>\nstep. Claude.ai went additional and noticed a whole consumer class to be<br \/>\nextracted.<\/p>\n<p>It was additionally unhealthy at making use of them. The mechanical act of refactoring<br \/>\nwas carried out by writing Python scripts utilizing grep and sed. These<br \/>\nscripts steadily acquired confused by indentation. Oh, the irony. In<br \/>\naddition, the only most beneficial refactoring was missed within the first<br \/>\ngo, and needed to be re-applied as a follow-up step. This is the reason the<br \/>\nvariety of steps within the determine don\u2019t match the refactoring steps within the<br \/>\nappendix.<\/p>\n<p>It took about eight hours to finish your entire experiment. This was<br \/>\nlargely unattended. The one intervention was after six hours 40<br \/>\nminutes when it appeared to have completed, however had skipped that step<br \/>\nand wanted to be redirected. This experiment was operating on gradual<br \/>\nresort WiFi. I questioned if that contributed to time taken. However on<br \/>\ndeeper evaluation of the code base, the cargo non permanent construct cache had<br \/>\nturn out to be very massive. Check execution was struggling, considerably.<\/p>\n<h2 id=\"further-work-and-broader-implications\">Additional work and broader implications<\/h2>\n<p>Sadly, it didn\u2019t happen to me to carry out a rely of the tokens<br \/>\nrequired to create and execute the refactoring plan till it was<br \/>\nalready full. I\u2019ve checked out my combination consumption throughout the<br \/>\ntime window the place I used to be doing this work, together with designing and<br \/>\noperating the experiment. I can\u2019t say what number of tokens have been required to<br \/>\ncarry out the refactoring. The higher sure is 5 million,<br \/>\nnevertheless. This consists of creating the refactoring plan twice, the work<br \/>\nto design the experiment together with the consultant change, and<br \/>\nvaried different duties. Future work ought to embrace a extra correct rely<br \/>\nof tokens consumed to refactor.<\/p>\n<p>This is only one experiment, on a big utility that&#8217;s<br \/>\nnonetheless greenfield and constructed and maintained by a single developer. However,<br \/>\nI consider it is a probably attention-grabbing first step. This effort<br \/>\nexhibits the worth, in money and time of refactoring. In addition to<br \/>\nmeasuring how costly refactoring is. It could be attention-grabbing to<br \/>\ntake a look at extra advanced adjustments, at wider refactoring, refactoring<br \/>\nrepeatedly, and even the relative worth of various refactoring<br \/>\napproaches.<\/p>\n<p>That is only the start.<\/p>\n<h2 id=\"appendices\">Appendices<\/h2>\n<p><em>Be aware: These appendices embrace the prompts that I used, and the<br \/>\noutput that was returned. The one modifying utilized has been to take away<br \/>\nthe precise code adjustments to be made. These are included with out<br \/>\nmodifying to point out how the brokers have been directed. There aren&#8217;t any hidden<br \/>\ntips. As such, there may be some language in right here that is likely to be<br \/>\ncomplicated. The error is within the authentic.<\/em><\/p>\n<details>\n<summary>The consultant change<\/summary>\n<p>That is the recorded immediate that was fed to every sub-agent, there was<br \/>\nno additional context equipped apart from the code base and accompanying<br \/>\nstructure documentation. Each sub-agent was beginning with precisely<br \/>\nthe identical info.<\/p>\n<blockquote>\n<p>You might be working within the Rust mission at <code>~\/dev\/your-project-name<\/code>.<\/p>\n<p>Add a brand new <code>ItemWatchStore<\/code> public async trait to the Firestore layer, following present patterns precisely. The trait will need to have three strategies:<\/p>\n<ul>\n<li><code>async fn watch_item(&amp;self, item_id: &amp;str, user_id: &amp;str) -&gt; Outcome&lt;()&gt;<\/code><\/li>\n<li><code>async fn unwatch_item(&amp;self, item_id: &amp;str, user_id: &amp;str) -&gt; Outcome&lt;()&gt;<\/code><\/li>\n<li><code>async fn watched_items_for_user(&amp;self, user_id: &amp;str) -&gt; Outcome<vec>&gt;<\/vec><\/code><\/li>\n<\/ul>\n<p>Watches are saved in a <code>item_watches<\/code> Firestore assortment. Every doc has fields: <code>itemId<\/code> (string), <code>userId<\/code> (string), <code>createdAt<\/code> (timestamp). There isn&#8217;t any Rust struct for a watch report \u2014 the strategies return <code>Vec<string><\/string><\/code> (merchandise ids).<\/p>\n<p>Implement the trait for each <code>FakeStore<\/code> (utilizing an in-memory <code>Vec&lt;(String, String)&gt;<\/code> subject added to <code>FakeStoreInner<\/code>) and <code>FirestoreStore<\/code> (utilizing the identical HTTP patterns used for different retailer impls on this file).<\/p>\n<p><strong>On the very finish of your response<\/strong>, output precisely this JSON block (fill in actual values):<\/p>\n<pre><code class=\"language-json\">{\n  \"files_read\": [\n    {\"path\": \"src\/firestore.rs\", \"chars\": 123456},\n    ...\n  ],\n  \"response_chars\": 7890\n}\n<\/code><\/pre>\n<p>Do NOT commit the change. Cease after writing the code.<\/p>\n<\/blockquote>\n<\/details>\n<details>\n<summary>Refactoring steps<\/summary>\n<p>That is the immediate that was used to create the refactoring plan.<\/p>\n<blockquote>\n<p>Following the strict definition {that a} refactoring is a provably<br \/>\ncorrectness preserving sequence of code edits, and utilizing Martin<br \/>\nFowler\u2019s 2nd version of Refactoring because the supply, study<br \/>\n@src\/firestore.rs. This can be a 17K LoC Rust file. No file needs to be<br \/>\nthat lengthy. It&#8217;s nearly actually not utilizing an inner language to<br \/>\nconstruct and handle queries. Produce and describe, however don\u2019t execute, a<br \/>\nsequence of refactorings that will massively cut back the road rely<br \/>\nof that file, with out altering the interface in any respect.<\/p>\n<\/blockquote>\n<p>Following is the outline of the refactorings utilized, extracted<br \/>\nfrom the plan constructed and adopted by Claude. The precise plan consists of<br \/>\npredicted code adjustments. For every refactoring, the person steps to<br \/>\nobserve have been listed. Every of these steps was individually testable, and<br \/>\nwas individually examined. This can be a stricter refactoring than most<br \/>\nhuman engineers would observe.<\/p>\n<p>The steps listed right here don\u2019t line up instantly with the measured adjustments<br \/>\nabove as Claude skipped essentially the most useful single refactoring<br \/>\n(splitting out the shop into sub-files) on the primary go and needed to<br \/>\nfull that afterwards as two extra steps.<\/p>\n<p><strong>Fowler ref:<\/strong> <em>Extract Class<\/em> (7.5); <em>Extract Operate<\/em> (6.1) for<br \/>\nevery primitive<\/p>\n<p><code>FirestoreStore<\/code> at the moment conflates two tasks:<\/p>\n<ul>\n<li><strong>Area question orchestration<\/strong> \u2014 which question to run, which paperwork<br \/>\nto put in writing,  parse outcomes into area sorts<\/li>\n<li><strong>Firestore HTTP transport<\/strong> \u2014 auth headers, URL development, JSON<br \/>\nencoding\/decoding of Firestore wire sorts,<br \/>\nretry-on-PRECONDITION_FAILED<\/li>\n<\/ul>\n<p>Fowler \u00a77.5 requires extracting a brand new class when you&#8217;ll be able to determine a<br \/>\ncoherent subset of a category\u2019s knowledge and behavior. The transport<br \/>\naccountability owns: <code>consumer: reqwest::Consumer<\/code>, <code>project_id: String<\/code>,<br \/>\n<code>MetadataAuth<\/code>, and <code>documents_url()<\/code> \/ <code>auth_header()<\/code>. Extract these<br \/>\ninto a brand new <code>FirestoreClient<\/code> struct.<\/p>\n<p><strong>Estimated financial savings: ~1,200 strains in <code>FirestoreStore<\/code> impls;<br \/>\n<code>FirestoreClient<\/code> provides ~120 strains web.<\/strong><\/p>\n<h4 id=\"step-2--extract-function-extractdocid-and-newlink-fowler-61\">Step 2 \u2014 Extract Operate: <code>extract_doc_id<\/code> and <code>new_link<\/code> (Fowler \u00a76.1)<\/h4>\n<p><strong>Fowler ref:<\/strong> <em>Extract Operate<\/em> (6.1)<\/p>\n<ul>\n<li>\n<p><strong><code>extract_doc_id<\/code><\/strong> \u2014 The expression<br \/>\n<code>doc.title.rsplit('\/').subsequent()?.to_string()<\/code> seems verbatim on the<br \/>\nbegin of all 20 <code>parse_*_document<\/code> capabilities. Extract it.<\/p>\n<\/li>\n<li>\n<p><strong><code>new_link<\/code><\/strong> \u2014 Constructing a <code>Hyperlink<\/code> struct with <code>metadata:<br \/>\nHashMap::new()<\/code> and <code>provenance: None<\/code> and a recent UUID seems 62<br \/>\ninstances. Extract a manufacturing unit operate.<\/p>\n<\/li>\n<\/ul>\n<p><strong>Estimated financial savings: ~500 strains<\/strong> (62 \u00d7 ~10-line structs \u2192 62 \u00d7<br \/>\n~2-line calls; 20 parse capabilities every lose 1 line of boilerplate).<\/p>\n<p><strong>Fowler ref:<\/strong> <em>Extract Operate<\/em> (6.1)<\/p>\n<p>Two sub-patterns recur contained in the <code>FirestoreStore<\/code> trait impls after operating a hyperlink question:<\/p>\n<ul>\n<li>\n<p><strong>Sample A \u2014 gather all hyperlink paperwork from question rows (~15<br \/>\nwebsites).<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>Sample B \u2014 question hyperlinks and return precisely one goal ID, error if<br \/>\nlacking (~8 websites):<\/strong><\/p>\n<\/li>\n<\/ul>\n<p><strong>Estimated financial savings: ~200 strains.<\/strong><\/p>\n<p><strong>Fowler ref:<\/strong> <em>Extract Operate<\/em> (6.1)<\/p>\n<p>Contained in the FakeStore impls, ~15 strategies repeat variations of<br \/>\n<code>inside.hyperlinks.iter()...<\/code>.<\/p>\n<p>Extract two strategies on <code>FakeStoreInner<\/code>. The 15 callsites then turn out to be<br \/>\nsingle-line. Strategies that moreover filter by a second predicate<br \/>\n(e.g. additionally checking <code>to_kind<\/code>) chain <code>.into_iter().filter(\u2026)<\/code> on the<br \/>\nresults of the helper.<\/p>\n<p><strong>Estimated financial savings: ~120 strains.<\/strong><\/p>\n<h4 id=\"step-5--replace-inline-code-with-function-call--4-firestore-value-constructors\">Step 5 \u2014 Change Inline Code with Operate Name \u00d7 4: Firestore worth constructors<\/h4>\n<p><strong>Fowler ref:<\/strong> <em>Change Inline Code with Operate Name<\/em> (8.5)<\/p>\n<p>Add 4 non-public free capabilities (file-level, not strategies) earlier than the<br \/>\ncodec block. Change all 128+ <code>json!({\"stringValue\": \u2026})<\/code> \/<br \/>\n<code>json!({\"timestampValue\": \u2026})<\/code> and so forth. inline expressions with calls to<br \/>\nthese capabilities. Every multi-word json macro name turns into a single<br \/>\nbrief name.<\/p>\n<p><strong>Estimated financial savings: ~80 strains (largely from multi-line json macros collapsing to one-liners).<\/strong><\/p>\n<p><strong>Fowler ref:<\/strong> <em>Extract Class<\/em> (7.3)<\/p>\n<p>The ~20 encoder capabilities all observe this form:<\/p>\n<pre><code class=\"language-rust\">let mut fields = serde_json::Map::new();\nfields.insert(\"foo\".to_string(), str_val(&amp;x.foo));\nfields.insert(\"bar\".to_string(), ts_val(x.bar));\njson!({\"title\": path, \"fields\": fields})\n<\/code><\/pre>\n<p>Extract a small builder. Rewrite every encoder operate to make use of the<br \/>\nbuilder. A ~40-line encoder shrinks to ~12 strains.<\/p>\n<p><strong>Estimated financial savings: ~500\u2013600 strains throughout the 20 encoder capabilities.<\/strong><\/p>\n<p><strong>Fowler ref:<\/strong> <em>Transfer Operate<\/em> (8.1)<\/p>\n<p>Convert <code>src\/firestore.rs<\/code> to a module listing: rename to<br \/>\n<code>src\/firestore\/mod.rs<\/code>. Then create <code>src\/firestore\/queries.rs<\/code> and<br \/>\ntransfer all 32 <code>LinkQuery<\/code> constants and the<br \/>\n<code>LinkQuery<\/code>\/<code>EqFilter<\/code>\/<code>EqValue<\/code>\/<code>Ordering<\/code>\/<code>Route<\/code> kind<br \/>\ndefinitions into it. Add <code>pub(tremendous) use queries::*;<\/code> in <code>mod.rs<\/code>.<\/p>\n<p>No behaviour adjustments; all callsites already reference names that have been<br \/>\nin scope by way of the flat file.<\/p>\n<p><strong>Reduces <code>mod.rs<\/code> by ~800 strains.<\/strong><\/p>\n<p><strong>Fowler ref:<\/strong> <em>Transfer Operate<\/em> (8.1)<\/p>\n<p>Transfer all 17 <code>pub trait<\/code> definitions (and their related error sorts)<br \/>\nto <code>src\/firestore\/traits.rs<\/code>. Re-export them from <code>mod.rs<\/code> with <code>pub<br \/>\nuse traits::*;<\/code>.<\/p>\n<p><strong>Reduces <code>mod.rs<\/code> by ~1,900 strains. Produces a ~1,900-line <code>traits.rs<\/code><br \/>\nthat wants additional decomposition.<\/strong><\/p>\n<h4 id=\"step-9--move-function-split-traitsrs-into-a-traits-module-directory\">Step 9 \u2014 Transfer Operate: break up <code>traits.rs<\/code> right into a <code>traits\/<\/code> module listing<\/h4>\n<p><strong>Fowler ref:<\/strong> <em>Transfer Operate<\/em> (8.1)<\/p>\n<p>Convert <code>src\/firestore\/traits.rs<\/code> to a module listing by grouping the 17 traits into 4 domain-aligned recordsdata:<\/p>\n<table>\n<thead>\n<tr>\n<th>File<\/th>\n<th>Traits<\/th>\n<th>Approx strains<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>traits\/planning.rs<\/code><\/td>\n<td><code>ConcentrationStore<\/code>, <code>GoalStore<\/code>, <code>ItemStore<\/code>, <code>NoteStore<\/code>, <code>PursuitStore<\/code>, <code>FocusPassStore<\/code><\/td>\n<td>~650<\/td>\n<\/tr>\n<tr>\n<td><code>traits\/content material.rs<\/code><\/td>\n<td><code>CaptureStore<\/code>, <code>TagStore<\/code>, <code>UrlReferenceStore<\/code>, <code>DocumentStore<\/code>, <code>PaperStore<\/code><\/td>\n<td>~550<\/td>\n<\/tr>\n<tr>\n<td><code>traits\/individuals.rs<\/code><\/td>\n<td><code>ThoughtworkerStore<\/code>, <code>ExternalContactStore<\/code>, <code>CompanyStore<\/code><\/td>\n<td>~300<\/td>\n<\/tr>\n<tr>\n<td><code>traits\/system.rs<\/code><\/td>\n<td><code>SessionState<\/code>, <code>LinkStore<\/code>, <code>SuggestionStore<\/code>, <code>SuggestionVetoStore<\/code>, <code>OAuthTokenStore<\/code>, <code>MigrationLedger<\/code>, <code>EmbeddingStore<\/code>, <code>RuntimeConfigStore<\/code>, <code>SalesforceSyncStateStore<\/code><\/td>\n<td>~400<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><code>traits\/mod.rs<\/code> turns into a pure re-export file (~20 strains). Related<br \/>\nerror sorts (<code>FocusPassError<\/code>, <code>SuggestionDecisionError<\/code>, and so forth.) transfer<br \/>\nwith the trait that produces them.<\/p>\n<p><strong>No trait definition adjustments, no callsite adjustments \u2014 solely<br \/>\nrelocation. Every ensuing file is 300\u2013650 strains.<\/strong><\/p>\n<p><strong>Fowler ref:<\/strong> <em>Transfer Operate<\/em> (8.1)<\/p>\n<p>Transfer all doc encoder\/decoder capabilities (<code>*_document<\/code>,<br \/>\n<code>parse_*_document<\/code>, <code>kind_str<\/code>, <code>parse_kind<\/code>, <code>parse_capture_source<\/code>,<br \/>\n<code>parse_outcome<\/code>, and so forth.) plus <code>FieldsBuilder<\/code> and the worth constructors<br \/>\nfrom Steps 5 and 6 into <code>src\/firestore\/codec.rs<\/code>. Make them<br \/>\n<code>pub(tremendous)<\/code>.<\/p>\n<p>After Step 6 this module can be ~400\u2013500 strains relatively than ~1,200.<\/p>\n<p><strong>Reduces <code>mod.rs<\/code> by ~500 strains (post-Step-6).<\/strong><\/p>\n<p><strong>Fowler ref:<\/strong> <em>Transfer Operate<\/em> (8.1)<\/p>\n<p>Transfer <code>FakeStore<\/code>, <code>FakeStoreInner<\/code>, and all 18 trait impl blocks for<br \/>\n<code>FakeStore<\/code> into <code>src\/firestore\/fake_store.rs<\/code>. Re-export <code>FakeStore<\/code><br \/>\nfrom <code>mod.rs<\/code> with <code>pub use fake_store::FakeStore;<\/code>.<\/p>\n<p><code>FakeStoreInner<\/code> and helper strategies keep non-public to the module.<\/p>\n<p><strong>Reduces <code>mod.rs<\/code> by ~4,700 strains.<\/strong><\/p>\n<h4 id=\"step-12--move-function-split-firestorestore-impls-into-per-trait-files-under-srcfirestorestore\">Step 12 \u2014 Transfer Operate: break up <code>FirestoreStore<\/code> impls into per-trait recordsdata beneath <code>src\/firestore\/retailer\/<\/code><\/h4>\n<p><strong>Fowler ref:<\/strong> <em>Transfer Operate<\/em> (8.1)<\/p>\n<p>Create <code>src\/firestore\/retailer\/mod.rs<\/code> with <code>FirestoreStore<\/code> struct<br \/>\ndefinition, <code>impl FirestoreStore<\/code> (constructor + <code>FirestoreClient<\/code><br \/>\nfrom Step 1), and <code>MetadataAuth<\/code>.<\/p>\n<p>Then create one file per logical area grouping.<\/p>\n<p>Every file accommodates solely <code>use tremendous::*;<\/code> (or express imports) and the<br \/>\ntrait impl block(s). No kind definitions, no helpers. Helpers utilized by<br \/>\na number of impl blocks keep in <code>retailer\/mod.rs<\/code>.<\/p>\n<p><strong>Reduces what can be a ~10,000-line file into ten recordsdata of 120\u2013650<br \/>\nstrains every. <code>mod.rs<\/code> turns into a ~100-line re-export manifest.<\/strong><\/p>\n<h4 id=\"step-13--move-function-co-locate-tests-with-their-modules\">Step 13 \u2014 Transfer Operate: co-locate assessments with their modules<\/h4>\n<p><strong>Fowler ref:<\/strong> <em>Transfer Operate<\/em> (8.1)<\/p>\n<p>The prevailing <code>#[cfg(test)]<\/code> modules take a look at particular area areas and<br \/>\nbelong with the modules created in Step 12 relatively than in a single<br \/>\n<code>assessments.rs<\/code>.Every take a look at module strikes inside a <code>#[cfg(test)] mod assessments { \u2026<br \/>\n}<\/code> block on the backside of the goal file, with <code>use tremendous::*;<\/code> to<br \/>\nentry the module\u2019s internals. No take a look at is modified, solely relocated.<\/p>\n<p>Any shared take a look at fixtures (<code>FakeStore::new<\/code>, helper builders) which are<br \/>\nalready in <code>fake_store.rs<\/code> are accessible by way of the prevailing <code>use<br \/>\ntremendous::fake_store::FakeStore<\/code> import chain.<\/p>\n<p><strong>Reduces <code>mod.rs<\/code> by ~2,000 strains; every goal file beneficial properties 200\u2013700<br \/>\nstrains of assessments which are instantly adjoining to the code they train.<\/strong><\/p>\n<\/details>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>As a part of attending to grips with the brand new world of agentic engineering, I constructed an utility to help my work. It\u2019s a classy app: high-quality internet UI with dynamic refresh and look-up, modals and auto-save, integrations to exterior methods, machine studying and textual content evaluation, background jobs, and a correct atmosphere setup [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":17293,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56],"tags":[9994,9993,7913],"class_list":["post-17291","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-benefit","tag-economic","tag-refactoring"],"_links":{"self":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/17291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17291"}],"version-history":[{"count":1,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/17291\/revisions"}],"predecessor-version":[{"id":17292,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/17291\/revisions\/17292"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/media\/17293"}],"wp:attachment":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- This website is optimized by Airlift. Learn more: https://airlift.net. Template:. Learn more: https://airlift.net. Template: 69d9690a190636c2e0989534. Config Timestamp: 2026-04-10 21:18:02 UTC, Cached Timestamp: 2026-08-01 07:07:05 UTC -->