?

Log in

No account? Create an account

Previous | Next

Programming in English

I'm unconvinced of Applescript's utility as a programming language, but its extensive use of prepositions in its syntax does make for some very, er, friendly to read code. It's at least charming.

tell application "Adium"
   set theAccountList to every account whose status type is offline
   repeat with theAccount in theAccountList
      tell theAccount to go online
      end repeat
   activate
   end tell

Tags:

Comments

( 7 comments — Comment )
moominmolly
Oct. 17th, 2008 03:18 pm (UTC)
Hah. That's adorably readable!
szasz
Oct. 17th, 2008 03:23 pm (UTC)
What I'm discovering, though, is that just like COBOL, the syntax only LOOKS like English; it's actually quite rigid like any procedural language, so I get frustrated when I keep having to go to the Applescript docs to figure out how to "say" something.

Its "default variable" (like $_ in Perl) is called "it", though, so you can also say things like:

get the beginning of theAccountlist
tell it to go online
signsoflife
Oct. 17th, 2008 03:26 pm (UTC)
You see, this is what I thought reading it -- that the syntax was deceptively english like, and I'd expect to find that more confusing than a more stilted syntax.
szasz
Oct. 17th, 2008 03:28 pm (UTC)
The canonical example in COBOL is where you want to write:

WRITE OUTPUT-FILE FROM OUTPUT-RECORD AFTER ADVANCING 1 LINE.

but that's a syntax error. It has to be "LINES" regardless of the plurality of the value before it.
szasz
Oct. 17th, 2008 03:24 pm (UTC)
Oops, I am lying. It used to be called "it", but when they added OO stuff to Applescript, apparently "it" is now a self-reference, what other languages would call "this". The default variable is now called "the result":

get the beginning of theAccountList
tell the result to go online


...not nearly as charming.
moominmolly
Oct. 17th, 2008 03:28 pm (UTC)
Oh, not nearly, alas.
jlindquist
Oct. 17th, 2008 05:19 pm (UTC)
Yeah, I find it cumbersome to write compared to shell scripts, particularly "What the hell do I do to make this function take this argument? (Never mind I can't just write it in vi.) Its syntax echoes what I remember of HyperTalk, for which Bill Atkinson drew from Smalltalk.
( 7 comments — Comment )

Profile

14L
szasz
Charley

Latest Month

July 2013
S M T W T F S
 123456
78910111213
14151617181920
21222324252627
28293031