There’s currently a whole load of things I want to read/play with/ do, and I really don’t have time for it all, even though I do have the interest and energy(most of the time). I guess it’s one of life’s quirks that when one is busy, there’s lots of things one wants to do, and when you’re idle/bored, you can’t be bothered to do anything. Case in point: I was unemployed for several months this summer, and apart from auditing a summer class and a little traveling, I didn’t get all that much done. Some of that I can chalk up to the grind and angst of being unemployed and scanning the job listings on craigslist and monster etc and sending out resumes, but I really had a lot of time on my hands that was just squandered. Mostly I realize that now when I’m juggling grad school and a full time job along with all the other things in life – I wish I’d used that time better. Now that I’m already busy I have all this interest in playing with this technology or reading that book, various things I couldn’t be bothered to do in the summer time when I was idle. Is it really just easier to manage one’s time when you’re busy? Once you’re in a go-go state it’s just hard to stop (inertia?)
I’m struck by how much the ubiquitousness of laptops has changed the college experience from the aspect of getting work done. – when I was in school ending in 2000 (up hill both ways…) laptops were still pretty rare. People got work that required a computer done in their rooms or computer labs – and as a Computer Science and Engineering major, for me that meant a whole lot of time in my room. Now that I’m back in school part time four years after getting my BS, I’m struck by the fact that I’ve spent more time in the library in the course of a semester than I did in my entire undergraduate education. Why is that? Well apart from the fact that I have better study habits than back then, its simply because I can – I’m no longer chained to a desktop computer. This is all pretty obvious, but now people can get their work done anywhere, and do. Walking through the Tufts library, half the people are tapping away on laptops, and most everyone is jacked into an iPod. I can only imagine how different my college career would be like now – and we’re only talking technology enablement, not “if only I knew then what I know now”.
I figure everyone and their dog has a blog,
so I should too. What better way to share my random musings and fun/wasting time with technology to so many and so few at the same time?
In several easy steps! (hopefully in some manner this will prove helpful to users of jython and freemarker in the future)
- The beginning
- Use a template engine to simplify site maintenance
- Create a semi-automatic scoring system
- Choose a different templating engine
- Take stock of what you’ve done
In the beginning, agree to be the “webmaster” of one’s local kickball division – simple an non-timeconsuming task given that the site has a handful of pages with static content, and one must update the standings and scores every week. Decide the site is an excellent opportunity to learn CSS layout. Spend an order of magnitude of time more to get the site up than it would have taken to throw up some 1997-style table layout.
Now the site is up and running – decide that since the same header and footer are on every page, it would make sense to use some kind of templating system (note: the site is static content only) to make it easier to add new sections, should the need arise. Consider various client driven solutions: Dreamweaver (too expensive), Nvu (generates crappy HTML, crashes, slow). Consider rolling your own, since all you need are static includes. Discard that idea.
Look at open source templating engines. Decide that you really want to have an ant script that will magically assemble the site (and who knows, maybe one day even upload it for you too!). Decide to use Velocity. Play with Texen for a while, but decide you really need its big sister vpp. Learn the syntax, get the gazillion jar dependencies downloaded and copy and paste the web pages into easy to manage chunks and get the includes working. Wa-lah! Now the website can be regenerated by a simple ant task – take this opportunity to add a photos section because its suddently really easy to do.
Now you’re in the promised land – no more editing 6 different files to change the menus! You can sit back, crack open a beer, life is good. But no – it irks you that you’re managing the score via a way-too-manual process involving an elaborate Excel spreadsheet and typing at least 2 different places. You’re a software engineer, you can do better than this. (Note: this decision is best made when you have a new full-time job and your Theory of Computation grad-class is taxing your time).
Spend T-rides brainstorming how best to represent the structure of the league, with teams, game schedule, results- of course you’d want it to be validating. Discard that effort when you have a brainwave – just represent the state of the league in jython script – you were going to process the XML in jython anyways after sleeping off the delusional fantasy of using XSLT. Cut out the middleman, mere mortals don’t need to edit this stuff!
Cut to creating a set of objects for your domain objects. You need your teams:
self.name = teamName;
self.shirtColor = shirtColor;
self.abbrevName = teamAbbrev;
Get the whole messy code here (note it doesn’t handle forfeits yet).
Throw in some other classes and some logic, now you’ve got a half-assed scoring system! Data entry is totally a breeze, I mean look at this, total user friendliness:
day2 = Day("9/8/2005",ppe,ppe)
game = Game("8:00","A",baggers,ppe,freeballers)
game = Game("8:00","B",spanking,ballsdeep,gentree)
Get the season so far here.
Great! Now we just wire that up to our template engine, and then its margerita time!
Not so fast! Now you discover that, at best, the Velocity support for Jython is experimental, and for some reason your download seems to think its 1.31 instead of the 1.4 you’re sure you downloaded, which doesn’t support Jython at all! (Discover this after spending hours the night before debugging, thinking you were doing something wrong) Now you consider moving to straight up Python and using the Cheetah template engine, but you become aware of FreeMarker through the flame-war inspiring intervention of one of its’ developers in the velocity-users mailing list. Syntax is similar enough, and it supports Jython! So you finish building out the scoring system and create some sweet templates for your standings page:
< #assign num=1>
< #list standings as s>
<tr <#if ((num %2) = 0)>class="shadedrow" >
< #assign num= num+1>
Get the rest of the standings template and the schedule template.
Wrap it all together with a small driver to load the templates, crank up the freemarker engine, and write out the output as I did here. (Note apparently the JythonWrapper is not really needed – i was chasing a bug with java dates that has since been fixed)
Now we’re almost done – one of these days need to convert the templates of the static pages to freemarker (or freemarkerpp) and then we’ll really be done – for now we’re done enough. Now keeping the scores and standings updated is breathakingly easy! It only took an order of magnitude more time to get this all written and working than it would have taken to actually do the manual edits over time. Oh well, that’s just the way we engineers roll I guess.
Thanks to the velocity-users group for their help trying to get Jython to work for me, as well as Jonathon of the FreeMarker project for introducing me to his project and providing a push in the right direction getting my system working, as well as responding quickly to a problem formatting java.util.Date objects embedded in jython objects.