Re: AppleScript and shell scripting
Re: AppleScript and shell scripting
- Subject: Re: AppleScript and shell scripting
- From: has <email@hidden>
- Date: Sun, 29 Jul 2007 21:28:42 +0100
Ed Stockly wrote:
Whatever the faults of Unix shell languages, the notion that
AppleScript is "the most easily understood computer language" is
absolute bunkum.
I wonder, is that the consensus here on the list? Does everyone
agree that all the work put in to giving AppleScript an English-
like syntax has failed to make it the most easily understood
computer language?
Biased poll, given that there are plenty of folk on this list whose
don't have any experience outside of AppleScript and are therefore
hardly qualified to judge.
What other language allows a novice to sit down with a script and
understand exactly what's happening?
AppleScript certainly doesn't allow novices to "understand exactly
what's happening". While AppleScript English-like syntax makes it
easier for a newcomer to determine a given script's purpose, its
ambiguous nature and obfuscated semantics make it *harder* to figure
out the actual mechanics by which it operates, which in turn makes it
*harder* to learn how to write AppleScript code. Why do you think
folk describe AppleScript as a "read-only language"? Heck, even
William Cook, who was instrumental in designing AppleScript,
acknowledges that its English-like syntax is the source of many of
its problems.
AppleScript is your classic bait-n-switch: it looks easy from the
outside, which makes it tempting to non-programmers, but once they're
in it turns out to be a whole lot harder than they thought. Why do
you think young kids are taught Logo instead of AppleScript? Why do
you think researchers in end-user programming are focusing on visual
environments like Alice and Scratch rather than English-like textual
syntax like AppleScript? While good syntax matters, what matters a
whole lot more is clear and logical semantics, and AppleScript's
semantics are a mess.
What experience, if any, do you have with languages other than
AppleScript?
Since you asked (and since you seem to dismiss all my concerns as
some kind of syntax phobia):
Certainly not; I'm sure there are multiple reasons for your own
hostility. But you must agree that the alien-looking syntax of
traditional languages like bash, Python, etc. scares off many non-
programmers whereas the familiar-looking appearance of AppleScript
does not - I know it did me when I started out.
Yet if someone like yourself can somehow manage to pick up one of
those strange-looking languages, why not other folk? I think it
borders on the patronising to say they shouldn't be exposed to it, as
if they're not capable of understanding or asking for help to
understand. It also ignores the benefits that other tools can provide
users where AppleScript can't, and since you do have a bit of
experience outside of AppleScript you must be aware that there are
things that other languages do better than AppleScript.
If writing a solution in language A takes a dozen lines and writing
it in language B takes just one, you need a better argument than "it
requires a modicum of learning" to reject the second solution
offhand. Yes it requires a bit of work to learn/understand what's
going on in even a simple a shell-based solution, but don't forget
that learning/understanding the more complex AppleScript alternative
will require some work as well. In addition, every line of code you
write means more work and more opportunity for things to go wrong -
and this goes at least double for novices whose lack of knowledge and
experience means their error rate is considerably higher than
average. For them, shortness and simplicity is a major virtue. It's
only fair to new comers that you take these issues into account as
well when deciding what the best solution to present them with should
be.
I'm not entirely unsympathetic to the 'lean towards AppleScript
where practical' argument, but I'm wondering if your own position
isn't motivated at least in part by a phobia of tools and
techniques you don't understand yourself.
Let me say again, my concern is not that I don't want to see or
learn shell scripting. My concern is that non-programmers who want
to learn appleScript because it's language makes it easy to
understand will come to this list and be overwhelmed with shell
scripting. That's it. And I think that's important.
If AppleScript wasn't such a grossly deficient language, you wouldn't
get nearly as many folk resorting to shell scripting as a workaround
to its inadequacies in the first place. If you have a problem with
this, do something about addressing those deficiencies yourself
rather than complaining about other folks' solutions.
While certain core problems can only be fixed by Apple themselves
(since only they have access to the AppleScript source code), there
is still plenty that folks like yourself could do to rectify/
ameliorate the situation by creating (or paying others to create)
freely available AppleScript-based libraries, C-based osaxen, Python/
ObjC-based scriptable FBAs, documentation and tutorials. Talk is
cheap; why not put your money where your mouth is? It'd be a lot more
productive than complaining.
Thus, the "right" AppleScript solution (using your preferred
choice of regular expression tool) should be something like:
There are plenty of AppleScripters who do not use shell scripting
or regular expressions and have been successfully scripting for years.
Where "successfully" all too often means "driving themselves insane
because they don't know enough to realise when they're doing things
really badly". Been there, done that.
To declare that one solution is "right" is the height of arrogance.
There are good solutions, and there are bad solutions. Promoting bad
solutions is the height of irresponsibility that only serves to
cripple understanding and code.
Also, while your solution works in situations where it's convenient
and permitted to install third-party software on the end user's
macs, that doesn't work for everyone.
Philip Aker already provided a portable solution that addresses that
issue. Nevertheless, you do the best and simplest thing first, and if
subsequent discussion finds it unsuitable, you deal with the problem
then. Anything else is just premature optimisation, a.k.a. the root
of all evil.
Oh, and don't forget your solution simply failed to do what the OP
asked for. I'd say that's a rather more serious problem than some
theoretical concern about mine. This was then followed by a bunch of
hoop-jumping and make-work to fix that bug at further expense to
simplicity and understanding. None of this benefits the OP, which is
what the exercise is meant to be about. Textual pattern matching is a
long-solved problem - i.e. use regular expressions - and the tools
for it are mature, robust and widely understood.
The basics of regexps are not hard to learn either - certainly far
easier than learning the basics of general programming in AppleScript
or any other language. (Like Bill, I learned them from Leonard's
great Regex Commands osax early on in my scripting career and got the
hang in no time.) If you want to avoid regexps for religious reasons
and reinvent the wheel badly on your own time, then that's your foot
to shoot. But don't come around teaching novices to shoot their own
feet as well and then claim you're only looking out for their best
interests.
Here's where I will leave it, if someone asks a question that I can
answer with a plain vanilla AppleScript answer, I will. I encourage
all AppleScripters to do the same thing.
This is fine if the plain vanilla AppleScript answer is as simple as
(or nearly as simple as) the alternatives. Otherwise it's just a self-
indulgent make-work exercise or religious zealotry masquerading as
"helpfulness".
From an off-line conversation:
>>>Are you really that concerned about new applScript users? What
new users? It's a dying language and the world is moving on, get
over it!
For those of us who use AppleScript for application scripting and
find the language easy to understand and easy to work with,
particularly non-programmers who use AppleScript as a second
interface, new users are precious. If this technology is going to
thrive, if it's going to be supported by developers and by Apple,
we need new users and we need to support them and help ease them
into the world of AppleScripting.
How does isolating AppleScript and its community from the larger
scripting world encourage it to thrive? Sounds more like a recipe for
further ghettoization to me - as if AppleScript isn't ghettoized
enough already.
This list could be the best tool for doing that, but it's been
hijacked by shell scripting and is losing it's effectiveness as a
place to help and encourage new users to learn AppleScript.
By all means keep using AppleScript to script applications. But stop
pretending its the right solution for everything else as well because
it's not. No, it's not ideal, but that's the way things are, and
letting newcomers know this isn't done to denigrate the AppleScript
language, it's to empower them as computer users.
"When your only tool is a hammer, every problem looks like a nail."
-- Abraham Maslow
"This is a local shop for local people. There's nothing for you
here." -- Tubbs Tattsyrup
has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
http://appscript.sourceforge.net/objc-appscript.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden