The Power of Copy and Paste
A reasonably large sized “Enterprise” Java web application ends up being multi-tiered , multi-layered, multi-moduled in that order, with at least a few million dependencies. The task of putting together such an application from scratch is truly daunting.
So how do you go about creating an application from scratch? I have a few favorite techniques that I have faithfully followed over the years:
- Copy an existing working application;start trimming it until I get to the point where I have an “archetype” that I can start back from.
- Start from one of the archetypes provided by maven. Most of the standard maven archetypes (obtained using mvn archetype:generate) are very lightweight, but could be a reasonable starting point.
- Another variation of the above 2 points is to generate your own archetypes – strip down an existing application and create a maven archetype for yourself.
- Use Appfuse as a starter application. Appfuse though is starting to get a little bit dated now, with no updates for the last year
- Use the sample applications provided by the Spring folks as a starting point – say the spring mvc-show case application
All of these approaches follow the common theme of “Copy and Paste” to create an application.
Now, copy and paste helps you kick-start an application, once you have started an application how do you keep adding functionality, after all most of the code structure would look similar – In Java you would add a new entity, a corresponding DAO to manage the persistence of the entity, a service tier, a controller, a view and so on.
The Rails folks did a wonderful job understanding that providing a simple way to kick-start, add functionality and pull in dependencies, is the quickest way to developer nirvana. Well, people who work with Rails are lucky, we Java guys don’t have that option, until now that is (Yes there is Grails, Lift, but these have not been an option in the enterprise shops that I have worked in).
Roo is turning out to be a wonderful alternative. With a few commands , you have a fairly green looking application up and running with all dependencies nicely pulled in. Adding functionality is equally easy; the roundtrip experience from creating an entity, to viewing the entity in a web page almost has the feel of a Rails based development. Well, Roo is still maturing, so it is not an option where I work yet, however that still leaves the “Copy and Paste" as a viable alternative for now!!. A simple way that I follow to add functionality to an application that I am working on is to simply start the Roo console, create the entities in roo, run the push in refactor and then creatively “copy and paste”.
"Copy and Paste" the most under-rated way of expanding code.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)