Man up future self!

As a programmer, I have to work with a lot of code that has been written by other people. Sometimes I have to write my own to interface with this code. this is when problems can occur.

When I’m writing code, I do comment as I go along. Most of the time it is sensible and important. Other times I do go off on a ramble and go a bit Monty Python on the comments. One time I did a whole rant, in cod-biblical, about the programmer and coffee!

Then I saw the below XKCD cartoon and that reminded me of many a time when writing code and then having to fix issues with legacy code without trying to break anything else! Sometimes this legacy code was written by myself!

Future selfOne of these was something a colleague wrote to parse a page of text and load it into a database. This piece of code was modified over about ten years but something that was written at the start, and hadn’t been called for many years did strange things. When that code was removed the parse just failed to do anything apart from hang. When it was put back the parse then started to work fine. The reason was never found but we it was left it in as we were scared what would happen [ or what we might summon from a deep pit of hell ] if it was fixed.

This code was looked at occasionally, with a wary eye as all of the programming team we knew this piece of code wasn’t called but was vital for the running of the code. Remove it at your peril. We can only think that is was called at some point, but we couldn’t find the call at all!, and whatever it returned was ignored.

I can’t remember if the above issue was actually commented in the code or was just ignored as there wasn’t that many people who needed to work on that piece of code.

At least with XKCD, your past-self did warn you that the code would break and need a re-write at some point in the future. Better that than run across it at some point. Data paths change, APIs get updated and older versions then get dropped. Twitter did this but that didn’t need a, large, re-write to fix.