The realization that helped me the most in programming was to keep code simple within each level of abstraction.
In practice, that means making bits of code that do one thing only. IDCT bit does IDCT, huffman decoder does huffman decoding. JPG parser use both to do JPG parsing, image library use the latter to decode the data into image, file handlers turn files into the data, and so on. Image library don't need to know about files below it, and IDCT code don't need to know about JPEG encoding above it. This tends to cost efficiency, but it results in code which is flexible, testable, re-thinkable and return-to-able.