Re: Removable Disks (wrapping code)
Re: Removable Disks (wrapping code)
- Subject: Re: Removable Disks (wrapping code)
- From: "John W. Baxter" <email@hidden>
- Date: Tue, 11 Nov 2003 13:45:24 -0800
- Envelope-to: email@hidden
On 11/11/2003 6:21, "Arthur Knapp" <email@hidden> wrote:
>
> From: email@hidden (Christopher Rosado)
>
> Subject: Re: Removable Disks (wrapping code)
>
> Date: Mon, 10 Nov 2003 12:48:30 -0500
>
>
> if month of (current date) is January then set newMonth to "01"
>
> if month of (current date) is February then set newMonth to "02"
>
>
Hi. I'm sure this works fine, but I just wanted to point out that
>
repeatedly calling a scripting addition can be a bit slow. Why not save
>
it to a variable:
>
>
set current_date to current date
>
>
Secondly, you want to use "else if" statements. Consider, if the month
>
happens to be January, then you end up making 11 unnessesary "if"
>
tests, where as this construction:
>
>
set thisMonth to month of current_date
>
>
if ( thisMonth = January ) then
>
set newMonth to "01"
>
else if ( thisMonth = February ) then
>
>
ensures that once you've hit the right month, the other "if" tests
>
aren't performed.
<other stuff omitted>
The CPU is sitting around doing almost nothing...let it make extra calls to
current date. It gets tired of wait loops. ;-)
However, the reason you don't want multiple current date calls, but want to
use a variable set once, is...
Consider just this part:
>
> if month of (current date) is January then set newMonth to "01"
>
> if month of (current date) is February then set newMonth to "02"
>
> ...
Now start the script such that the first call to current date happens at the
very end of December, and the rest of the calls happen in January. There
will be no successful tests, and newMonth will be unset. (There are also
opportunities to use the day and the month from different calls where the
month changed between...if the day is obtained first, you could have
February 31.)
Correct results are always more important than speed, size of code, or
anything else. For a suitable definition of "correct."
--John
_______________________________________________
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.