Re: Scripting Style (was: Re: Hiding Slaves)
Re: Scripting Style (was: Re: Hiding Slaves)
- Subject: Re: Scripting Style (was: Re: Hiding Slaves)
- From: "Arthur J. Knapp" <email@hidden>
- Date: Mon, 16 Sep 2002 12:00:11 -0400
>
Date: Sat, 14 Sep 2002 15:24:58 +0100
>
From: has <email@hidden>
>
Subject: Re: Scripting Style (was: Re: Hiding Slaves)
>
Paul Berkowitz wrote:
>
> [...] it's more a matter of personal taste: some
>
> people prefer to it it the "textbook" way 'as string'.
>
Being a thoroughly uncharitable and unkind sort, I'd tend to attribute it
>
not to "taste" but to faddishness, cargo cult, cleverness for its own sake,
>
deliberate obfuscation, L33Tness, etc. [1]
No, that isn't fair. (And please stop having interesting discussions over
the weekend when I can't participate). ;-)
>
'As string' is entirely unambiguous, dirt simple to read and understand.
"" & variable
is also entirely unambiguous, dirt simple to read and understand, to anyone
but the newest newbie, (and lets face it, if all AppleScript code was
written to only be understood by the newest of newbies, we would never
get anywhere.) One only has to learn once how the concatenation operator
works, (with the class of it's leftmost operand controlling what kind of
concatenation is occuring), to both understand and to remember the empty
string "trick".
>
That empty string concatenation is not (as Ken's post has just
>
demonstrated). It's just bad programming. [2]
To me, it's learning how to use an operator with a deep understanding
of it's function, which is very good programming.
In AppleScript, the overloaded nature of the concatenation operator almost
compels one to use left-side implicit coercion. Once you come to understand
how the class of the leftmost operand affects concatenation, it becomes
entirely natural to use:
"" & leftVar & rightVar
It feels even more natural when you have many values to stringify:
set i to 3.14159
set j to " Hello"
set k to " World "
set l to boolean
-- i itself will cause the & operator to create a list
--
i & j & k & l --> {3.14159, " Hello", " World ", boolean}
-- We can use "as string", but this looks and "feels"
-- inefficient, as AppleScript is first creating a list:
--
(i & j & k & l) as string
--
-- from:
-- {3.14159, " Hello", " World ", boolean}
-- to:
--> "3.14159 Hello World boolean"
-- This is a more pedantic approch, explicitly coerce all
-- non-strings to string:
--
(i as string) & j & k & (l as string)
-- But I would think that overall clarity for almost anyone
-- but the absolute newest newbie, this is the most natural
-- and convenient:
--
"" & i & j & j & l
Look, concatenation is the most simply and basic of all things
one can do in AppleScript. Intimately learning how the operator
works is an essential first step in moving from newbie to
mastery.
>
> property u : ("" as Unicode text)
>
>
>
> set hidFolderPath to ((u & (path to scripts folder)) & ".hid")
>
First person to do this, I kill just on General Principles.
Why? I'm not quite clear on what the General Principles are.
>
[1] No doubt endearing myself even less to those folk who use it... But
>
diplomacy never was my strong point...
Typically, I don't use it except for coercing multiple non-string items
together. As some have pointed out, there is the slightest speed to be
gained, (and I'm a sucker for speed), but as a syntactic technique, it is
no more difficult to learn, use, and remember than working with the text
item delimiters, considering/ignoring statements, etc.
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
a r t h u r @ s t e l l a r v i s i o n s . c o m
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.