|
October 2006
October 13, 2006
Syntact-Ick
I sort of hate to bag on Applescript, because it's an amazingly powerful tool for automating tasks in Mac OS X. Truth be told, I couldn't do my job without it. Well, okay, users of bash, tcsh or zsh won't be impressed, probably. But that's the thing: Applescript was supposed to be the caring, sharing scripting language for the rest of us. But sometimes it absolutely drives me round the bend.
Here's what I mean: I frequently troll the Mac OS X Hints site, and today, I find this useful entry detailing how to use Applescript to print selected text from the browser. Here's the code snippet:
tell application "Camino"
activate
tell application "System Events" to keystroke "c" using command down
end tell
do shell script "~/Documents/Scripts/sel_lpr.sh"
where "sel_lpr.sh" is the following one-line shell script:
#! /bin/sh
pbpaste | lpr
Can you guess which line of Applescript is making me crazy? Yes, it's this one:
tell application "System Events" to keystroke "c" using command down
This is why I think that Applescript makes things worse by trying to sound more like English. Using an English-like syntax to make a language more accessible to novices is an admirable goal, but there's a reason most computer languages don't read like human languages: the computer is not a human brain. For one thing, a computer needs a level of specificity that the brain doesn't. English is by nature abiguous in its mapping of words to ideas. A computer language must by definition be unambiguous.
English already has a set of ideas that go with its words. Applescript tries to co-opt English grammar, but only succeeds in setting up the expectation that a line of Applescript will read like an English sentence. Clearly, that won't always be possible. And when it goes wrong, like in the above line of code, the discontinuity adds an extra level of confusion. By confusing one linguistic mapping (that of ideas to English words) with another mapping (that of software routines to English words), Applescript creates a perfect situation for the syntactic mush we see above.
I'd rather have English in one compartment in my brain, and my computer language in another. There's nothing immediately obvious about this line of Perl to a novice:
$x =~ s/a/b/;
and yet, once learned, it's really easy to remember.
Posted by Kevin Carlson at 10:42 AM Permalink
|
October 05, 2006
Get Ready for PyCon
PyCon 2007 may be several months away, but the conference is now accepting papers. Held Feb. 23-25 in Addison, Texas, the conference will feature a series of thirty-minute talks, keynote speakers (TBD), and five-minute lightning talks. The deadline for submissions is October 31.
Posted by Kevin Carlson at 11:57 AM Permalink
|
|