DekGenius.com
[ Team LiB ] Previous Section Next Section

6.4 Abbreviations and Synonyms

Many AppleScript terms permit other terms to be substituted for them. For example, the following expressions are equivalent in pairs, assuming a and b are defined:

a is less than b
a < b

a is b
a = b

Some terms have a very large number of equivalents. For example, these expressions amount to the same thing:

a  b
a <= b
a less than or equal b
a is less than or equal to b
a is not greater than b
a isn't greater than b
a does not come after b
a doesn't come after b

To add to the confusion, on decompilation, AppleScript might substitute one equivalent for another (see Section 4.4.2). So the code in the previous example compiles, but afterwards it looks like this:

a  b
a  b
a is less than or equal to b
a is less than or equal to b
a is not greater than b
a is not greater than b
a does not come after b
a does not come after b

I call terms that are functionally equivalent to one another synonyms. I call terms that are replaced by other terms on decompilation abbreviations.

Code in this book is compiled before being pasted into the page, so you won't see any abbreviations in the book's code examples (except, as here, with the explicit purpose of displaying an abbreviation). In fact, this book does not even list abbreviations except where I find them particularly handy when typing code. For example, I habitually type less-than-or-equal as <= even though in the compiled code what will appear is , so I tell you about this abbreviation (under Section 15.3).

I don't tell you about all synonyms either, and on the whole I try not to use them. I feel that it's good style, and makes your AppleScript code more legible, to adopt just one synonym for each term and stick with it. In general my personal preference is the shortest synonym, but not always; for example, of the following two expressions, I prefer the second:

a  b
a is not b

And in a very small number of cases I do use two synonyms indiscriminately. For example, I'm equally likely to use either of these expressions:

a = b
a is b

To sum up: wherever there are synonyms, I have a favorite (or, in a very small number of cases, a couple of favorites). My favorites are the versions of each term that I tell you about, and they are the ones I use in code.

    [ Team LiB ] Previous Section Next Section