Thursday, July 17, 2008

Code Generation

Code generator, -noun : a tool used by management to regulate (read: reduce pay) or replace the software engineering intelligentsia with code monkies.

Seriously, that was what came to my mind when I first heard the term. In fact, I was right. It turns out the director of the company I was working for at that time, whom introduced the term to me, defined it exactly that way.

Fast forward a few years, I joined a Canadian/German outfit that just off-shored part of their dev team. It was a J2EE and Swing laden sweatshop in the tropics. At least it looked that way during the inquisition, or interview in some nomenclature, with all the J2EE and Swing interrogation. I was in for a big surprise. The first day at work, I was tasked to implement a simple search screen with a link to a dev guide and coding conventions. I was excited, getting down and dirty so quick and early has never happened to me before. I reminded myself to buy the lotto that day. Sadly, that thought didn’t last, as quickly as it faded, it was replaced by apprehension after I read the guide. I quickly did as the dev guide suggested, created my business interface, annotated it, created the implementation and filled out the business logic, run the ant task to build and deploy. Lo and behold, my EJB 2.1 SSB and the official confirmation of my officiation of the office of the code monkey.

Surprisingly though, I stayed and enjoyed working there longer than I first suspected, which was 1 day. The framework, allowed me to write business code without hassling with all the ejb 2 overhead, such as home and remote interface, xml configuration, etc. Plain old java beans became persistable entities (no, not ejb entity beans) as easily. All this was before Java 5, before EJB3. I was even developing swing interfaces without dealing with Swing code most of the time, it was a framework not unlike JSF, years before JSF. I only had to deal with Swing code when there were requirements to build some very non-standard UI behaviours, which is a testament as to why BAs/End users should never be given control over defining User Interfaces.

Interestingly, after my time there, code generation has been a very useful tool to me to solve problems as well as to improve development efficiency. We were using xdoclet back then to do compile time code geneartion, but with advent of annotaions and the mirror API in Java 5 and its standardization into the JDK in 6 and a number of byte code/runtime manipulation libraries nowadays, the potential for compile and runtime code generation is almost limitless.

During the JAOO knowledge sharing session a few weeks back, discussions about TDD came up. Someone remarked about how un-enforceable it is and its up to the developers discipline. That immediately reminded me of some POC annotations I wrote a while back when the mirror API was first made available in jdk 5, along with the processors, that generated skeleton unit tests. If I annotated my business interface or class, at compile time it would generate Test classes and test method for all the public methods in the business interface and class. Of course the test methods were generated to throw an exception with a “TODO” string in it, I still had to write the test code. If we wanted to enforce this, all we have to do is add a checkstyle like mechanism into the source check-in hooks to inspect the business classes/interfaces for that annotation. Obviously, this doesn’t guarantee that the test code is implemented or even correct/useful, but it is one step closer to TDD.

Basic UI requirements

Whenever a new framework is being discussed, or “pimped” as a colleague of mine describes it, all sorts of nergasmic hand waving takes place and a lot of geek saliva are wasted on how easy it is to do things compared to the older frameworks. Unfortunately, almost always, the basic requirements or standards of the actual users of the systems implemented by such frameworks are often lost in the geek moan-fest.

What I’d like to list down here, mostly for my reference, is some very basic requirements of features that are often very useful for end users of web applications, some of it can be adopted for non web based UI as well.

  1. Idempotence : Users should be able to accidentally click on a button twice in succession or click on refresh after a button click without it causing a rise in global warming. Related to this, is also clicking on the back and forward button and actually going back and forward instead of getting gestapo signs popping up
  2. Linkable or book-markable screens : Users should be able to bookmark screen so that they can return to it easily at a later date. This is especially useful if the screen requires half a day to get to.
  3. Consistent theme : This is a bit subtle. One of Ben Shneiderman’s golden rules of interface design is Consistency. If users are using a single application that are made up of a number of systems which they have absolutely no idea of, they should not see a duck-crap green with menus on the side on one page and hello kitty pink with menus on the top the moment they navigate to another screen.

There it is, not a big list, but something to begin with. How these are used as criteria to determine the next shiny geek toy are as follows:

  1. Can the new toy support those features out of the box, if not what add-ons/plug-ins or customization needs to be done
  2. Once we know the new toy support those features, how easy is it to be used by the *coughcoughcodemonkiescoughcough* developers. Is it a one-liner or is it xml-hell, etc?
  3. Now compare that to the old framework
Again not much, but something to start with.

Opening Day!

Wow never though I'd ever get my own blog going. But here it is. First post!