First plan, then code
By llauren on Nov 17, 2006 in english, geek
Note so self: Regardless how small a project may seem, the way to make a one day job a two week mess is to do first and plan later. It’s been said many times before, but obviously it needs to be said again. First plan, then do.
I had this small project (actually more of “just a job”) on the job to create a way for our employees to enrol to our “Little Christmas” party. The way i attacked the problem was first to think of all kinds of wild, “practical” and “convenient” ways to get it done. Then i ignored it for a week. Then came the deadline and the “practical” and “convenient” ways turned out not to be. All sorts of “solutions” came and were recycled. Frustration ensued.
Last night, in some angst, i sat coding and re-coding what actually seemed to be a pretty good solution: a set of connected PHP forms on a web site of mine, backed with a mySQL database. Yes, i know it’s hugely overkill, but i couldn’t get SQLite to work anywhere (but my home box) so i moved to a bigger hammer. Still, the code was full of bugs. Logical bugs mainly, because things were hugely complex and Just Wouldn’t Work. At least not in a logical way.
So i decided to Plan First.
At bedtime, in bed, i scribbled in painstaking detail exactly what would happen with my form in all its states, removing all needless complexity, on my PDA. And voilá, it really wasn’t that hard! All the complexity was there just because i hadn’t properly thought of the problem before i started working on it. And the deeper i’d got into my messy code, the more complex and filled with special cases it got.
So this morning, i got up one hour before normal wake-up time, sat down in the coding sofa with my laptop, and made it work.
OK, granted, there were still some minor bugs left when i arrived at work and had to demo the thing, but even they were easy to understand and stomp out.
Moral: When you understand the problem, then creating a solution isn’t really that hard to do. I hope i can remember that next time i attempt to “just do a small job”.
Post a Comment