This week's editorial is a guest post from Phil Factor.
Occasionally, I blink with amazement at some inscrutable code I’ve written and wonder what I’d consumed before writing it. Some beverages make you think you’re writing good code when it is lousy, whilst others make you write good code but forget to document it. In both cases, me-in-the-present roundly curses me-in-the-past. I’ve never found a stimulant such as coffee that makes you write good code as well as document it.
It helps, when picking up the pieces, to remember what type of tea or coffee you drank before an exacting programming task and drink the same stuff before you try to understand it. Beware, though: It depends. Sometimes, you need a different perspective on your code from the giddy moment of inspiration. If you write code under the influence of stimulants, you need to test it without, or vice versa. One old programmer advised me, a long time ago, “Never test code sober if you wrote it whilst sober”. The converse is, he suggested, also advisable.
Although, in an emergency, strong coffee is useful, we working programmers, whatever fancy names we give ourselves, only prosper by finding the means to deliver satisfactory code whatever our mood or location. Whether we are holed up in our quiet study at home, crouched on a plastic chair in an open-plan office whilst trying to ignore the ambient prattling, squatting on the floor of the server room, or surrounded by anxious chatterboxes on a site visit, we still have to deliver consistently reliable code: maybe not of our best. Perhaps that is the real value of the professional programmer. We leave the flashes of brilliance to the amateurs and academics: we just deliver consistent and reliable output whatever the background noise or discomfort. We all have our coping strategies to achieve this, but I’ve long since abandoned the technique of drinking too much tea, coffee or Jack Daniels.