Free ranging comment

8 PM November 29, 2004

I love watching free-range hens running around the yard. Poultry in motion.

By alang | # | Comments (3)
(Posted to Stuff)

Plain Old Java Object

1 AM November 26, 2004

The C2 Wiki on the topic of POJOs:

Fowler et al invented the acronym POJO so that such objects would have a “fancy name”, thereby convincing people that they were worthy of use.

I don’t know why that amuses me. But it does amuse me. Muchly amuses me.

By alang | # | Comments (3)
(Posted to javablogs and Java)

The volatile keyword

1 AM November 24, 2004

Java’s execution order model gives me headaches when I think about the details, but it boils down to this:

There is no guarantee that two threads will have a consistent view of any given variable, unless (a) the threads synchronize on the same some object at some stage, or (b) the variable is declared volatile.

Using volatile forces the thread to retrieve the value from main memory before it is read, and to set it immediately after it is written, ensuring that

I find volatile handy where one thread is writing a variable, multiple threads may read the variable and there is no need for threads to block on the variable. For example:


static volatile int progress = 0;

static void doIt() throws InterruptedException {

(new Thread() {

public void run() {

try {

while (progress < 100) {

Thread.sleep(55);

progress++;

}

} catch (InterruptedException e) {

}

}

}).start();

while (progress < 100) {

System.out.println(progress);

Thread.sleep(500);

}

System.out.println(“done”);

}

This snippet of code starts a thread that increments the progress variable, while the main thread waits for the variable to reach 100. Since the variable is declared volatile, the watching thread is guaranteed to see the same value that the incrementing thread sees. If progress was not volatile, the watching thread may not ever see the value change – even after the incrementing thread had terminated.

Update: Any use of synchronize causes a thread to make any outstanding writes to main memory, and to re-read variable values from memory before using them again.

By alang | # | Comments (1)
(Posted to javablogs and Java)

LRU Map

2 AM November 19, 2004

I went looking for a light-weight cache today and found the LRUMap class buried in Commons-collections. LRUMap works just like a normal map except that it can only contain a certain number of items. When your code tries to insert more than that number of items, the LRUMap evicts the least recently accessed item.


Map cache = new LRUMap(3);

cache.put(“A”, “Aardvark”);

cache.put(“B”, “Bobcat”);

cache.put(“C”, “Kitten”);

// Prints “Aardvark” and makes “Bobcat” the

// Least Recently Used key

System.out.println(cache.get(“A”));

cache.put(“D”, “Dinosaur”);

// Prints Aardvark, null, Kitten, Dinosaur

System.out.println(cache.get(“A”));

System.out.println(cache.get(“B”));

System.out.println(cache.get(“C”));

System.out.println(cache.get(“D”));

By alang | # | Comments (3)
(Posted to javablogs and Java)

Bye-bye Back Pages

8 AM November 18, 2004

Chris Sheil, writer of Back Pages has stopped blogging, at least while he finishes his book. Back Pages has hosted lots of good arguments in the blog comments, but – (cue music: lone trumpeter playing The Last Post_) Chris’s last post ends with an empty comments section and nowhere to enter a comment. It’s kind of sad.

I’d only been reading Back Pages for a few months, but in that time I found many of Chris’s posts and ensuing comments thought provoking. In particular:

  • The Fear, loathing, etc series analysing the polls in the lead up to the recent Australian federal election.

Thanks Chris! You’ve left your mark on the way I think about the world.

By alang | # | Comments (1)
(Posted to )

WSAD/Eclipse Keys

11 PM November 14, 2004

I continue to rave about IBM's Eclipse based IDE, WSAD.

Here are the shortcut keys I use most. One of the big tricks with WSAD/Eclipse is learning the shortcut keys, because they don't appear in the right-click menu. Most I've learnt by inspecting the menubar, others from the documentation, but many have come by watching over the shoulder of my colleagues. Here are the ones I use the most.

KeyDescription
Ctrl+Shift+OOrganise Imports
Ctrl+Shift+MImport type under cursor
Ctrl+Shift+FFormat Code
F3Open declaration
F4Open hierarchy
Ctrl+Shift+GShow all references
Ctrl+Shift+UShow references in this file
Ctrl+QGoto last modified editor position
Alt+Left,Alt+RightGoto prev/next editor position in history
Alt+Shift+MExtract Method
Alt+Shift+RRename method/variable
Ctrl+LGoto Line number
Ctrl+OPop-up Outline
Ctrl+SpaceComplete whatever you're typing.

(These all work from the Java perspective, and some work in other perspectives too.)

So, what shortcut keys do you use? Have I missed any of your favourites?

By alang | # | Comments (15)
(Posted to javablogs and Java)

John Martinkus on Iraq

3 AM November 13, 2004

John Martinkus, the Aussie journalist who was kidnapped in Iraq last month, spoke to the Radio National’s Media Report about his experiences there. (transcript, real audio) He talks about the restrictions that journalists operate under in Iraq, which has some bearing on the kinds of reports that can (and can’t) be made.

By alang | # | Comments (0)
(Posted to Rants)

Kevin Sites in Falluja

7 PM November 12, 2004

Kevin Sites is a freelance journalist, currently embedded with the marines in Iraq. His latest two blog posts, Photo Blog: Taking Falluja and Street By Street are well worth taking the time to read.

You’d have to be desperate, brave or trapped to be in Falluja this week.

(via BoingBoing)

By alang | # | Comments (1)
(Posted to Rants)

Headlines Today

9 AM November 9, 2004

Headlines from today, Tuesday, November 9.

  • The Daily Telegraph* “This is a pure fight of good against evil” (page 8 and 9.)
  • The Sydney Morning Herald* “Clear out the terrorists: Allawi orders full assault” (link)
  • news.com.au* “It’s a fight to the end, says Rumsfeld” (link)
  • ABC* “Full-scale assault on Fallujah begins” (link)

I’m just saying.

By alang | # | Comments (1)
(Posted to Stuff and Rants)

More Advice to Democratic Bloggers

11 PM November 8, 2004

Joe posted Some Quick Advice to Democratic Bloggers, to which I would add:

  • IF Ohio was rigged, Kerry would have been presiding over a hostile senate and a hostile house of representatives – not exactly a tenable position. Be careful what you wish for.
  • The fact that the conspiracy theory can get this far shows up some serious deficiencies in the accountability and transparency of the vote casting and counting process. That’s the thing to attack. But wait a few months until some of the heat generated by the election dissipates.
By alang | # | Comments (1)
(Posted to Rants)

Egg Salad

1 AM November 8, 2004

Q: What is Mr Burn’s favourite food?

A: (steeples fingers) Egg-salad.

By alang | # | Comments (1)
(Posted to Stuff)

O'Reilly and Stock Art

8 AM November 7, 2004

O’Reilly’s Head First Design Patterns features cute-girl-in-a-tank-top. Turns out that it’s a stock photo that has already been used on the Vagisil Teen Center web site.

Since we call O’Reilly’s Perl book, “The Camel Book,” I suppose that makes this one, “The Vagisil Chick” book.

(via Joe)

By alang | # | Comments (2)
(Posted to Software Development and javablogs)

Stallman on Beethoven and Software Patents

11 PM November 5, 2004

Richard Stallman was in Sydney recently, and ABC Radio National broadcast a portion of his lecture on Software Patents. Stallman draws an analogy between software and music, and asks how Beethoven would have faired if musical ideas had been made patentable in the 1700s.

Audio stream available on the ABC‘s The Buzz site – starts at around 8 minutes 20 seconds. Transcript should be available Tuesday or Wednesday.

By alang | # | Comments (0)
(Posted to Rants, Software Development and javablogs)

Loathing The Printer

12 AM November 3, 2004

Update: I have found the printer of my dreams – the HP LaserJet 4300DTN. On Thursday, I set up a customer’s test environment, which including unpacking a brand new printer. From the moment I turned it on, the 4300 just worked. Sigh.

I loathe our office printer, and it hates me right back. I can tell by the way it picks up two sheets of paper at once, but pretends not to notice until it has conveyed the paper into its deepest and most inaccessible reaches. This is right over the toner fuser, which stays on for a few seconds after a jam, heating the paper to the point of brittleness, and ensuring the only way to remove the pages is in eight or twelve ragged strips. Every now and then, the printer also claims a burnt sacrifice of human flesh.

I also loathe our office printer because it is the outward and visible symbol of the Microsoft Windows printing subsystem. Here I present the specification for the Windows printing subsystem, reverse engineered by watching it’s behaviour over many battles:

  1. If there is no printer job, ignore the printer. Even if it is on fire, just ignore it.
  1. If you do have a printer job, and the printer is online, shovel the bytes out to the printer as fast as it will accept them. Then call the job done. If a user wants to know whether or not it worked, let them look in the output tray. If an application wants to know whether or not it worked, stuff it.
  1. But if you have a printer job and the printer is missing, jammed or on fire, tell the user that the printer is out of paper.

This aspect of the loathing is due to me working on an application that needs to know whether or not a particular page has actually printed. Our fourth or fifth design uses a hardware print server to expose the printer’s parallel port via TCP/IP. We use the Windows printer drivers to produce the bytes we need to print – Windows can be configured to print to a file instead of a parallel port – but then the application handles all of the sending and status testing itself. It works, but it’s ugly, and the operating system should be handling this for me.

The worst thing about the office printer is not that it doesn’t work, but that it only almost doesn’t work. If it plain didn’t work, it would be scrap by the end of the week. But because it limps along, because it can be made to behave if you cajole and threaten and tinker, it is allowed to stay. Crafty little devil.

You might suppose that I’m the leading advocate for printer replacement, but that position is filled by others with better qualifications than I. Our dear printer has a penchant for failing in the middle of large documents. Most commonly with a unique and artistic interpretation of the humble paper jam, but it can also fatally halt with “PCL XL ERROR.” It generally does this while a director is printing something to take to a meeting that starts in five minutes.

One day somebody will take that printer up the lift to level 11, then throw it down the middle of the stairwell. Bang, clang, crunch, splat, cheers and applause – our sanity restored.

By alang | # | Comments (3)
(Posted to Rants, Software Development and javablogs)

Calling Dr Who

10 PM November 1, 2004

For all you Dr Who fans out there, I recommend Raindancer’s theme song cover, Calling Dr Who. It’s a eurodance track with 16 beats to the bar, and they’ve set lyrics to the melody. It works well enough that I can’t get the song out of my head.

(A very slow Download page)

By alang | # | Comments (3)
(Posted to )
© 2003-2006 Alan Green