Be Kind to Future-You

An early mentor of mine described the starting point of a development effort, feature implementation, or a debugging session as

The Point of Maximum Ignorance

Besides it being the point where the client wants a fixed-price bid, it is also the point where Past You can do the most good for Future You

When one is coding a feature and comes to the error handling, one has a choice: throw an Exception("Something went wrong") or pay some of the debugging work forward. That point of error handling is The Point of Penultimate Wisdom1(PoPW)

The code knows

One can find wisdom after something went wrong by furiously2 instrumenting the code and deploying it into production, by swimming upstream in the logs to find the butterfly wingbeat that started the particular process, and by stepping through a half-dozen procedure calls to get to the point of failure to find the values and the exact point of failure, but the Point of Penultimate Wisdom already knows all the things. The choice is whether to have the PoPW communicate it in the original error message

Pre-loading debug information — as an investment — minimizes the operational work needed during the chaos, pressure, and confusion of a failure. While not all the work is guaranteed to return dividends, its presence (like insurance) allows some confidence that failures can be diagnosed quickly (as opposed to being a terrifying Complete Unknown)

One can catch every exception and explicitly log exactly what was happening (and re-raising the exception, one hopes). Modern systems automatically provide a lot of information about errors, even in production builds, without added debugging information. One must balance the code-clutter of reporting the details of a detectable error3 against the future value of finding a problem quicker

While the person debugging a failure might not be the person who last touched the code, it does not really matter

Eagleson’s Law: Any code of your own that you haven’t looked at for six or more months might as well have been written by someone else

Do your (future) self a favour


  1. The Point of Ultimate Wisdom is just after successfully debugging a failure and discovering a design flaw 

  2. and sometimes angrily, depending on the time of day and day of week 

  3. harkening back to the days of C (and of Go today) where one checked the return of every function for 0 = SUCCESS 

 
0
Kudos
 
0
Kudos

Now read this

The Futures of Python

Futures defer execution of code. They can allow code to wait for external resources like file reads, network calls, and database access, and then automatically continue without stopping every other operation. They allow the definition... Continue →