Introduction to Scripting Languages
Scripting Languages
Scripts are user-readable and user-modifiable programs that perform simpler operations and control the operation of other programs.
They have the following properties:
- Program code is present at run time and the starting point of execution:
- Compilation is not needed.
- Compilation to intermediary languages may be performed behind the scenes as an optimisation.
- Presences of a suitable runtime environment is required for thee execution so scripts:
- Includes one of:
- Interpreter
- Just-In-Time Compiler
- Byte-code Compiler
and a virtual machine.
- Includes one of:
- Execution of scripts is typically slower than the execution of code that has been fully pre-compiled.
- Rich and easy to use interface to the underlying operating system in order to run other programs and communicate with them.
- Rich I/O including:
- Pipes
- Network Sockets
- File I/O
- Rich I/O including:
- Easy integration with larger systems:
- Often used to glue other systems together.
- Can be embedded into other applications.
Language Constructs
- Variables, functions, and methods typically do not require type declarations. Automatic conversion between types:
- Strings and numbers.
- Lots of pre-defined functions and libraries.
- Lots of pre-defined functions for the specific purpose the language was designed for.
- Ability to generate, load, and interpret source code at run time through an
eval
function.-
This can lead to self modifying and running code like the following:
var x = 2; var y = 6; var str = " if ( x > 0) { z = y / x } else { z = -1 }"; console . log ( ' z is ', eval ( str )); // Output : z is 3 x = 0; console . log ( ' z is ', eval ( str )); // Output : z is -1
-
Language Evolution
The evolution of a scripting language typically starts with a limited set of languages constructs for a specific purpose:
- PHP started as a set of functions for tracking web visits.
The language then accumulates more and more language constructs as it is used for a wider range of purposes:
- These additional language constructs may or may not fit well together with the original core and may duplicate existing language constructs.
- During this evolution of the language, backward compatibility may or may not be preserved.
Language design of scripting languages is often sub-optimal.