Site Archive (Complete)
Lightweight Languages Blog: Syntact-Ick
Light Weight Languages
ALTERNATIVE SYNTAX

Perl, Ruby, Python, PHP and More.

by Kevin Carlson
DECENT PROGRAMMING

Rails, Ajax, Python, Zope and more.

by Jeffrey Hicks
RubyConf 2006

Breaking News from the Show

by Jack Woehr
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



This is a public forum. CMP Media and its affiliates are not responsible for and do not control what is posted herein. CMP Media makes no warranties or guarantees concerning any advice dispensed by its staff members or readers.

Community standards in this comment area do not permit hate language, excessive profanity, or other patently offensive language. Please be aware that all information posted to this comment area becomes the property of CMP Media LLC and may be edited and republished in print or electronic format as outlined in CMP Media's Terms of Service.

Important Note: This comment area is NOT intended for commercial messages or solicitations of business.



October 2006
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        


 
INFO-LINK


Related Sites: DotNetJunkies, SD Expo, SqlJunkies