Refactoring a Legacy Codebase One Function at a Time

Accessibility is easiest when it is part of the design from the start rather than something you bolt on before launch. Semantic HTML does most of the heavy lifting for free, and the remaining work is usually about focus management and clear labels.

Where things went wrong

We rolled the change out behind a feature flag to five percent of traffic first. Nothing exploded, the error rate stayed flat, and the response times improved by roughly a third. After a week we turned it on for everyone and deleted the old code path.

  • Use semantic HTML elements wherever possible
  • Make sure every interactive element can be reached by keyboard
  • Give images meaningful alternative text
  • Check colour contrast in both light and dark modes

A better approach

Small pull requests get reviewed faster, get better feedback and are far easier to roll back when something goes wrong. If a change is too big to review in one sitting, it is probably too big to merge safely.

How to get started

Documentation does not have to be long to be useful. A short note explaining why a decision was made is worth more than pages describing what the code already says. Future readers can work out the what; the why is the part that gets lost.

A good rule of thumb is to measure before you change anything. It is remarkable how often the part of the system you are sure is slow turns out to be fine, while something you never thought about is quietly eating half your budget.

Notes from a pairing session

What I would do differently

The first version of anything you build will be wrong in ways you cannot predict. That is not a failure of planning; it is how learning works. The goal is to make those mistakes cheap to discover and cheap to fix.

It started, as these things usually do, with a bug report that made no sense. The page loaded fine for everyone on the team, but a handful of customers were seeing a blank screen. It took two days and one very patient support engineer to work out that the problem only appeared on older phones with a particular browser extension installed.

By the end of the week we had a fix we were proud of, a test that would catch the problem if it ever came back, and a short write-up for the rest of the team. That last part is the one most people skip, and it is often the most valuable.

Code is read far more often than it is written. Every shortcut that saves you five minutes today costs the next person who touches the file a little more time, and that next person is very often you, six months later, with no memory of why you did it.

Posted in

jamie

Leave a Reply

Your email address will not be published. Required fields are marked *