Monday, December 31, 2007

Today's Java Irritant: Design-by-Contract Disconnects.

Design-by-contract systems enforce API behavior. In Eiffel, contracts specify both internal and external behavior, at the language level.
connect_to_server (server: SOCKET)
server /= Void and then server.address /= Void
-- etc.

This does what it looks like, at runtime. (/= == != :)

The cost of doing the same in Java is higher; most frameworks use some form of aspect-oriented programming. This isn't a bad thing in itself, but gives some people (managerial types and unimaginative programmers) the heebie-jeebies. Dealing with issues created by lots of aspects can be daunting, but are relatively straight-forward in a well-educated Java house.

Lighter-weight solutions exist, may be preferable in many situations, and are easy to grok. Putting a chunk of precondition tests at the start of a method is trivial:
public String foo(final String bar_) {
// etc...
Here, the issue is that there's no automagic way to track or document preconditions other than either manually documenting them in Javadocs (preferably through a simple doclet tag, like @pre, or whatever) , or by programmatically scanning the source and pulling out "useful" information and doing something useful with it. Neither are particularly appealing: Javadocs go stale quickly, and writing a robust source parser is non-trivial.

Another answer is to use one of the annotation- and/or aspect-based solutions (or XDoclets, but... ew?) and swallow the bitter pill that is Java, and pay the cost of educating your developers. The packages I'm currently considering are Contract4J, which uses pre-built AspectJ aspects, and SpringContracts (which is nice since most my projects use Spring).

Wednesday, December 19, 2007

OLPC: Minimal First Impressions

Hooray, my OLPC arrived this morning!

Without having the time to go in to any detail, here some initial first impressions.

- It's really small, but the carrying handle and LCD hinge/swivel assembly make it larger than my Eee PC. Not a huge issue for me, and the hinge/swivel makes for some cool functionality that I want in a small notebook. Handle I can live without, but it won't be a deciding factor for me. Tie.

- It's marginally heavier than the Asus. Subjectively I prefer holding the Asus in one hand; the weight distribution seems better/more convenient. Winner: Asus. UPDATE: I just found a nice way to hold the OLPC; if you wrap your arm around it you can rest the back end on your forearm while the front rests on your chest. It's a little awkward, but the additional depth makes it a bit more convenient than the Asus (I think). NEW WINNER: Tie.

- You've seen the keyboard, you don't need me to add anything, right? Fine. The Asus keyboard is obviously better for most of what I need to do. That said, I'd be more comfortable taking the OLPC into harsher environments, which I need on occasion. Winner: Asus, with caveats that make it seem more like a tie.

- Boot-up time is acceptable, but slower than the Asus. Again, this won't be a major deciding factor, but a quick boot-up is rather important to me: the quicker it starts up, the quicker I can do something useful, the more likely I'll be to make use of the functionality I can hold in my hand. Asus (20-25 seconds worst case), OLPC (90+seconds?!). Winner: Asus, hands-down.

- The OLPC screen is pretty nice, and the no-backlight mode is really easy to read in bright light, and passable in low-light. The Asus screen is good too, but (so far, anyway) I haven't been able to turn the backlight off. Winner: OLPC.

- Apps: The Asus is a typical Linux box. The OLPC as delivered isn't set up for non-kid use, but there's a shell available, vi is installed by default, and I'm assuming I'll be able to use it as a generic Unix box w/o much of a hassle. I could be wrong. As delivered, winner: Asus. In reality, most likely dead even.

- Speed: Asus, no contest, at least so far. The OLPC is running a Geode at 433MHz, the Asus a Celeron M (at 630MHz?). I'm surprised the perceived speed difference is so great, and I'm not sure where the biggest differences are. Hopefully someone with more time will post some I/O benchmarks.

- Battery life: Don't know yet. I'm guessing the OLPC, perhaps even by a landslide. The Asus will go ~3 hrs, depending on what you're doing. I'd rather it was... a full day :)

- Noise: OLPC, hands down. The Asus gets pretty hot and has a fan and isn't afraid to use it.

- Networking: So far, I can't get the OLPC to connect to my WPA-PSK wireless; this is a MAJOR lose. I'm sure somebody else has this figured out, though. Temporary winner: Asus. UPDATE: Heng's comment does, indeed, solve the problem. New winner: Tie.

First Final Verdict: if only they could combine the two... I may end up going to and getting a UMPC at this rate, but they cost 2-10x as much, so I'm in no hurry. I suspect I'll be using the Asus more because of the keyboard, but once I have time to start hacking on the OLPC (and mod the case) that might change.

I'm excited by both, which is an unfortunate commentary on my life. This *is* a useful form factor (at least for me, and, I suspect, a lot of other people) but I'm not sure the optimal ergonomics have been figured out yet, and, as usual, we still need better batteries.