Google Webfinger

This is pretty old news, but I missed the original announcement and I think it’s pretty interesting.

Google have implemented an alpha of the WebFinger protocol. If you have a Google profile, click on “Edit your profile” and add ‘webfingeralpha’ as an interest. Congrats, your gmail address is now a WebFinger identifier and will resolve to an XRD file containing information about services you use (if you’ve included that information in your Google profile).

This is pretty fun to play around with. Given an email-like identifier, such as evalpaul@gmail.com, get the host-meta XRD file for the domain:

paul@knuth ~ $ curl -i http://gmail.com/.well-known/host-meta
HTTP/1.1 200 OK
Content-Type: application/xrd+xml
Transfer-Encoding: chunked
Date: Mon, 01 Feb 2010 12:36:47 GMT
Expires: Mon, 01 Feb 2010 12:36:47 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Server: GFE/2.0
...
<?xml version='1.0' encoding='UTF-8'?>
<!-- NOTE: this host-meta end-point is a pre-alpha work in progress.   Don't rely on it. -->
<!-- Please follow the list at http://groups.google.com/group/webfinger -->
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0' 
     xmlns:hm='http://host-meta.net/xrd/1.0'>
  <hm:Host xmlns='http://host-meta.net/xrd/1.0'>gmail.com</hm:Host>
  <Link rel='lrdd' 
        template='http://www.google.com/s2/webfinger/?q={uri}'>
    <Title>Resource Descriptor</Title>
  </Link>
</XRD>

Now that you have the URI template, get the XRD file for the specific user:

curl "http://www.google.com/s2/webfinger/?q=evalpaul@gmail.com"
<?xml version='1.0'?>
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>
	<Subject>acct:evalpaul@gmail.com</Subject>
	<Alias>http://www.google.com/profiles/evalpaul</Alias>
	<Link rel='http://portablecontacts.net/spec/1.0' href='http://www-opensocial.googleusercontent.com/api/people/'/>
	<Link rel='http://webfinger.net/rel/profile-page' href='http://www.google.com/profiles/evalpaul' type='text/html'/>
	<Link rel='http://microformats.org/profile/hcard' href='http://www.google.com/profiles/evalpaul' type='text/html'/>
	<Link rel='http://gmpg.org/xfn/11' href='http://www.google.com/profiles/evalpaul' type='text/html'/>
	<Link rel='http://specs.openid.net/auth/2.0/provider' href='http://www.google.com/profiles/evalpaul'/>
	<Link rel='describedby' href='http://www.google.com/profiles/evalpaul' type='text/html'/>
	<Link rel='describedby' href='http://s2.googleusercontent.com/webfinger/?q=evalpaul%40gmail.com&amp;fmt=foaf' type='application/rdf+xml'/>
</XRD>

Social Web Workshop

Chris Messina was in Toronto last week and ran a full day workshop on social web technologies at the Centre for Social Innovation. He had delivered a talk the night before called “Identity is the Platform” (slides) and the workshop focused on many of the same topics. The simplest way that I can think of to explain the premise of both is: 1) The web is becoming more social and 2) The data you create on the web has value.

The workshop was fairly interactive with people from the audience asking questions or raising points every so often. It was a pretty diverse group professionally speaking, made up mostly of software developers, technologists, designers and some marketing people. The material wasn’t very technical, which I found disappointing, but given the crowd it was the only thing that made sense (I guess for some reason I expected more developers).

The real take-away of the workshop was an overview of various open standards and protocols that can be used together as a sort of Open Web stack. The usual suspects were discussed: OpenID, OAuth, PubSubHubub and a few that were fairly new to me: Portable Contacts, Activity Streams and the Salmon Protocol. Chris also spoke a bit about the Mozilla Drumbeat project which certainly looks interesting.

At the end of the workshop we got into groups and brainstormed about how social web technologies could be used to create a better web. I co-opted my group to talk about how FreshBooks (my employer) could be made more social. Some really interesting ideas were brought up and I think it’s a great case study for working with a community that already exists (as opposed to building a community for a new social application).

The workshop was great. I’m glad I had the opportunity to participate and I definitely came away with a few thoughts and ideas. For one, it could be a worthwhile project to document existing or create new open source projects that use open web technologies. Often it’s easy to find sample code, but it’s usually stripped down and not very useful. Real, concrete examples from open source projects could be extremely useful for developers looking to implement support for open technologies and protocols.

Wrapping C++ Classes in a PHP Extension

I have a tutorial at the Zend Developer Zone called Wrapping C++ Classes in a PHP Extension. It walks you through writing a simple PHP extension that wraps a class written in C++. This is a useful thing to be able to do, especially when exposing an already existing library’s API to PHP userland scripts, which seems like a fairly common task.

Bad Signs – PHP’s “Shut Up” (@) Operator

Derick Rethans has a post about PHP’s “shut-up” operator (@) and why it should be avoided. He outlines a fairly common debugging scenario and gives some “under-the-hood” explanations on why that particular operator sucks. I couldn’t agree more (that it should be avoided) and I want to go further and talk about something that has always bugged me about that operator. In my opinion, it’s a hackish, band-aid fix to a much larger, much more worrisome problem: horrendous API design.

First, a disclaimer. I know that there are some historical reasons for a lot of these things (i.e. Exceptions not appearing until PHP5) but that doesn’t change the current reality. Consider for instance filesystem functions in the standard extension:

$lines = file("/tmp/file.txt");

If the file “/tmp/file.txt” does not exist, depending on your php.ini settings (because display_errors should always be ‘Off’ on production systems), you may get something similar to the following output:

Warning: file(/tmp/file.txt) [function.file]: failed to open stream: No such file or directory in /path/to/your/docroot/test.php on line 3

Now the proper thing to do of course would be to verify up front that the file exists and is readable with a call to is_readable() or something similar, but imagine this is a case where there is no way to determine ahead of time if a warning or error will be generated (Derick mentions silencing network errors with stream_socket_client() as one example). In this case, you might be tempted to use the shut-up operator and depend on the return value as the one true way to see if something was succesful or not.

Now compare this with what languages like Python (for example) do, If you were to write similar code in Python:

fp = file("/tmp/file.txt")

If the file did not exist, you’ll get an IOError which, if left uncaught, will result in the following being written to standard error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
IOError: [Errno 2] No such file or directory: '/tmp/test.txt'

The difference here of course is that an IOError can be caught, ignored or whatever best suits your needs. It’s a part of the language, the API is not just spewing out garbage to standard output or standard error. More importantly, having a function (or technically a constructor) like file() throw an exception follows a consistent design philosophy whereas PHP’s error system always leaves me guessing or consulting the docs.

I guess what I’m saying is that I think the shut-up operator is just one of those signs that PHP is suffering from some serious cruft and I don’t think those kinds of things bode well for a language.

What drove me away from Apple

I recently replaced my Macbook Pro with a Thinkpad x200 running Arch Linux and Windows Vista. After 5 years of using Apple products I decided to switch – to borrow one of their marketing terms – because frankly, I was sick of being abused as a customer and the lock-in was making me less and less comfortable. Here’s a list of the things that really did it for me:

  • Pricing the Macbook Air so high with such low specs.
  • Releasing an pitiful update to the air along with a nice $100 price increase.
  • Doing away with the matte screen option.
  • Pulling the remotes from being included with laptops (admittedly not a huge deal, but felt like salt on a wound).

Is it just me or is Apple becoming a little too arrogant? Anyway, I know Lenovo won’t be saints either, but at least in the non-Mac OS X world I can easily switch vendors down the road if I ever need to.