Ask HN: How do you improve code for future AI?

2 tmaly 5 5/31/2025, 1:03:44 PM
I am sitting on tons of legacy code at my day job. I keep looking at how fast AI is improving over the last few years.

I am thinking what can I do to improve the massive amount of legacy code I have to maintain so that eventually I can let a better AI in the near future help me more?

What are your best tips that are working now?

Comments (5)

apothegm · 1d ago
AI has limited context windows and little ability to reason about what complex code does.

If you can refactor it to small modules with simple interfaces and properly document the interfaces and what the modules do, AI can work with your code more easily. Think of the ideal AI codebase as being assembled from libraries (even if private internally developed ones) with a small amount of glue code in between.

tmaly · 1d ago
This is exactly the thought I had. The challenge is starting with messy undocumented code that sprawls out all over the place.

How to you go from spaghetti code to nice neat modular code using AI?

apothegm · 20h ago
Ah, getting AI to do that part of the work… hasn’t worked for me. The only thing that it’s been helpful for in that regard is as a rubber duck, which isn’t much. But honestly, the built-in refactoring tools in an IDE are more consistent.

How’s your test coverage? Good E2E tests that treat the codebase like a black box will help a lot, however you approach the actual refactoring. That might conceivably also be something the AI could help you with.

lucfranken · 2d ago
Did you try running some ai over it to see if it is capable of being useful?

Legacy code is a statement but in the end it only matters if it works and is maintainable.

It might surprise you.

tmaly · 1d ago
I got mixed results. A good portion of the code was written by former employees. There is little documentation.