Re: Scripting Style (was: Re: Hiding Slaves)
Re: Scripting Style (was: Re: Hiding Slaves)
- Subject: Re: Scripting Style (was: Re: Hiding Slaves)
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 14 Sep 2002 20:43:39 -0700
On 9/14/02 8:01 PM, "Michael Sullivan" <email@hidden> wrote:
>
When there are two ways of programming something and one is more clear,
>
always prefer the one that is more clear, unless there is a specific
>
advantage to using the less clear version. Back when appending
>
something to the empty string was faster than an explicit coercion, this
>
wasn't necessarily bad programming. Now that there it's actually
>
*slower*, it is, since it reduces clarity to no other advantage.
>
>
That said, it's a fairly minor point, as most folks on seeing that code,
>
will understand what it is doing, and what it is supposed to produce,
>
even if the implicit coercion is not obvious to them.
I notice that some of the people I most respect on this list have managed
not to catch my tone of voice at all. In the course of explaining to the
person who was seeing the ("" & ) coercion for the first time what it did, I
said more than once that I used 'as string' myself, that 'as string' was
clearer, and that it's now faster too. I agreed that the ("" & ) could be
seen as obfuscating. The one and only claim I made for was it that it saved
typing: if you don't see that as a very gentle put-down of those who
continue to use it, you miss a lot. (And if you think about for a moment, it
doesn't even save much typing.) My 'u for Unicode' suggestion was obviously
tongue-in-cheek. Not obvious? OK, so I'm telling you now: it was meant to be
tongue-in-cheek.
So what is eliciting all these portentous disquisitions? Merely the fact
that I was light-hearted about it instead of being heavy-handed, and that I
was willing to grant that it might be OK to use ("" & ). It's really, really
NOT a big deal, you know. Implicit coercions are permitted and even
encouraged by the ASLG. That's why they built them into the concatenation
operator. People who want always to use the best and the clearest methods
will not use it. **I don't use it myself**, although I do occasionally baulk
at:
set AppleScript's text item delimiters to {" "}
"Some string here anyway; " & ({"and", "a", "list", "here."} as string)
when
set AppleScript's text item delimiters to {" "}
"Some string here anyway; " & {"and", "a", "list", "here."}
works perfectly, as it was designed to do. Have you really, really never
done this?
And, as far as AppleScript is concerned, that's absolutely the same thing as
set AppleScript's text item delimiters to {" "}
"" & {"Some", "string", "here", "anyway;", "and", "a", "list",
"here."}
No difference at all, except to human readers who have never seen it before
and for whom it might in fact be an excellent pedagogic example and spur to
learn about the concatenation operator.
And - it's 1/10,000th of a second or so slower. Mustn't forget that.
We are using a forgiving language here. I happen also to like the "best"
way, even when there's next to no practical reason for using it. But I
really don't mind if some people exercise their personal preference to use
the other way - there's really no need to be so prescriptive. It works, and
there's no danger involved. It's probably just a habit dating from the time
when it actually was faster and therefore justified using an obscure bit of
code for those who enjoy such things. A bit dated now, but not worth all
this fuss.
--
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.