It's been a while since I was last a full time programmer, but it seems I've still something of the mindset. I've had a bit of code to write for work that's been a bit awkward for a few days, this evening at something of a loose end I had a look at it. I don't usually do much work out of hours, but there were deadlines, and I seemed to be in the right frame of mind.
Ah... it then turned into one of those times where you've solved the piece of the puzzle and everything just starts dropping into place. "Ah ha! I pulled that code into a separate function because I'd used nearly the same code twice, and that's just good practice. Now I see if I just add one more parameter to that function, and recode it a bit here
it becomes general enough that I can reuse it to do that job everywhere".
OK so "recode it a bit here
" meant turning a simple SQL statement into something that dynamically generates the SQL depending on the parameters, which is somewhat unpleasant, but still the best solution I could think of as it minimised code replication.
It's been a while since I last got the puzzle-solving programming buzz, I miss it. (Though not enough to want to go back to programming for a living, I'm too sloppy to be able to consistently write good code.)