Atom constructs are cool

This screen shot illustrates something very cool about the Atom feed format. (If you’ve written an RSS parser but haven’t done Atom yet, you might find this interesting.)

Atom project screen shot

What you’re looking at is part of the Atom spec (leftmost), then part of the list of files of my XML-related classes, then the interface for a class named RSAtomPerson.

(Note to people who don’t program in Cocoa: the “RS” prefix is there because, in Cocoa, you typically prefix your class names with some initials—your own, your company’s, or the name of the project.)

Object-oriented thinking

Atom is more complex than RSS, yes—but, at the same time, the Atom folks did a cool thing that mitigates this complexity: they defined certain “constructs” that are re-used in different places. If you’re using an object-oriented language (such as Objective-C, Python, and C++) you can map these constructs to classes.

For example, a Person construct has three pieces of information: name, URL, and email address. Wherever a person is identified in an Atom feed, it uses a Person construct. You might have a whole bunch of Person constructs in a single feed—but, each time a person is identified, it’s done the same way.

There are other constructs too, for content, dates, and links. (The Content construct is probably the most complex, but you only need to do it once, and then you can handle titles, summaries, and content elements.)

What I like about this is that it practically tells you how to write an Atom feed parser: it suggests breaking up your code into a collection of small classes for each of the different constructs. Though an object-oriented language isn’t required to parse Atom feeds, the Atom spec is a case of object-oriented thinking applied to feed formats, which is cool.

Going back to the screen shot—you can see it, a direct line between the spec and its expression in object-oriented code. Nice.

30 Nov 2004