Archive for August, 2004

Calculating God by Robert Sawyer

Sunday, August 29th, 2004

As many of us programmers are, I’m a sci-fi fan. I think I started programming before I started reading sci-fi, but it’s a very tricky call. Do books about Tobias the cat, witches and magic count? Just when did my early forays into BBC Basic become programming and not just copying from the book.

As I’ve gotten older, my voracious appetite for sci-fi has diminished a touch, assisted by my having read many of the greats. So I was overjoyed to spend Saturday afternoon reading Robert Sawyer’s Calculating God cover to cover in a few hours. For a long time my top 50 favourite books has been relatively unchallenged, but this book leaps in there, possibly into the top 30.

Sawyer has a successful series about Neanderthals in a parallel universe, but it’s relatively tame. Calculating God is far more visionary and reminds me of reading Stephen Baxter’s work a couple of years ago. (In fact, Baxter has a relatively tame series too, about mammoths that is perfect for kids).

Reading the best of both authors reminds me of when I first discovered Asimov. I highly recommend.

Continuing to use MoveableType?

Saturday, August 28th, 2004

I’m planning to move us to Roller at some point soon. Still dealing with hardware problems at the moment (DNS server died last night). However, I’ve realised that my wife and I can continue to use MT if we want to.

MT free edition can only be used by 1 author and that 1 author can have 3 blogs. We want 2 x 1 author/1 blog. So we just need 2 MT free editions. Very simple and obeys the licensing. So is feasible that we could stay with MT.

No Vegas :(

Friday, August 27th, 2004

In answer to Matt Raible’s going to Vegas post:

==================================
Due to constraints of time and other issues, the
following sessions have NOT been scheduled:

(1052) ‘Jakarta Commons (part 1: J2SE-centric)’
(1053) ‘Jakarta Commons (part 2: J2EE-centric)’
==================================

Ah well, a shame. I was hoping to get to meet people etc, but can’t really find the 1000 usd for the trip. I guess my son will get a father for the 4th week of his life instead :)

% trick

Monday, August 23rd, 2004

A while back, we got addicted to IBM’s CodeRuler at work. It involves having a large group of objects managed by the system, and you get given a 500 millisecond gap in which to give them all orders for the next round.

A major problem is that you can’t change those objects (peasants and knights) codewise. So there’s no way to extend them, add better behaviour, or gain any access to the system’s containment for them (to split them up into subgroups for example, or even to know when new ones are created).

My solution to this was a neat trick I think. Probably well known by many, but also probably new to others. I created command-style objects that knew what each groups particular mission was. I then used the following snippet, while looping over my population of peasants to assign them to a mission each time:

peasant.hashCode() % peasantMissions.length

I did the same for my knights. It’s a nice little trick (in my opinion) that means that even though I don’t have control over the objects, I’m able to split them off into groups, and keep them in the same groups, without any extra container systems.
My previous version had Mission objects which contained the peasants, and it wasted time at the start finding the newborn peasants and adding them to the missions etc.

It came up tonight as a solution to a threading problem. We have a threadpool. It acts as the server-process for a client (much as a forked process with Apache does I think), however it is completely first-come-first-serve in which client it chooses to send a message to (this is a push system). As we’ve hooked it to a system that sends messages a lot more than before, we’re finding that the 10 threads are overtaking each other and clients are receiving the data for a single construct out of order.

So one possible solution that immediately raises itself for me is that I could apply the % trick. Effectively it gives you a repeatable load-balancer (low-tech as it is), and each client would appear to switch to a single-threaded system, even though the server was still being aggressively multi-threaded.

As I said, this is probably well known in the right circles, but I liked how a simple game environment that was largely seen as a harmless bit of fun has helped me out.

Joda Time

Monday, August 16th, 2004

Monday nights are research-something-new nights, and todays entry is Joda Time. Does it kick J2SE dates arse, is it wonderful, or is it yet another date fuckup.

Joda Time (0.95) comes in a 450k jar file. Chunky ’tis true, but I’m sure we’re all so tired of java.util.Calendar that we’ll happily swalllow this lump.

The Olympics plus a need to go read Tolkien and exercise mean I’m surprisingly out of time already on my research-something-new-night, but I managed to see pass a few facets of J-T.

First off, we can print out the current moment:

        // Now        System.out.println( “Now: ” + new DateTime() );        System.out.println( “Today: ” + new DateOnly() );        System.out.println( “Time: ” + new TimeOnly() );

I assume clashes with util.Date, sql.Date and sql.Time lead them to use the slightly ungainly Only class names. This is probably worthwhile as we would think a new Date() was both a date and a time. Here’s the output:

Now: 2004-08-16T21:43:18.289-04:00Today: 2004-08-16Time: 21:43:18.594

Next up, making a historic date:

        // Printing a date        DateOnly bday = new DateOnly(1975, 11, 13);        System.out.println( “BDay: ” + bday );

Output:

BDay: 1975-11-13

One of the best new things we get with Joda-Time is a Duration/Interval structure. This is sorely missed in the J2SE Date system, and is worth it alone.

        // Working out my age        DateOnly now = new DateOnly();        DateOnly bday = new DateOnly(1975, 11, 13);        Interval age = new Interval(bday, now);        System.out.println( “Age: ” + DurationFormat.getInstance()            .getDefault().print(age.getDuration()) );

Output:

Age: 28 years, 9 months and 14 days

Leap years are often a big deal. Let’s roll over from Feb 28th to Feb 29th:

        // Roll into a leap year        DateOnly feb28 = new DateOnly(2000, 02, 28);        MutableDateTime feb29 = feb28.toMutableDateTime();        feb29.addDays(1);        System.out.println( “Leap: ” + feb29 );

Output:

Leap: 2000-02-29T00:00:00.000-05:00

And is a date in a leap year?

        // Is it a leap year?        DateOnly feb28 = new DateOnly(2000, 05, 05);        System.out.println( “Leap? ” + feb28.year().isLeap() );

Which outputs true. I like this code, I can ask a date, time, or datetime for its year(), hourOfDay(), weekOfYear() and many others. These return DateTimeFieldProperty objects and let you ask questions about the year etc.

Last up, formatting a DateTime. I’ve left off parsing as I’m trusting that it’s a nice inverse of this:

        DateTime now = new DateTime();                                          DateTimeFormatter fmt = DateTimeFormat.getInstance()            .forPattern(”h:mm a ‘on the’ dd’th’ ‘of’ MMMM, yyyy”);        System.out.println( “Now: ” + fmt.print(now) );

which prints out:

Now: 9:43 PM on the 16th of August, 2004

Note, the ‘th’ is hardcoded. So a bit of a cheat by me. Would love to see that in the library :)

These Formatter classes are modelled after the JDK ones with a few extra bits, (though the javadoc doesn’t say which bits are extra), and have Parser equivalents, however they don’t extend java.text.Format. One thing I’d like to see here is a bridge to the java.text.Format stuff.

So let’s review.

Durations. Yum. With formatting.
Date and Time only classes.
NO CALENDAR! You can treat a date like a date, not like a moment in time.

In case that last statement has you thinking it’s Java 1.0 all over again, there’s an Instant class which is equivalent to the undeprecated parts of java.util.Date, and can be used for the optimised part of the systems I presume.

There’s one thing I still want to check, but will do that at work with JProfiler. What’s the memory usage and what’s the speed to create these things. I notice that Instant still has a Chronology class, which is the J-T equivalent of a Calendar it seems. Does this make it a lot worse than java.util.Date?

Will hopefully find time at work to have a look at that and see what it’s like.
Unless it’s terrible, I’m going to be pushing it as a standard library at work.

=============================

- Joda-Time is BSD-compatible licenced. It’s 0.4 version was released back at the start of 2002, so it’s at least 2 and a half years mature.

It’s primary author, Stephen Colebourne, is a Jakarta Commons committer. I therefore may be exhibiting biast.

Ashkelon for OSJava

Monday, August 16th, 2004

Following on from seeing jdocs.org turning up, I decided to set up Ashkelon for OSJava.

http://wiki.osjava.org:8080/ashkelon/apis.do

It’s running on a postgres database, and I had only 2 real problems. The first was a Tomcat ant task in the build file that was not found on my system. The author (Eitan Suez) quickly helped, and I commented out the relevant chunk.

The second is that Ashkelon ships with the JSTL 1.1 jars, though it only uses JSTL 1.0 taglibs. I run on a Tomcat 4 server, so a quick rollback of the jars was all that was needed here.

Once you set your database up, there’s an init.sql script to get you started and then you write an xml file per API and load it in. The output for loading in is a bit too verbose to be of use to the normal user, so although I saw a lot of warnings, and even a few errors, I’ve no clue if they were bad or not.

It decided to hang on one project (scraping-engine), so I probably need to talk to Eitan about that too. In fact, checking it out, scraping-engine failed to load, but when I loaded xmlwriter, it decided to call it scraping-engine instead of xmlwriter. Odd.

Now that I’m listing issues. Another problem it has is not liking codebases that share package namespaces. Because I’ve been splitting up a larger codebase, I have a few projects that have code in com.generationjava.io. Ashkelon doesn’t (possibly by design) separate these, so when you look at Genjava-CSV, you can’t see the classes that are in that project.

It’s definitely a lot smoother than my Multidoc hack, but I’m not convinced yet that it offers enough to be worth a database and a Java server. jdocs.org’s comment feature will be a happy addition if that turns up, and it would be nice if it could use a Maven POM directly to save on configuration time.

NFJS: Third day

Wednesday, August 11th, 2004

Lastly, a descrption of the third day at the No Fluff conference.

I began the day with a talk on Tapestry by Erik Hatcher. I actually began the day with WaffleHouse, we found it this time. Not too impressed with it, bit of a dive.

Anyway, Tapestry. We’ve dabbled with this at work (Tapestry-2 and not the latest, which is 3). It’s gotten a bad name at work, mainly because we were not very good at it. Erik’s team hired Howard for 2 days to come teach them, and that would have been a good thing for us.

I used mind-maps for the first time with the Tapestry talk. Very amateurly I’m sure, but I got a lot of information down. One interesting part was OGNL, it looks quite cool. A better BeanUtils.

All in all, I like the look of Tapestry. It’s a mindset change, but changing keeps you agile. I’m not sure I want to push it at work, simpler to just change our one Tapestry thing to Struts (or even just plain-jane JSP which is my preference) and someday goto the GUI-generated JSF.

Erik had a lot more slides than time, so bit of a rush towards the end.

Next up, expert-panel time. One main quote I liked was Stuary Halloway’s term of ‘Console Naked Objects’. sed, awk, bash, grep etc etc. There were various IDE questions, and I always like to answer that with, “my IDE is vim, grep, sed, awk, perl, bash, tail, wc, …”.

Lunch was partaken at this point. Good time to mention two complaints about the hotel; the temperature was far too low (everyone complained) and the food was so-so (I’m picky, but the non-picky eating machines I went with were also unimpressed). A third one is that the wireless signal did not reach my room, but ended at the door. Helped me get sleep though I guess.

After lunch… GIS talk with Scott Davis. Scott was mainly organising things, but took time out to talk ot some of us about the wonderful world of GIS. Nice for me as I’ve got some vague plans for an educational product here and despite exposure to GIS in the past, had some questions. In fact, since getting back I’ve played with JUMP (buggy, but works) to get my first data-set together. Scott’s took a bit too long to cover the basics (GPS, phones etc) and lacked time to get deeper into other areas.

Finally, I went to the second showing of Stuart Halloway’s Metaprogramming talk. Like State Machines, this one was interesting because there was no religion. It wasn’t telling us about tapestry, or groovy, or aspects etc. It was telling us about the JDK. Couple of code snippets here that might work their way into Commons Lang, and Stu also used aspects to highlight his point, without it being a talk to sell aspects to us. Very nice to see them in a supportive role, ie) how we’ll mainly use them.

That’s it. Mike and Eric both seemed to like the conference a lot; much in the way I liked it last year. This year it’s a bit less of a discovery, but still lots of good learning.

NFJS: Mind-map of notes

Tuesday, August 10th, 2004

Someone, whose name I’m not too sure of (Mike? Jim?) was doing a lot of notes using mind-maps. I tried using it for the Tapestry talk and got a lot of information down.

Looking for software, FreeMind (freemind.sf.net) seems a pretty good one. Basic, but easy to use. So I’ve output my legal-pad full of notes into a nice summary map. This is then exported as a rather dull html page: Conference notes

NFJS: Lunchtime giveaway

Sunday, August 8th, 2004

Forgot to mention the lunchtime giveaway that NFJS do on the Saturday and Sunday. Eric, having just bought the last t-shirt or something, remarked that he’d probably win.

Lo and behold, his was the first name out of the hat (4 drawn on each day). He chose Mike Clark’s Project Automation book (yep Dave, no t-shirt for you).

To drive things home, mine was the last name out of the hat on the Saturday and I walked away with David Geary’s JSF book. I’ve just finished months of technical-reviewing for Kito Mann/Manning’s JSF book, so I’m a bit up to my eyeballs with it all; but I always like David’s books and am sure I’ll be turning to it at some point. His AWT/Swing books are my Java GUI bibles.

So our company managed to grab 2 wins out of 4. On Sunday, Mike, didn’t get pulled out of the hat, so no pressies for him.

All in all, it looked like there were maybe a hundred people there. I think there was room for about 130 people maximum.

(Removing expert panel transcripts)

Sunday, August 8th, 2004

I’m not sure blogging the comments of an expert panel is really ethical; mainly because I’m not confident that I won’t misrepresent their opinion. So I’ve pulled those blogs.