Re: How to do a goto with Applescript?
Re: How to do a goto with Applescript?
- Subject: Re: How to do a goto with Applescript?
- From: "Stockly, Ed" <email@hidden>
- Date: Wed, 12 Jan 2011 12:48:29 -0600
- Acceptlanguage: en-US
- Thread-topic: How to do a goto with Applescript?
>>Mark>> If you're just counting, there's no reason not to use i as your loop
control variable,
>>>> Alex>>>OK. Stop right there please.
>>>> Alex>>>Using i, j or k is non descriptive. You do not know what you are
counting. You have to take a split second and analyze the loop and see what it
is. There is no context to what you are counting.
In most cases in AppleScript the context is provided.
Tell page y of document x of application ³Foo²
I find that reads easier and is easier to understand than
Tell page pageIndex of spread documentCount of application ³Foo²
In cases where the context will not be provided or there may be any
confusion, then yes, I would definitely use a more descriptive handler name.
>me> The exception to the previous rule is counters which serve no other
function except as an index within a loop.
>>tom>>I disagree. I see no reason why loop counters shouldn't also be
descriptive. In fact, I especially find it useful within nested loops to know
exactly what each loop is counting, by looking at the name of the counter.
Instead of i, j, k etc, why not describe the actual thing being counted, with
names such as rowNumber, columnNumber, fileNumber, paragraphNumber etc (or use N
instead of Number, eg rowN, columnN, fileN, paragraphN)?
That¹s a good point, and there is no one saying not to do that. (At least
I¹m not saying that).
What sparked this discussion, as far as I am concerned, was the idea that
any use of single character variable labels in any context was a bad habit,
lazy or sloppy programming.
That¹s not the case either in appleScript or in the broader world of
programming. There is an appropriate use for single character variable
names.
That said, Alex was correct that the OP¹s original script was using single
character variable names inappropriately. They were not referencing an
integer in a repeat loop, and that is indeed a bad habit.
>me> If using a single character variable label for integers adds any confusion
a more descriptive term should be used.
>>Tom>>I would take that further and say that not using a more descriptive term
inherently omits information. While not necessarily "adding confusion" it makes
it harder to understand for no good reason.
First, when used properly it does not make the script harder to understand
(see above).
Second, I think I would rephrase that part of the AppleScript style guide to
read:
³In cases where a single character variable label for integers adds any
confusion or its use is not clear, a more descriptive term should be used.
Of course, single character variable labels are never required and some
scripters prefer descriptive variable names for all variables.²
ES
_______________________________________________
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