Writing code that’s easy to debug begins with realising you won’t remember anything about the code later.
Most of the programming I do — if you were to watch — looks very much like me sitting and staring suspiciously at my computer. Occasionally I sip a beverage. Occasionally I will rub my chin. Sometimes I will grudgingly type some code, knowing full-well I’m building something I’m going to curse about later.