Uli's Web Site
[ Zathras.de - Uli's Web Site ]
Other Sites: Stories
Abi 2000
Stargate: Resurgence
Lost? Site Map!
     home | blog | moose | programming | articles >> blog

 Blog Topics

15 Most Recent [RSS]

 Less work through Xcode and shell scripts
2011-12-16 @600
 iTunesCantComplain released
2011-10-28 @954
 Dennis Ritchie deceased
2011-10-13 @359
 Thank you, Steve.
2011-10-06 @374
 Cocoa Text System everywhere...
2011-03-27 @788
 Blog migration
2011-01-29 @520
 All you need to know about the Mac keyboard
2010-08-09 @488
 Review: Sherlock
2010-07-31 @978
 Playing with Objective C on Debian
2010-05-08 @456
 Fruit vs. Obst
2010-05-08 @439
 Mixed-language ambiguity
2010-04-15 @994
 Uli's 12:07 AM Law
2010-04-12 @881
 Uli's 1:24 AM Law
2010-04-12 @874
 Uli's 6:28 AM Law
2010-04-12 @869
 Uli's 3:57 PM Law
2010-04-12 @867


Headaches further revelations

Sometimes you sit there with a headache and the memory of an article and two e-mails you read two days ago, not being able to do much else, and you suddenly comprehend something you didn't before. And if the headache isn't from alcohol, you can actually assume that this revelation will still be valid once you feel human again. Try this one:

There were a couple of postings on Cocoa-Dev by someone trying to use Cocoa APIs using AppleScript Studio's call method function. Now, if you remember, that function lets people used to not-quite-English statements like

copy (display dialog with prompt "I failed jiggery-pokery but I had A's in hullaballoo") to myVar
turn nice readable Objective C statements like
foo = [[NSFileManager defaultManager] directoryContentsAtPath: @"/Users/"];
into toll-free-bridged unreadabilities like
set foo to (call method "directoryContentsAtPath:" of (call method "defaultManager" of class
"NSFileManager") with parameter "Macintosh HD:Users")
(Note that I inserted the brackets in the AppleScript to improve readability).

Now, when I first read this I thought that guy got what he deserved. If you clicked the link above, you'll know my thoughts about AppleScript, and this example shows beautifully why you want to do Cocoa development in Objective C. So why doesn't that guy bite the bullet and switch languages?

Then, today, I wrote an e-mail to Tom Pittman and in the last line gushed a little about how his CompileIt! stack helped me get into programming from within the safety of HyperCard. Now, for those of you who never got to play with HyperCard or CompileIt!, basically CompileIt is like AppleScript Studio's call method command: It lets you call all the system APIs as if they were HyperTalk handlers and functions. So to have Quickdraw draw a rectangle, you'd write something like:

put newPtr(8) into myRect -- 8 bytes, for 4 two-byte shorts
setRect myRect,10,10,100,100
frameRect myRect
disposPtr myRect -- yes, no "e" - those were the System 6 symbol names.
Of course, you could have just done this in plain HyperTalk, by scripting the user's actions with the drawing tools, like:
choose rect tool
drag from 10,10 to 100,100
but play along there, will you? Well, anyway, just like with ASS and call method, this allows you to turn a straight affair of English-like code into a bastardised form of some systems-programming language.

So, what's the benefit? The benefit is a shallower learning curve. With tools like HyperCard or ASS, you can create the basics of an application, all the drudgework, using a much more natural set of metaphors. And when those fail you, you don't have to start from scratch writing event loops and window-management code. You just learn about those few lower-level Toolbox or Cocoa commands you need and only use those.

The advantage is that you can get to know the frameworks step by step, having small successes each time. By the time you have to learn the actual details of Cocoa programming, you'll already know most of the commands and conventions, and it won't feel half as foreign as it would have if you'd jumped straight in.

It doesn't change my opinion that AppleScript is a bass-ackwards language, and it doesn't change my opinion that call method's main effect is making code unreadable, but at least it makes me frightened of all these AppleScripters that will push into the Mac programming market eventually once they've moved to a better-designed language. They had the same basic learning curve I had, and they put up with AS... They'll smoke me in their pipes... :-)

Reader Comments: (RSS Feed)
No comments yet
Or E-Mail Uli privately.

Created: 2006-04-07 @352 Last change: 2006-04-07 @412 | Home | Admin | Edit
© Copyright 2003-2023 by M. Uli Kusterer, all rights reserved.