@interface AQBlog : NSBlog @end

Tutorials, musings on programming and ePublishing

Using AQXMLParser and Friends

Permalink

I've been asked a number of times to provide some examples on how to make use of AQXMLParser. A question which came in today has prompted me to make the effort and actually put together a simple project which demonstrates its use, along with its companion classes HTTPMessage and AQGzipInputStream.

The example project uses the asynchronous xml parser API to fetch my basic Tumblr post list, and displays the types and slugs of those posts in the UI (although it actually records all the data, in case some enterprising soul wants to actually make a detail view).

It fetches the data using a fairly simple set of code. I originally had it using a gzip stream, but it seems Tumblr never gzips its responses, so that didn't work out. I've left the appropriate code in there, albeit commented out, for your edification. In the snippets below, however, I've reinstated the gzip code.

Developing for iOS in a Server-Centric World

Permalink

Turns out, developing iOS apps is different from developing web apps. Like, hella different. For any server-side readers out there, I thought I'd hit you with a few big ones: There is no CSS. Every part of a design has to be coded in Objective-C.

  • There is no flow layout (like HTML). Everything is position: absolute;.
  • Small “cosmetic changes” can mean hours or days for developers to complete.
  • No one unit tests in Cocoa. Like, no one.
  • Likewise, unit testing is a bitch.
  • No one does automated UI testing. There are some open source projects, but it's far from the mainstream.

Truth from Mr. Furrow there. As someone who went the other way, I can absolutely say that folks using some of these new server-side frameworks have a ridiculously easy time of it.

Things are starting to change on our side, of course: starting back in the late 80's with Interface Builder and the Application Kit, and more recently with Cocoa Autolayout. There's still a world of difference between tweaking a CSS file to change a button's composition and doing that in Cocoa however.

Apple's Response to the 'Kindle Theory' of Antitrust

Permalink

[I]f Amazon was a “threat” that needed to be squelched by means of an illegal conspiracy, why would Apple offer Amazon's Kindle app on the iPad? Why would Apple conclude that conspiring to force Amazon to no longer lose money on eBooks would cripple Amazon's competitive fortunes? And why would Apple perceive the need for an illegal solution to the “Kindle threat” when it had an obvious and lawful one which it implemented – namely, introducing a multipurpose device (the iPad) whose marketing and sales success was not centered on eBook sales?

This sounds quite fair— until you consider the restrictions placed upon competing eReader apps on this multipurpose device:

  • No sales except through Apple IAP @ ~110% of revenue.
  • No sign-up for accounts.
  • No links to store websites via Safari.
  • No links to company website (even for displaying corporate privacy policy, etc.).
  • No static text giving the address of company/store website.
  • No static text saying 'our website' or similar.
  • No introduction or mention of non-free content availability.
  • No use of the words 'trial' or 'preview' to refer to content.
  • No means to acquire new content aside from 100% free content within the application.
  • No text suggesting that non-free content is available for purchase (even without discussion of where one might do so).

For the record, all of the above were cause for the Kobo app to be pulled from the store if we did not submit a hotfix immediately. I find it hard to believe that they wouldn't be doing the same to Amazon.

Readium Open Source Initiative Launched to Accelerate Adoption of EPUB 3 | International Digital Publishing Forum

Permalink

The IDPF has got together a who’s-who of people and companies in the eBook world to work on an open-source implementation of a reference ePub3 reading system and container library. And of course Kobo is putting a ton of weight behind it. Also, me: I’m going to be working on this project full-time here very shortly.

Looking through the project’s goals, you’ll see a good amount of overlap with the goals I’d previously stated for the ePub Author project. The core aims are all there:

  • A browser of ‘ePub3-flavoured HTML’ content.
  • A library encapsulating the correct parsing and generation of all forms of structured content described in the ePub3 standard.
  • Best-in-class support for non-Roman scripts, particularly vertically-flowing ones.
  • No limits on its use as the core of a larger project, even commercial ones.
  • Lots of industry know-how being funneled into a single output.

So yeah: I’m rather excited about this one. Expect to hear more from me as it all progresses.

Now I’ll just go back to writing ePub3 structured content handling code…

“Downmarket Genre Fiction” Is It?

Permalink

The astute Mr. Gemmell earlier today made note of a rather elitist-sounding article over at paidContent:UK. The author of that piece rather laments the fact that eBook consumption is led by ‘genre fiction’. You know– everything that most people read; something — shudderclassifiable. Science fiction. Romance. Crime. Horror. Fantasy. Historical.

So, is it just me, or does that sound an awful lot like regular books? What else could we call them……… Ah yes– stories.

This all smacks of the same sort of book-snobbery we see in some literary awards' shortlists, or in programmes about books on the BBC. This has prompted a number of authors to call out the organizers and producers of such fare for their low view of so-called 'genre fiction'. In March 2011, author Stephen Hunt wrote:

In my world there is only one genre permitted access to the oxygen of publicity in the mainstream media, and that genre is contemporary fiction. It is also called literary fiction by its supporters, just to underscore the point that anything that isn’t written in their genre can never be classed as literature or improving or worthy.

The end result of all this snobbery, he points out, is the loss of the joy of reading in the youth of today. In amidst the many other ways of finding entertainment, the elevation of ‘contemporary fiction’ as the only thing worth reading has turned off many of our youth from reading altogether:

And that conflict, dear reader, between what we read and what is actually covered by the media has sadly begot a much greater one. People, especially younger readers, have given up on fiction on dead trees. They were happy to play the 'literary fiction' game in a gentler age, when it was the only game in town. Hell, some crazy old dudes even read short fiction in the pulps back in the day. But it's a more packed playlist now: MMOGs, IM, BitTorrents, RSS feeds, happy slapping, texting, DS, Xbox, Twitter, FaceBook, iPods, iPads, YouTube, blogging, Tumblr, Angry Birds – you know the drill, right?

I suppose I was lucky in high school that my English teacher didn't hold to such things– we were specifically encouraged to read fantasy and science fiction; I remember reading Howard Fast's The First Men there, and many people's marks took a good boost when writing up that one (we were tasked with writing a newspaper editorial about the experiment in the story).

When reading the article which provoked today's discussion, I initially thought that perhaps the inflammatory title (*downmarket* genre fiction) was an addition by the editor, and that perhaps the writer herself had a more nuanced view. However, down towards the bottom were a couple of gems which rather cut short that hope:

The reading public in private is lazy and smutty. E-readers hide the material. Erotica sells well.

I’m not so sure it is wise to underestimate the boundless idiocy of the unobserved reading public. They may intend to go to the Economist website to read the latest in the euro crisis, but oops! they’ve ended up on Mail Online reading about the Kardashians.

…ok. That's one way of putting it. Another might be: we read for entertainment, not self-betterment. Most people spend long days working, then most of their evenings working in another fashion: food, cleaning, caring for family. If we choose to spend our leisure time reading, we are more likely to read something entertaining than improving; simple fatigue will dictate that as the norm, if nothing else. Don't think that it's all slush, though. Of everything I've read in my life, no book has made me reach for the (conveniently built-in) dictionary than Gregory Macguire's Wicked series. Damn that guy has some vocabulary. And how many other 'genre fiction' books – and genre fiction in a fantasy setting, based upon a line of children's books, no less – would come with study notes included?

The establishment might choose to look down its nose at writing for the sake of story, but its nature does not make it automatically sub-standard.

iBooks Author vs. ePub Author

Permalink

"iBooks Author"

So, yesterday Apple launched the new iBooks Author application for the Mac. It looks great, produces fantastic dynamic content, and more than one person assumed that it was outputting ePub3 files. However, that was not the case, as is extensively documented by Daniel Glazman (co-chairman of the WC3 CSS working group) on his blog:

A wysiwyg EPUB3 editor will not be able to edit correctly an IBA document because of the different mimetype and the proprietary CSS extensions. iBooks Author is not able to reopen a iBook it exported in their pseudo-EPUB3 format because there is no Import mechanism! That means that on one hand EPUB3 readers cannot reuse a document created by iBooks Author because of its HTML/CSS/Namespaces extensions, and on the other iBooks Author cannot create an iBook from an existing EPUB3 document because it cannot import it.

In actuality, it even goes a little further than this.

I Don't Have a Story

Permalink

It's been fascinating to read all the remembrances of Steve Jobs over the past couple of days, and all the inspiring eulogies written by those whose lives he had profoundly affected in some way.

As much as I'd love to, however, I don't really have any stories like that. Obviously my career would likely not be anything like it is now, and I almost certainly wouldn't have the sort of community standing I now enjoy. But I can't really say that I would miss him because of that– I am where I am, and I shall go further, and his presence is unlikely to affect that. I am of course grateful for his role in creating a world where I've been able to achieve what I have, but that world is here now.

So, why would I miss him? What, exactly, am I mourning? Because I'm clearly affected by his passing.

After much musing, I think I now know.

Firstly there is a selfish reason: there was so much more I believe I could have learned by watching him. I learn best by watching others, and I've paid close attention to Steve Jobs for a long time now. Each decision, each statement, I tried to understand; to walk around in his shoes for a while. Perhaps I wouldn't agree with him, but I could hardly grow as a person unless I understood why that was, and could justify both sides. The justifications, after all, are what should be compared, not the actions themselves.

So I'm sad that there is little more I can learn from him. He was a good teacher in that regard (and I know teachers, I was raised by them), and so I shall miss all that I'll never learn from judging his reactions to what happens in the future.

Secondly, I feel like he had great respect for the users of computers. That manifested as his perfection, I think, and I know a lot of people are (or would be) grateful for that. So we respected him in return— what goes around comes around. Therefore, we feel the same loss we would for anyone whom we held in esteem.

So I guess what I have to thank Steve Jobs for is all that he taught me, and the respect he showed to me, and engendered in me, all without even knowing of my existence.

Thank you Steve. Take your rest now, you've earned it a thousandfold.

The Spark

Permalink

I got into computers at an early age. I suppose it was only natural— my father had been involved with computers and programming since university in the mid 60’s, and by the time I was about 6 or 7 he was working with programming enough that he had a computer at home, on which I wrote my first BASIC program at the age of 8 or 9. My first real exposure to the whole world of computers, however, came through a BBC series called The Dream Machine.

The series itself showed everything from Babbage and Blexley Park through to the relatively new 32-bit personal computers which were available at the time. The thing that got me interested though was the information on the Home Brew Computer Club in 1970’s Silicon Valley, and the characters and events which made the greatest impression upon me were the two Steves and the rise of Apple Computer. These two unassuming individuals’ achievements, culminating in the immensely powerful introduction of the Macintosh were the spark which ignited my own desire to work with computers, and to learn more and more about them as I grew older.

More than anything else, I’m thankful for that example. Without it I strongly doubt I would be where I am today.

Memory Management in Objective-C

Permalink

An article on the Fun with Objective-C Tumblr today talks about learning Objective-C.

This is something any experienced Cocoa developer has been asked at least half a dozen times:

“What’s the best way to learn Objective-C/Cocoa?”

I have two answers to this question:

1. Be curious
2. Don’t be satisfied

There's plenty to read in the full article, but it finishes with the following epithet:

1. Know what a pointer is.
2. Memorize the memory management rules.
3. Never invoke -retainCount.

The second item there is one I'm frequently told is ‘really difficult’ to understand. It's not. It's really not. It looks like this:

  • Only the owner of an object needs to even think about its memory management.
  • You only own an object if you get it from a method whose name begins with any one of:
    • alloc, including +allocWithZone:
    • new, including +newSomethingSomething
    • init, including -initWithSomeParameter (er, no, it doesn't. I'm being stupid. Sorry.)
    • copy, including -copyWithZone: or -mutableCopy or -mutableCopyWithZone:
  • You also ‘own’ an object (technically, you own a single reference) if you send it the -retain message.
  • If the object doesn't come from a method matching those rules, you don't own it.

Edit: Specifically, the method must either be one of the above words, or begin with one followed by an uppercase letter. This means that +newSomething returns an owned reference, but +newestSomething does not. Thanks to Dave DeLong for reminding me of this via email.

It's that simple. If you call a method beginning with alloc, new, init, or copy, then you must use -release (or -autorelease) to balance that call. If you don't call one of those methods, you Needn't Care.

How about CoreFoundation? That's even simpler: you own an object if it comes from a method containing Create. The same thing could be said about Copy, but CoreFoundation's copy constructors are always careful to frequently already contain Create, so we don't need to. Anything named using Get returns an already-managed reference, so you don't need a CFRelease for it.

Edit: I'm reminded by Peter Hosey that many CF-style APIs outside of CoreFoundation itself tend to use Copy without Create, for instance those in CoreGraphics. Note however that not everything that looks like a CF object really is one— many are just C wrappers around Carbon-era C++ code.

See? Easy. A list of four keywords in Objective-C code indicate the only times you need to ever think about memory management. And one keyword in CoreFoundation to tell you the same.

Now, there are exceptions– usually when something missed the boat, or when an existing API needed to be changed to fix an internal memory-management issue. The documentation will tell you about these very rare cases, but the best way to catch them for now is judicious use of Build & Analyze. The Clang compiler's static analysis tool knows all about these rules, and can be told about any differences to them by any API. It will tell you explicitly if you've released something you don't own, or have failed to release something you do own. Use it. Love it.

Memory management in Cocoa isn't difficult. There are rules, but they're simple and easy to remember. The main thing to remember is:

Don't over-think it.