Thursday, May 31, 2007

Log4j code template in Eclipse

I just tried adding my own code template to Eclipse, and wanted to recommend it to Java programmers, if you can identify a pattern you use all over the place. For me, it was the way I use log4j. Just about every class ends up declaring a Logger field, which all look like this:

private Logger m_logger = Logger.getLogger(getClass());
Even with Eclipse's tab completion accelerating this, it started to get tedious. Now, I just type logger, press Ctrl-Space and enter to confirm the selected template is what I meant. I do then have to use Ctrl-1 to Quick Fix the error that I need to import the log4j package. That's the only potential improvement I've identified.

Actually, it gets better. Instead of using the method call getClass(), I've seen some people use the static class member class, as in MyCollection.class. There's presumably some infinitesimal speed difference, I don't know as I've never looked into it. Frankly, before I thought of these templates I used the getClass() approach because it was faster for me to type in Eclipse. Once I've typed Logger.getLogger(g, I hit Ctrl-Space for the auto completion list and hit return since getClass() is the top choice. Now with the custom templates, I can get the Classname.class form for free by using a template variable:
private Logger m_logger = getLogger(${enclosing_type}.class);
If everything stays in Eclipse, even the hard-coded class name is no problem because it gets renamed when the class or file gets renamed.

To get started writing your own template, open Window > Preferences... and select Java, Editor, Templates.

Some thoughts on code templates

Java is an OOS, Object Of Scorn, for many functional and dynamic scripting programmers, partly for its verbosity. Just as VC++ helped me deal with C++, Eclipse is helping me deal with Java by providing some decent accelerators like these templates. The fact that I can write my own is nice. It's my opinion that even in the most elegant languages I know of, it's not always possible to factor out every pattern in a large code base to an tiny pearl of beauty. I think you inevitably end up with a few code patterns of significant size that could benefit from editor templating.

Tuesday, May 15, 2007

Franchised web apps

It's time for another free-for-the-implementing business idea. This one: web site franchises.

Take the software that runs flickr or reddit or any of a thousand other things, and package it so it can be installed on a server farm elsewhere and customized. The example of reddit is perhaps most compelling to me as regards customization, because it's easy to see that the format of the software is so independent of its content, yet the social way reddit functions could be adapted to other groups of people. Right now it would be hard to grow a home improvement user base on reddit because of the slant of the existing user base. But somebody could buy a home improvement reddit franchise and start it up. This would be a way for the creators of a web application to get into markets they know little about.

I can think of two possible drawbacks for franchising a given web application. The first drawback is the financial aspect. If the application is having problems turning a profit with the existing international user base, fragmenting it would not be an option. There would have to be the potential for customizing the application in a way that adds value. The second potential drawback is the task of packaging the web application for replication. In most cases, this would be a non-trivial development cost. Designing 3D buttons and Javascript animations is fun and can be taken to show-and-tell, writing install scripts can be a tedious and under-appreciated chore.

Another angle to the web app franchise idea is some things may be salable to large corporations and government agencies for internal use without concerns about compromising confidential information over public networks.

As with most (all) of my ideas posted here, I expect this one is so good it was done long ago and I just now finally forgot enough of its origins that I think it's new. Please correct me. If I happen to be wrong, and you make some real money with this idea, I'd appreciate a link back to this blog, with due credit: "Thanks to JFKBits, whoever or whatever that is" would be fine.