Sniffing out code formation
Today (uhh… actually since yester-late-nite into wee hours on now), I’ve been working on a Black Berry Project at the office. My work is really diverse and priorities differ on projects, so I had started this project last year December and had to leave it at the initial release with the QA team to get onto something more ‘Billable’.
Well… finally the clients are getting ‘Giddy’ with expectation, so again I have to get back to it.
First a couple of Acid tests.
- Will I look at my code and go like… Ohhh…. Men… what the heck is this? (I passed this… everything just flowed, and I think 3 weeks is a long time span for this test)
- Will I start looking for ways to change my code because I was being plain what-i-don’t-know-to-call-it earlier? (I passed this test too… everything I did then, seemed right now, lets not think about 6 months from now yet…. I’ll still be maintaining it by then, so we’ll know)
- Will I view my own code in the light of QA requirements made by the QA team and go like… “Damn!!! How am I gonna fix this!” ? (Well again I passed this, as I instinctively knew where to look for stuff that was being requested and exactly where to add them. This was so cool that in just 1 day (actually less), I’ve fixed more than 50% of the QA requests and made another release to the QA team. Hehe… they won’t take me for granted next time :D )
- Will I… uhh… I can’t think of anymore acid tests J
Again, I learnt to appreciate a good sense of code smell. One of the bugs was an uncaught exception, which I didn’t handle in the first release. Well… I could have fixed that in less than 1 minute, but something told me… hey dude… why postpone that Exception Handling framework for this library? Just do it now… or you’ll be chasing yourself around by weekend probably.
So well… I went with my gut, developed the exception framework, which took me like 15 minutes to properly think out and integrate. In so doing, I also extended its reach to various parts of the code. Now, I can’t really quantify what this has done for me right now, but I think it has just saved me light years of work tmrw, so I can be royally lazy again and get to more interesting parts of code.
The last thing that made me really smile today, was a comment I had put above an Even Listener class. I had two components that where doing similar stuff that smelt a bit similar to me. In my first version, I didn’t want to fall culprit to premature optimization, so I just put a comment there that I suspected these two dudes could be replaced with one event listener if I gave it some more thought. Well… was I right… and today, without even so much thought… I just saw the answer before my eyes and implemented it… loosing like 25 or so lines of code into one small section with just 7 lines of code. Pretty cool huh?
I think leaving notes like this in your code is good. Infact in unix, the venerable Vi(m) will give the text TODO: special coloring, so you can easily spot it as you wade thru you code. This encourages you the coder to leave your self post-its in your own code.
Ahh…. I talk too much… I better go to bed, as I have to wake in the next 4 hrs time…
uhh…. Work can suck wen it comes to hours.