Saturday, September 27, 2008

I am lazy!

It is annoying to feel compelled to start every post with "Wow... It has been a long time since I've posted something here". Of course one answer is "So don't". I'd rather think that some people would prefer to say "So post more". I am known for having an occasional delusional moment here and there, though ;-)

I believe one of the reasons that I don't update this blog as often as I wanted to, besides being insanely busy, is that, bottom line, I am a lazy person. Fortunately, a characteristic that would put me out of any work back 50 years ago, is actually something that should be rewarded on the software development world. Let me illustrate this with an example.

When I am heads down, working 15+ hours per day to develop an entire product or a complicated feature, I get extremely paranoid (way more than normal) about introducing regressions by entering a, or better, any new line of code. And testing everything all the time is too tiring (I started by saying that I am lazy, remember? ;-). So I usually choose to automate as many tests I can. Sure I have to invest some time putting together an automation strategy (usually based on JUnit). But after that, I just need to click a button and watch the JUnit progress bar go while I exercise the divine right of not doing anything for a few minutes - OK, I am lying: usually I am working on another portion of the code while the tests are running.

On my last endeavor, for example, testing the code consisted on executing 11 Java examples that invoke an API written to identify security issues on web applications by looking at their code and by interacting with them as a hacker would do. Each one of these Java applications run for about 2 to 10 minutes and produces a long log that has to be verified. After doing this by hand 3 times, my laziness kicked in and forced me to find an easier way to test my code. After one or two hours of JUnit fun, I had a class that, for a test method like the one below, executes the XYZ.class on a separate VM, collects the generated log, and compares it with a baseline I know is correct.

public void codeCoverageExample() throws Exception {

The comparison part was a bit tricky to implement because the logs have things like timestamps and temporary file paths that change from execution to execution. With some creativity and several regular expressions, I managed to circumvent all the issues and, like a famous black-turtle-neck-guy says, "BOOM" : the annoying tests were out of my way ;-)

I will write at least one more post pointing out cases in which being lazy was extremely valuable. I am already thinking about EMF related examples...

Actually, on a minor digression, is my passion for EMF the ultimate proof that I am lazy? After all, it does generate a bunch of the code that I would need to code by hand ;-)