frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

The Economic Benefit of Refactoring

https://martinfowler.com/articles/exploring-gen-ai/refactoring-economic-benefit.html
39•javaeeeee•1h ago

Comments

defrim•41m ago
Being a bit cheeky here -- the amount of comments on this post is a telltale sign of how common / desirable refactoring is for the majority of developers (xD). It isn't our fault though, maybe if those pesky managers read this article then they would understand..
sltr•34m ago
It's been on HN for 45 minutes. It's before 9am on the west coast
imoverclocked•37m ago
It’s interesting that cyclomatic complexity or cognitive complexity scales with token usage. A codebase that enforces upper bounds on one of these two also (potentially) helps AI agents stay efficient.
vaylian•35m ago
Interesting take-away:

> Claude is unable to look at code, look at refactorings in general and work out which are suitable to apply: a human needs to actively guide it.

Claude is happy to produce a very large Rust file. But you need human guidance to make it smaller.

vehemenz•3m ago
"I would have written a shorter letter but did not have the time"
sltr•34m ago
the punchline: "Refactoring reduces token consumption"

I appreciate the effort to quantify the benefit rather than pontificate. It's worth mentioning Martin Fowler wrote a whole book on refactoring [1], in which he states, "to refactor, the essential precondition is [...] solid tests", which I think is the real benefit here, AI or not. Good tests protect against regressions, whether human or robot. They also help encode the spec, which humans and robots can read.

[1] https://www.oreilly.com/library/view/refactoring-improving-t...

pmg101•31m ago
(Just to note that although the article is on martinfowler.com Martin is not the author. It's attributed to Thoughtworks CTO Giles Edwards-Alexander.)
sltr•25m ago
Thanks for catching that. Updated my post
pmg101•33m ago
It's very interesting to have some data on this.

It matches my experience which is that LLMs greatly benefit from well factored code, but are not particularly adept at creating such code.

Much like most human developers I suppose!

danbruc•15m ago
Interesting that the amount of code essentially remained unchanged. In my experience it is not unusual that refactoring messy code cuts the number of lines in half.
stingraycharles•13m ago
It can go both ways. Lines of code is a terrible metric for pretty much any goal that refactorings are meant to tackle.
NichoPaolucci•4m ago
I don’t know. LOC to me is indispensable for certain refactoring goals in my opinion.

Taking a component and turning it from 7K lines to 3K lines and maintaining functionality obviously means there’s less complexity introduced, less to go wrong now, and less overhead to modify in the future.

Sure it can go the other way, the component needs to support something it might need, we need to adjust larger patterns, this function needs to be refactored into something more robust.

But lines of code is a pretty decent metric of success for “trimming down and cleaning up” style refactoring, to me at least. It’s not everything of course, but it’s definitely an indicator.

paxys•14m ago
I have been enforcing this myself through AGENTS files and other explicit instructions. What’s crazy is that none of the existing coding harnesses include such instructions by default. Two lines in Claude Code and Codex and the entire world would be writing better, more efficient code. Makes me believe in the conspiracy that these companies want more verbose code and longer files because it directly results in higher token usage.
theturtletalks•13m ago
Make it work, make it right, make it fast, in that order

Make it right is the refactoring

firasd•12m ago
I think this is one of those things where a human in the loop is indispensable

An agentic refactoring pass does make sense cause one LLM reviewing work can spot things the ‘generator’ LLM missed while focused on the initial task output

But can the reviewer agent ever actually have in mind what this project actually is? And how the code all comes together to do the work involved? In other words what parts of the code are redundant or can be made more elegant

Asking coding agents to refactor your codebase is maybe like asking trauma surgeons to increase your exercise capacity. The agents are gonna need a really holistic POV to do this properly

I guess part of my point is that just splitting big files into multiple files is only refactoring in a superficial sense without having a theory of what code belongs together and what can be extracted into utility functions etc

vehemenz•5m ago
Opus/Fable 5 (or really, any thinking model) do a better job of refactoring than Sonnet would. I think the takeaways are still valid, just not as valid when using a more expensive model at a higher effort level.
BenoitEssiambre•5m ago
The benefits go beyond reducing token consumption. Compact contexts also foster better reasoning, enable intelligence across more layers if you can load them in a single context, and writing software to enable this, results in more correct software, software that _generalizes_, that has higher probability of being correct not just for tested cases, but for the interpolations and extrapolations of these cases.

Refactoring towards good abstractions is more powerful than people realize. There's information theoretic bayesian math to back this up.

It's a bit of a divine coincidence that software that is more economically and energy efficient to process and run tends to also be more correct.

It's all about reducing the entropy of your code. https://benoitessiambre.com/entropy.html

hammock•1m ago
> It's all about reducing the entropy of your code

In all corners of our world and the universe at large, reducing entropy in anything can be thought of as “building.”

Gemini Robotics 2 brings whole body intelligence to robots

https://deepmind.google/blog/gemini-robotics-2-brings-whole-body-intelligence-to-robots/
154•ai2027•1h ago•108 comments

Physicists Solve a Muon Mystery. Now, Old Results Don't Add Up

https://www.quantamagazine.org/physicists-solve-a-muon-mystery-now-old-results-dont-add-up-20260729/
35•ibobev•1h ago•0 comments

The Economic Benefit of Refactoring

https://martinfowler.com/articles/exploring-gen-ai/refactoring-economic-benefit.html
40•javaeeeee•1h ago•20 comments

SDL_GPU minimal, single-header, high-performance 2D graphics painting library

https://github.com/n67094/sdl_gp
30•n67094•1h ago•9 comments

Hacker Public Radio

https://hackerpublicradio.org/
47•bmacho•2h ago•4 comments

Launch HN: Prized (YC S26) – Let non-engineer staff build secure internal tools

https://prized.dev
39•marinoseliades•3h ago•20 comments

RFC 8890 – The Internet is for End Users (2020)

https://mnot.net/blog/2020/for_the_users
59•notarobot123•3h ago•17 comments

Upper stage impacting the moon on 2026 August 5

https://www.projectpluto.com/25010d.htm
46•ryannevius•3h ago•11 comments

RCade: The Arcade Cabinet with CI/CD Deployment, Custom Graphics Card for CRT [video]

https://www.youtube.com/watch?v=W-OpIbLUOU0
12•evakhoury•19h ago•0 comments

Ron Gilbert started production on Thimbleweed Park 2

https://www.grumpygamer.com/twp2_announce/
173•alberto-m•8h ago•81 comments

Paging Through a Parquet File in DuckDB: File_row_number or Offset?

https://rusty.today/blog/paging-parquet-duckdb-file-row-number-vs-offset/
20•rustyconover•1h ago•3 comments

Show HN: Claude-account – switch Claude Code accounts without logging in again

https://github.com/hamzarehmandeveloper/claude-account
7•hamza_rehman•1h ago•3 comments

Gpiozero Flow

https://bennuttall.com/blog/2026/07/gpiozero-flow/
106•benn_88•5h ago•33 comments

Are We Stuck with Lean?

https://mathoverflow.net/questions/513742/are-we-stuck-with-lean
59•jjgreen•4h ago•24 comments

Mbodi AI (YC P25) Is Hiring Robotics/Research Engineers

https://www.ycombinator.com/companies/mbodi-ai/jobs
1•chitianhao•4h ago

The Alice and Bob After Dinner Speech (1984)

https://hex.ooo/library/alicebob.html
25•kamma4434•3d ago•4 comments

Building a native C# implementation of CEL engine

https://bsid.io/writing/building-a-cel-engine-for-net
27•jackedEngineer•2d ago•4 comments

3D Pinball for Windows (1995)

https://98.js.org/programs/pinball/space-cadet.html
52•mushstory•5h ago•25 comments

Why Don't People Use Formal Methods? (2019)

https://www.hillelwayne.com/post/why-dont-people-use-formal-methods/
83•Thom2503•4h ago•59 comments

Show HN: I think I made my own web version of minimalistic audacity

https://github.com/askpext/HERTZ
5•askadityapandey•1h ago•2 comments

Trusted URLs via Cryptographic Signatures

https://blog.certisfy.com/2026/04/trusted-urls-via-cryptographic.html
8•Edmond•1h ago•8 comments

Go LLM SDK for streaming, tool-calling AI backends (plus frontend React lib)

https://github.com/grafana/ai-sdk
42•matryer•4h ago•13 comments

The Lost Civic Life of Movie Rental Stores

https://thereader.mitpress.mit.edu/the-lost-civic-life-of-movie-rental-stores/
50•facundo_olano•2h ago•53 comments

The Glass Famine

https://edconway.substack.com/p/the-glass-famine
84•baud147258•3d ago•37 comments

CosmosEscape: Taking over Every Database in Azure Cosmos DB

https://www.wiz.io/blog/cosmosescape-taking-over-every-database-in-azure-cosmos-db
39•uvuv•4h ago•10 comments

Azulejo

https://en.wikipedia.org/wiki/Azulejo
133•Amorymeltzer•1d ago•43 comments

Why Is Everyone Trying to Build a Solid-State Battery?

https://www.construction-physics.com/p/why-is-everyone-trying-to-build-a
84•crescit_eundo•3h ago•92 comments

Google will expand age checks on Android worldwide till the end of the year

https://android-developers.googleblog.com/2026/07/google-play-age-signals-api-safer-experiences.html
262•dmantis•6h ago•296 comments

The first watch featuring computer functions

https://by.seiko-design.com/140th/en/topic/58.html
71•stefanv•4d ago•28 comments

You can't solve computer use by ignoring the interface

https://steelmanlabs.com/blog/computer-use-is-far-from-solved
42•mpavlov•5h ago•22 comments