Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
One of the strengths of the telephone directory is that no user manual is required to read and use it; this is because the telephone directory is laid out in a consistent and logical manner. In most U.S. communities, for example, telephone directories have a set of blue pages that contain information about schools and government agencies. These directories always feature a set of white pages that contain residential phone numbers. Phone numbers are sorted by the name of the resident, and are presented in alphabetical order, from A to Z. Telephone directories also contain a set of yellow pages that include business listings, this time ordered by the business category (Hairdressers, Sporting Goods, and so forth). No matter how big the directory, you can find phone numbers with relative ease, because you know exactly where to look for that information. Unlike, say, mystery novels, telephone directories are specifically designed to keep the suspense to a minimum.
To make your scripts easy to read and maintain, consider using a similarly consistent and logical structure. Although scripts vary depending on their nature and complexity, longer scripts might include the following sections:
This section might also be needed to parse command-line arguments and to ensure that the script is running under the proper script host. If necessary, these actions should always occur before the script does anything else. If your script requires three command-line arguments and cannot complete successfully without all three, the script should verify the existence of those arguments before doing anything else. Never carry out half the functions in a script before verifying whether the script can complete successfully.
It is also a good idea to list procedures and functions in the same order in which they are called. This is not required; placing a procedure in one location rather than another does not affect performance. In fact, before a script is run, the script host checks the file and identifies the location of all functions and procedures. As a result, the script host can find each function and procedure regardless of its location in the script, and regardless of the order in which the functions and procedures are called. However, placing procedures strategically makes it much easier for others to read and maintain your script.
Send us your feedback | « Previous | Next » |