Re: AsciiNumber & AsciiCharacter Handlers
Re: AsciiNumber & AsciiCharacter Handlers
- Subject: Re: AsciiNumber & AsciiCharacter Handlers
- From: has <email@hidden>
- Date: Wed, 8 May 2002 20:26:22 +0100
Nigel Garvey wrote:
>
> tell (a reference to text item delimiters)
>
> set {o, contents} to {contents, c}
>
> set {i, contents} to {my kStr256's text item 1's length, o}
>
> end tell
>
>
It's very inefficient code though and the above snippet takes about twice
>
as long to execute as its conventional counterpart.
Another problem [no offence] is that it's almost unintelligible. Compare it to:
set oldTID to applescript's text item delimiters
set applescript's text item delimiters to c
set i to kStr256's text item 1's length
set applescript's text item delimiters to oldTID
This is much more legible [1]. Not just to novices, but also to experienced
scripters and even the original author.
It's easily overlooked, but unless your code is one-off disposable stuff or
something that you know with 100% certainty will _never_ require further
maintenance [2], there's every chance you'll be trying to read this stuff
again at some point in the future. Six months down the line, once you've
forgotten how it all works and have to figure it all out again from
scratch, you're going to be jolly thankful for all that tedious typing,
tidying and commenting you did when you first wrote the thing. (Uh... you
DID remember to tidy and comment your code back then, didn't you...?;)
--
As for the RSI-inducing typing required by a simple TID switch, I find it
well circumvented by keeping the following script in my Scripts [3] menu:
======================================================================
set the clipboard to "set oldTID to applescript's text item delimiters
set applescript's text item delimiters to \"\"
set applescript's text item delimiters to oldTID"
======================================================================
You wouldn't believe how often I use this when coding. I've another one for
timing code that also gets used regularly.
This topic really begs the question as to why all our programming tools
don't come with autocomplete and glossary [4] features as standard. Users
could reduce much of this tedious, repetitious typing down to a couple of
keystrokes if these sorts of features were standard, and tool developers
might make a few bucks from grateful customers in the process.
HTH
has
[1] Though it'd a lot better if meaningful variable names were used instead
of 'c', 'i' and 'kStr256'.
[2] ha! :p
[3] Smile's own script menu in my case, but I'm sure it'd live happily
under any general Scripts menu.
[4] Heck, I'd be mighty tempted to write one for Smile if I could just
find the time...
--
http://www.barple.connectfree.co.uk/ -- The Little Page of Beta AppleScripts
_______________________________________________
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.