• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scripting Style (was: Re: Hiding Slaves)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting Style (was: Re: Hiding Slaves)


  • Subject: Re: Scripting Style (was: Re: Hiding Slaves)
  • From: Paul Berkowitz <email@hidden>
  • Date: Fri, 13 Sep 2002 20:48:27 -0700

On 9/13/02 8:13 PM, "Ken Scott" <email@hidden> wrote:

> I have a question about the script snippet that you posted above. Why do you
> prepend the empty string to the (path to scripts folder)? Does this force an
> alias to become a string, or something like that? Is this more efficient
> than saying (path to scripts folder) as string?
>
> I'm a new scripter, and learning by example.

John doesn't like typing, so he uses the implicit coercion to coerce lists,
aliases and anything else that will coerce to string by the ("" & ):
whatever is on the right-hand side of the concatenation operator will coerce
to what's on the left-hand side if it can. (And John will only use it where
it can.)

Once upon a time, back in OS 7 and 8, this was also faster. Speed freaks did
a lot of testing while John was away, and proved conclusively that 'as
string' explicit coercion is actually faster in OS 9 and X (I can't recall
the exact change-point). (Nigel tried to tell John this the day he came back
to the list, but I noticed he wasn't too interested.) Unless you're doing it
10,000 times or so in a repeat loop, you won't notice the difference in
speed one way or the other, so it's more a matter of personal taste: some
people prefer to it it the "textbook" way 'as string'. Any you never know if
a coercion will one day start behaving oddly, but this one never has. It
works fine


Actually in that particular snippet, there's even another infinitesimal
improvement in speed in writing out

path to scripts folder as string

since here 'as string' not a coercion at all but an actual parameter of the
'path to' addition. But again, you'd never notice.


However, John in particular is going to have to stop doing it any day now
(he likes using Unicode). 'as Unicode text' has no such shorthand coercion,
unless you happen to have captured a sample of an empty Unicode string and
give it a variable. John could actually start all his scripts:

property u : ("" as Unicode text)

---
set hidFolderPath to ((u & (path to scripts folder)) & ".hid")


(It works). But most of time it doesn't help much: when you're concatenating
strings on to the end, you still have to out the whole thing into Unicode
with an 'as Unicode text' when you're done. At least you used to, or you
could get a missed byte, I was once told. Maybe it's all behaving nicely in
AS 1.9. I've just tried a few 'u' coercions, and they seem to work. I'm not
prepared to take the risk myself, however.

Chris? How are Unicode and string concatenations behaving now, with Unicode
on the left?

--
Paul Berkowitz
_______________________________________________
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.

References: 
 >Scripting Style (was: Re: Hiding Slaves) (From: Ken Scott <email@hidden>)

  • Prev by Date: Scripting Style (was: Re: Hiding Slaves)
  • Next by Date: Re: Sorting? [sorted]
  • Previous by thread: Scripting Style (was: Re: Hiding Slaves)
  • Next by thread: Translating Quoted Printable
  • Index(es):
    • Date
    • Thread