Phillip Pearson - web + electronics notes

tech notes and web hackery from a new zealander who was vaguely useful on the web back in 2002 (see: python community server, the blogging ecosystem, the new zealand coffee review, the internet topic exchange).

2003-2-22

Need my own notebook PC

I wonder when the new Lindows Mobile PC will be available in New Zealand. It sounds ideal for me -- not too expensive, and small, so I can carry it around everywhere. It doesn't sound incredibly fast, but that's only an issue if I try to fully compile big C++ projects, which I don't do a lot of in my spare time (only at work).

Java impressions

Today I'm coding in Java - writing my first Java web app. For various reasons, I can't get online or at any of the computers that contain any of my other active projects (the Topic Exchange, a comment server and the PyCS search extension), but I do have a copy of "Oracle 8i Java Component Programming with EJB, CORBA, and JSP" and an old Pentium notebook with a text editor. Not a Java compiler, but I know C# syntax well enough that I can hopefully bang out a whole heap of almost-Java and fix it later on.

My impression so far is that it's not as annoying as I'd expected. It's certainly quite verbose compared to Python, but the JDBC stuff isn't too bad: I can handle using PreparedStatement and ResultSet objects for everything.

I'm coding in almost the same style as I use in Python. It doesn't translate well into C++, where all the redundancy in declarations and definitions makes creating new objects and methods into quite a chore, but it seems OK here.

One disadvantage to not being able to get online is that I can't get at any of the Apache and OpenSymphony projects that everyone seems to rave about. Or maybe that's an advantage - I'm actually getting some code written, instead of spending all day reading about things.

Part of the app is a very simple template compiler. It takes files that look like this:

		<item>
			<title>{{title}}</title>
			<link>{{link}}</link>
			<description>{{description}}</description>
			<guid>{{link}}</guid>
		</item>

and turns them into code like this:

package nz.co.myelin.foobar.templates;

class rss_item
{
	public String title;
	public String link;
	public String description;
	public String link;

	rss_item()
	{
	}
	
	public String render()
	{
		return "		<item>\n"
			+ "			<title>"
			+ this.title
			+ "</title>\n"
			+ "			<link>"
			+ this.link
			+ "</link>\n"
			+ "   <description>"
			+ this.description
			+ "</description>\n"
			+ "   <guid>"
			+ this.link
			+ "</guid>\n"
			+ "  </item>\n"
			+ "\n";
	}
}

This is a more complicated version of what I do when I want to display something from a Python script, and is very similar to the HTML::Template module in Perl. Not as powerful as things like Cheetah, but also harder to screw up, and it also lets you let other people write their own templates without worrying about security or that they might mess up the code, because there's no code in the template.

Another thing - caching. Apparently the accepted way to cache web pages in the Java world is to use a library called OSCache. However, it sounds like it occasionally goes mad and totally pummels your server. I don't really understand this -- how difficult does caching web pages need to be? You just put a little hook in the bit of your code which writes the page out to the server, and get it to save a copy in the cache. From then on, if you need to serve that page, you grab it back out with a quick SELECT from the database and serve it. If you want to be clever, you can store a Last-Modified date and an E-Tag in the cache as well, and then other people might cache you too. All this is trivial stuff, and it won't get you kicked off your server for bad behaviour because it's too simple to break.

... more like this: []

distutils even better than expected

Nice - one distutils script may be enough to build the Pythonised version of ht://Dig's htsearch module. I was all set to code all the stuff to detect where the Python include and lib directories were (for automake etc), but a closer read of the distutils manual showed that all I need to do is put the other ht://Dig include paths and library filenames in the include_dirs and libraries bits in my setup script and distutils will handle everything for me.