Author Archives: Paul Dixon

Some goals for April

I’m going to set myself a few goals for April, as there’s a variety of things I’ve been putting off. I’m hoping that by “going public” it will spur me to get them done!

Complete tagging system for Geograph

Geograph has a single “category” for each image and I’ve been working on-and-off since January to replace this with a decent tagging system. It’ll make such a difference to the usability of the archive and open up new possibilities, so it can’t happen soon enough. I’ll write about the design decisions made too…

Learn Python

This “Why Python?” article by Eric Raymond got me thinking I should try and give Python another crack. The next time I find myself turning to Perl I’ll see what Python has to offer. I like Perl for speed of development and the CPAN library, but I find it really time consuming to write decent OO code in Perl, so I rarely bother. Let’s see if I can if I learn to love Python too!

Release source code to pastebin.com

It’s been a year since the last release, and I get a steady stream of emails asking for the source. During April I will tidy the source, add a few common feature requests and release it under the GPL.

I think that’s enough. Let’s see how it goes…

PHP5 Iterators

I’m late to the PHP5 party. When it was released I kicked the tyres, wrote a few sample scripts, but lacked the time and resources to deploy it properly.

But as I’m about to start a large new project, it’s time to bite the bullet!

I’m playing around with Xapian, which is a C++ search library with a nice object oriented interface, but the PHP bindings for it exposed it as a series of functions, so I set about writing a wrapper to mimic the “real” API.

I noticed several classes implemented an iterator, so I thought it would be an opportunity to try and use the Iterator interface, and found a great article on PHP5 Iterators over at Scatterism.

Within a few minutes, I was able to turn a slightly ugly Xapian loop into a nice foreach – behold!

Before

$mseti = MSet_begin($matches);
$end=MSet_end($matches);
while (! MSetIterator_equals($mseti, $end)) {
        $doc=MSetIterator_get_document($mseti);
	$percent=MSetIterator_get_percent($mseti);
	$docdata=Document_get_data($doc);
	MSetIterator_next($mseti);
}

And after!

$mseti=$matches->begin();
foreach($mseti as $doc){
	$percent=$mseti->get_percent();
	$docdata=$doc->get_data();
}

Proof that iterators really do wash whiter and shift the stains inferior patterns leave behind 🙂