top | item 41691946

(no title)

impostervt | 1 year ago

A few months ago I started a job where I inherited a JS code base that is around 250,000 lines. It was one big class, with several sub classes, that did everything. Some files were 30k lines long.

No frameworks, no reactivity. If you click a button, you had to update everything on the screen with event listeners manually.

Took the guy years to write it. It's like a monk got locked in a cell for years with a basic book of javascript.

I started by refactoring into web components, because I had to do it piecemeal. It's been a big help, and I've cut 50k lines of code so far. But the real point was to just learn everything the old code was doing before I start a rewrite.

discuss

order

Sammi|1 year ago

> I started by refactoring into web components, because I had to do it piecemeal.

Yes. The key to making an old and arcane code base understandable to yourself, is to refactor one small part of it at a time. That you're redoing with web components is just one way that would achieve this. I applaud you for not just throwing everything it away and starting anew.

On risk of this approach is that you get some way though and then move on to some other project, and someone else comes along and inherits the old project and starts refactoring in their own style, and so now you have an old arcane code base in three different styles... it still beats a rewrite of a 250.000 line code base in one go.