Friday 22 October 2010

I love to...

I've learnt some really painful lessons these last few weeks. I grew up programming in turbo C and debugging was just one of those things I picked up naturally and ran with. Then I made then switch to java with it's fancy IDEs and convoluted 'frameworks' and I gave up on debugging. I still occasionally used the IDEs debugger but most of the time I just put print statements all over the place, sat back and watch the code spew out lines of messages as it self destructed. About 3 years ago, I picked up unit testing as a by product of an encryption project I worked on in software engineering class. Unit testing was easy and cool when it's a new project I'm working on and not some 10 year old architectural master piece... or so I thought.

So a little over a 6 weeks long ago my boss says dude I've got the coolest project for you. Fix up this synchronous module so it's asynchronous using JMS and using the approach taken by 'other existing asynchronous modules'. If you don't know it yet that, there, is the perfect recipe for a project from hell.

Anyhow, I spend the first one week or so reading the existing code. The next one week creating class diagrams and sequence diagrams Those 2 there (class and sequence diagrams before actually writing one line of code) make up a perfect reason to be thankful that I was too busy growing up in the 80s not dable into coding (not that there were computers or the internet available where I grew up anyway). Remember I've got about 4 weeks - and I've spent the first 2 or 3 doing nothing... well almost nothing. So, I finally start tweaking the interface. Let me just say right now that working with old code makes you appreciate senior programmers more - how they kept their sanity while managing to construe such insanity is purely beyond me. But I digress. So I finished tweaking the interface, what with sessions and requests, data objects put into memory in java code and accessed from the JSP (cue utter and complete mayhem), in about a week and was now left with the code itself.

JMS is a cool technology. It would have been cooler though were it not tied to the JEE framework somewhat (you know, kinda like the way scala actors are written in a self contained scala library). So now I had to practically create a temporary cache in memory that manage insertion and retrieval with some complex voodoo logic because the manager is a singleton amongst other reasons. I've also got to accomodate the existing code (you remember that part earlier where I said something about making sure my code changes followed the existing pattern).

After fooling myself into believing I knew what I was doing for all of one week I finally was humble enough to learn. I realized in hindsight that writing unit tests for the existing code was the smartest way to not only learn but to also make sure down the road that my changes were good enough. The nature of writing unit tests is that you end up breaking up the code into small compartments (apparently that's one of the reasons it's called unit testing - duh). Smaller compartments mean you understand the code better. I also learnt that debugging isn't a dead act after all- it's good programmers that are reducing in number. Old code will always exist... cos some smart dude will come up with a better why to write it (writing intelligent software that can create software faster would fall under this category) and there'll always be the need to maintain it (except of course you also write sofware to maintain the code in which case you'd have to maintain the software that maintains the software that maintains...). Reminds me of that one time we had to write a compiler in college. I had classmates who complained because it was a waste of time which is wierd cos I enjoyed the entire course (I didn't read for the exam and I didn't get an A because I was too busy trying to get my compiler to compile).

These last few weeks we've been talking about humility in church. Last week I told a church member, in jest, that I'm sure God was opposing me because of my pride. I guess there's some truth to that especially since he gives grace (I like to read this as style) to the humble. Humility is accepting your failures/foibles and then submitting what (who) you do not fully understand because you realize and accept that you are flawed. I finished my project 2 weeks behind schedule. I now have to struggle to meet up other goals but it's been worth it in the end. I love programming.

No comments: