How to structure your scripts

Best practice for creating scripts is that all of the scripts must be structured in the same way to enhance readability and facilitate troubleshooting. This section describes structuring methods that you should follow when creating a script.

Comment block

Every script starts with a comment block that contains the following:

  • Name of the creator
  • Creation date
  • Name of the script
  • Short description of the scripting function
  • Intended use, if the script is intended as a script component, in effect as a command
  • Description of pecularities, if something is unusual about the script

Parameters block

The following requirements apply for a parameters block:

  • The second block in the recommended structure is the parameter block.
  • Parameters are the data, passed to the script in the job call, needed for the script to function.
  • Parameters must be declared. When parameters are declared, it becomes clear for the reader what is needed to make the script work. Also, in case of troubleshooting you can easily find an error by comparing the list of passed parameters to the list of needed parameters.
  • Use descriptive names for the parameters.
  • Use comment when you suspect something might not be clear.
  • The use of capitals in parameter names is not prescribed in the Core scripting language, but capitalization must be consistent.

Constant block

  • A parameter block is followed by a constants block.
  • A constant is declared and initialized at the same time, after which its value is fixed.
  • Constants can be initialized with the value of a parameter or a variable.

Example

Const Text copiedfilename = destparameter["c:\temp",];
/* The constant copiedfilename is initialized with the path/filename as stored in the destparameter. */

Const Number numberofcopies = Var1 + Var2;
/* The total of two Variable values is stored in a constant. */

Variable block

The constant block is followed by the variable declaration block. Variables are entities that can contain values. Variables are typed: Text, Number, or Boolean. Variables are used to give meaningful names to values changed in the script.

Script body

After the parameters, the constants, and the variables are declared, you can add the body of the script. This body consists of a list of commands and control statements. As all parameters, constants, and variables now have meaningful names, this part of the script should be easy to create and maintain.

Indentation

You can use indentation to show that parameters belong to a command.

Example

Copy
   Src(source_file)
   Dest(copied_file)
   TimeOut(waittime);

In this example, source_file, copied_file, and waittime are either parameters, variables, or constants defined or declared at the beginning of the script.