Archive for the ‘Apple’ Category

Bring back STX and ETX

Saturday, December 30th, 2006

Some people think that XML is the greatest invention since sliced bread. (I won’t name names, to protect the non-existent.) In contrast, I think that it’s just a symptom of a disease, a terminal illness infecting the entire computing world. Programmers are supposed to be smart, but we’re actually the ones who are responsible for the spread of the disease. We started and promoted the practice of using printable text to delimit printable text. In my haughty opinion, this was one of the worst ideas in the history of computers (surpassed only by SMTP and MacAppADay). It was doomed to fail from the beginning, kind of like the paradox of the liar. The use of printable text to delimit printable text has been the cause of countless bugs — let’s say 500 billion — and indeed, countless security vulnerabilities. It continues to plague us today.

Having worked on a feed reader, I do know a thing or two about this issue. I can tell you that it’s a major pain to parse XML feeds. Parsing HTML is even worse, but thankfully we can leave the majority of that to WebKit. It’s hard enough when everything is perfect, but we inevitably run into issues where the text is improperly escaped or not properly escaped. This is no fun for anyone.

Since the beginning, ASCII contained a number of non-printing control characters, but for some reason they have fallen out of favor. Among the control characters are STX (0x2) and ETX (0x3). Their position in the list of character codes indicates their importance: they were used to delimit text. With character codes such as these, parsing data into strings becomes trivial:

  1. Start parsing a string when you see a STX code.
  2. Continue until you see a ETX code, you see a non-character code, you reach a preset maximum length, or you run out of data.
  3. If the last code was ETX, you’ve got a good string. Otherwise, you’ve encountered an error, and you can do whatever error handling you like.
  4. There are no more steps. The characters in the string are all literal, no unescaping necessary.

Unicode has added some similar codes such as SOS and ST. I’d like to see even more control codes, to allow for fine-grained specification of the structure of the text. For example, we could have control codes to delimit words, sentences, paragraphs, etc. This would be similar to tags in HTML but without the use of printable characters to represent the tags.

Why don’t we do this now? One objection is that files containing control characters are not human readable. I think that this is a lame excuse, because no computer file is human readable. Although my hard drive is enclosed, preventing me from examining the files on there, I have burned text files to DVD, and no matter how long I stare and squint at the shiny bottom, all I can see is my own reflection. Anyway, a lot of markup is human readable only in the sense that Derrida is human readable: there is a series of legible text characters, but do you really want to wade through all the crap to make sense of it?

Perhaps the real point underlying this objection is that control-character delimited text would not be readable by simple (i.e., dumb) text editors. This is true, but why should we be ruled by the lowest common denominator? Many modern text editors are quite intelligent and could handle the new format easily. They can already parse various forms of syntax and highlight them for the user. Let’s not let backward compatibility hold us back. That’s certainly not the Apple Way. It’s not entirely the Microsoft Way either; after all, the Word file format makes no concession to simple text editors. Neither does the cross-platform Adobe PDF.

The most powerful objection to using control characters as text delimiters is that we shouldn’t force users to learn how to input control characters along with text. I agree, which is why I think the burden should be placed on computer programs — the text editors and command line interpreters — rather than on users. When taking text input from users, an app should do the following:

  1. Use the context to guess the user’s intention.
  2. Give a visual indication of the guess to the user. Syntax coloring is one example, but the possibilities are endless. Be creative.
  3. Make it easy for the user to correct bad guesses.

In command line interpreters, by the way, there’s no good reason why the space key needs to separate arguments, as opposed to a key for a non-printable character such as escape. It’s the 21st century, by Jove, and we should be finally be able to use any printable character in a file name, including colons, quotes, slashes, and spaces, without having to do voodoo on the command line just to refer to it! (I won’t even mention hierarchical file systems, which are themselves a bad idea. Oops, I just did. Since I mentioned it, the ideal behavior when a user enters a file name is to quickly find the named file or files, which any decent file system should be able to do, and show a visual preview so that the user can verify or choose the correct file, if necessary.)

This rant has been brought to you by BBEdit. The makers of BBEdit, I assume, take no responsibility or credit for the content here, nor do they endorse the opinions I’ve expressed. (Or do they?)

(No, not as far as I know, which is nothing. In any case, I do endorse BBEdit.)

How to delete a master password in Tiger

Thursday, December 28th, 2006

Warning: Do not attempt if you’re using FileVault. Side effects could include Very Bad Things™ such as losing your entire home directory, headaches, vomiting, diarrhea, going to jail, not passing Go, not collecting $200, and ripping a hole in the space-time continuum. Do not attempt while under the influence of narcotics or while operating heavy machinery.

Warning #2: For goodness’ sake, back up your files before attempting. For safety’s sake, make multiple backups of your entire hard drive, and store them off-site, preferably off-planet.

Warning #3: My lawyer has just run away screaming, so I should offer the disclaimer that you proceed at your own risk. I assume no liability for any consequences, which may include but are not limited to lost data, broken marriages, seven years of bad luck, and the Apocalypse.

Given the above warnings, why would anyone in their right mind want to delete the master password from their computer? Answer: they wouldn’t. (My mind is going. I can feel it.) In my case, setting the master password was only an experiment, so I didn’t want to leave it on. Anyway, here’s what you do:

  1. Remove FileVaultMaster from the Keychain List in /Applications/Utilities/Keychain Access.app.
  2. Move the files FileVaultMaster.cer and FileVaultMaster.keychain in /Library/Keychains/ to the Trash. This requires an administrator password.
  3. If you set a password hint for the master password, enter the command below in /Applications/Utilities/Terminal.app. This also requires an administrator password.

    sudo defaults delete /Library/Preferences/com.apple.loginwindow MasterPasswordHint

  4. Restart. (This may not be necessary, but it won’t hurt.)

This conversation can serve no purpose anymore. Goodbye.

IGNORE THIS FILE

Thursday, December 21st, 2006

/etc/fstab.hd: This file does nothing, contains no useful data, and might go away in future releases. Do not depend on this file or its contents.

Methinks the file system doth protest too much!

P.S. Pay no attention to the man behind the curtain.

Leopard Tech Talk: Postlude

Thursday, December 14th, 2006

If you think that America is a free country, try driving through Illinois. Their state motto is Give us all of your spare change. As I mentioned before, one of the Mac OS X Leopard Tech Talks was held in Chicago yesterday. (Except that it wasn’t yesterday when I mentioned it before.) I was there, and I had a good time. As you would expect, security was tight: I was asked for my name before receiving a name tag. Apple was kind enough to provide food and drink for the free event, which was much appreciated, though the NDA prevents me from disclosing the items on the menu. I will, however, reveal the latest secret Leopard feature. I can confirm that seeded builds now include a Spotlight-searchable C++ GUI Programming Guide. Thanks, PC guy!

I believe that I can also reveal, since I discovered this information myself by testing, that Vienna is Leopard-ready. Or at least, nothing appeared broken when I played with it for 5 minutes. Yay!

I met a number of people at the event, including fellow blogger Geoffrey Schmit of Sugar Maple Software. The biggest celebrity was Sal Soghoian, AppleScript product manager for Apple. Indeed, he was so famous that he wasn’t required to wear the standard Apple employee uniform, or the 15 pieces of flair. To their credit, the ‘software evangelists’ who gave the tech talks were open and honest. They answered my questions, and they also convinced me to shave my head and dance with an iPod at airports. I would like to thank them, as well as Apple for bringing the show on the road to a location near me.

All I can really say about the content of the talks is that Leopard has a lot of cool stuff for developers. I’m tempted now to get an ADC Select Membership, so that I can receive seeds. (In case you’re wondering, Leopard seeds are not distributed to the attendees of Leopard Tech Talks.) Perhaps that was their insidious purpose. Anyway, I would recommend attending if there’s a Leopard Tech Talk in your area. Amen!

Leopard Tech Talk: See you in Chicago

Friday, December 1st, 2006

I’ve received a confirmation email from ADC that I can attend the Leopard Tech Talk in Chicago on December 13. Thanks, Apple! I’ll try to ensure that Vienna is Leopard-ready.

If you’d like to meet me there, let me know. I should be conspicuous as the only poor soul without a laptop.

From the days of yore

Friday, October 20th, 2006

When you work in an office, or more precisely a cubicle, you often receive an inheritance from the previous occupants. In my last office I inherited a number of books, which I didn’t pay much attention to until I moved out. Among the chaff, I recently discovered some wheat. Well, not really wheat: more like wood pulp, quite inedible wood pulp, but interesting inedible wood pulp nonetheless.

  1. Macintosh Pascal by Robert Moll and Rachel Folsom, 1985.
  2. Macintosh Revealed: Unlocking the Toolbox by Stephen Chernicoff, 1987.
  3. Macintosh Revealed: Programming with the Toolbox by Stephen Chernicoff, 1987.
  4. Macintosh 512K enhanced by Carol Kaehler, Apple Computer, 1986.

The last book is particularly interesting, because it’s a manual. That’s right, folks, believe it or not, Macs used to come with a manual! Actually, Macs still come with a manual, but it’s mostly a hardware manual, whereas the old manual gives extensive instructions on how to use the operating system and software. I could tell that it was from the 80s without even looking at the publication date, because the people in the photos are all wearing official 80s uniforms, hairstyle included. I imagine that a-ha is playing in the background.

A few things struck me in looking through these books. First, a cloud of dust in my face. Second, it struck me how much has remained the same over the years. The Finder is still there, along with the Desktop and the majority of menu items, keyboard shortcuts, and mouse behaviors. I was intrigued by something called the MiniFinder, which seems to be a cross between the Dock and the application switcher. (Really, it wasn’t so mini, because it took up the entire screen.)

Another thing that struck me was the status of Pascal as the primary language for the Mac at that time. I wrote Pascal programs a lot as an undergraduate. I think I last saw Pascal on one of those VH-1 Where are they now? specials.

The final thing that struck me was the vast number of years Chris Espinosa has spent at Apple. The acknowledgments of Stephen Chernicoff’s books thank Chris Espinosa as one of his managers at Apple. Chris still posts frequently as a representative of Apple on the Xcode-users mailing list. Of course, I’m just assuming that it’s the same person rather than, say, the second generation of Espinosas, and that Chris has been at Apple the whole time.

Sorry, this post doesn’t offer any useful information. If you didn’t like it, you can send me feedback, but you have to use a #2 pencil.

WordPress bug with post comment feeds

Friday, October 13th, 2006

In the tradition of Apple Bug Friday (RSS), this post inaugurates WordPress Bug Friday. Actually, it’s just a coincidence that I fixed the bug on a Friday. Anyway, the bug is that the comments feeds for posts were returning HTTP code 304 (Not Modified) in Vienna, even though the posts had new comments that did appear in the main comments feed for the blog. Vienna, being a good net citizen, reads the Last-Modified date from a feed’s HTTP headers and sends the date back as If-Modified-Since in its request headers to the feed.

The cause of the bug in WordPress 2.0.4—as well as earlier versions of 2.0, I believe—appears to be that the comments feeds for posts were checking the last modified date for posts rather than the last modified date for comments, because unlike the main comments feed for the blog, http://lapcatsoftware.com/blog/comments/feed/, the comments feeds for posts, e.g., http://lapcatsoftware.com/blog/2006/10/09/stand-and-unfold-yourself/feed/, do not contain /comments/ in their URLs.

I discovered a ticket at the WordPress Trac discussing the bug, along with a patch. The patch was just two lines of code (or one, depending on how you count), so the change in the file /wp-includes/classes.php was easy to make, and it seems to be working fine now. Please let me know if you experience any problems.

While I’m on the subject of WordPress bugs, I’ll mention another one that has bit me a few times. If your post includes escaped HTML characters such as less-than and greater-than symbols, then when you edit your post again after saving or publishing, WordPress unescapes the characters in the editing view. Consequently, if you don’t re-escape those characters before saving or publishing, your post will be messed up. The technical term to describe this situation is lame. In some circles, they use sucky. My workaround is to compose a post entirely in a text editor such as Smultron and ensure that everything is perfect before I enter the post once and only once in WordPress.

Thus our first edition of WordPress Bug Friday comes to a close. I would be remiss, perhaps, if I did not also throw in an Apple bug. Since this post is lacking somewhat by my usual standards of (attempted) humor, I’ll mention an amusing and harmless little bug I came across. As a member of the Apple Developer Connection, I receive a monthly mailing containing a DVD with documentation and software updates. On the mailing label a few months ago, between my name and address, there was a line with the text NULL. Obviously the mailing label software was printing an additional field that in my case was empty. Given my programming background, I found this to be hilarious. (Admittedly, no one else did.)

By the way, I also find it amusing that ADC keeps track of us by PersonID. I am not a number, I am a person! Oh wait, I’m both.