Functions And Procedures
Functions and Procedures are units of code within the script engine that perform a specified task – they can be referred to as sub-routines. A sub-routine is a mini-program, or sub-program.
These sub-routines are extremely useful as they not only divide script code into readable and manageable chunks, but they can also be easily used multiple times throughout your program.
As these scripts process, entries detailing the processing progress and any errors are written to a Log file. Every script that is run posts entries to a log file, and every time that a single script is run, a Log entry is written.
However, although functions and procedures are very similar, there are subtle differences and the lines between them can be blurred.
Both these sub-routine types can have zero or more parameters of specified data types.
A function will always return a single resulting value, whereas in comparison, any results obtained from the execution of a procedure are either contained in one or more output parameters, or have another purpose such as writing something to the screen or writing to a file.
One other difference is that function calls can be used as a part of an expression, while procedures are complete statements.
As functions and procedures are essentially the same and the differences between them are very limited, throughout this guide the term function will be used liberally to refer to either a function or a procedure.
In short, a Procedure is a piece of code that is called to perform a particular task, and a Function is a piece of code that is called to perform a particular task that will return a value.