What are scripting languages?

Scripting languages are a popular family of programming languages that allow frequent tasks to be performed quickly. Early scripting languages were generally used for niche applications – and as “glue languages” for combining existing systems. With the rise of the World Wide Web, a range of scripting languages emerged for use on web servers. Since scripting languages simplify the processing of text, they are ideally suited to the dynamic generation of HTML pages.

Today, according to the TIOBE Index, scripting languages account for around a third of the world’s most frequently used programming languages. JavaScript is virtually the only client-side scripting language that runs in the browser. But the server-side languages PHP, Python, Ruby, and Perl are all scripting languages too.

How do programming and scripting languages differ?

To understand what makes a scripting language, it helps to become familiar with conventional programming languages like C, C++, and Java. In these languages, the programmer writes a source text which is converted to binary code in another step. Two files are used in the process: the source text file that the programmer works in and a subsequent binary file that can be run directly on the computer. A compiler is a special program that acts as a translator between the two files.

The process of converting source text to binary code is called “compilation”. During compilation, the source text is checked for its plausibility: Are all the variables actually defined? Do the types of functional parameters match the functional definitions? Did the programmer forget a character somewhere? This check is performed across the whole source text and can take some time. The binary code generated from the compilation is strongly optimized so that it runs as fast and error-free as possible. Compiled languages are, therefore, particularly suited to computationally intensive tasks and larger systems.

No compilation is required when executing a program written in a scripting language. So, no binary file is generated from the source text written by the programmer. As a result, programs written in scripting languages are usually less efficient. However, this loss of efficiency isn’t merely a disadvantage. It’s a well-considered trade-off: scripting languages relieve the programmer by transferring more of the burden to the processer. For this reason, scripting languages are very useful for small to medium-sized programs.

The core idea of reducing the workload for the programmer can be seen as a running theme throughout the architecture of many scripting languages. For example, they dispense with the need for manual storage management – a particularly efficient, yet error-prone technique. Moreover, in most scripting languages it’s not necessary to enter the type of variable. Since programs written in scripting languages aren’t compiled, there’s also no need for a main() function. Software can be written directly using scripting languages, with less source text. Compare the following examples. Both programs deliver the same results:

// "Hello World" example in Java
class HelloWorld {
    static public void main( String args[] ) {
        System.out.println( "Hello World!" );
# "Hello World" example in Python
print "Hello World!"

Features of scripting languages

As mentioned earlier, scripting language programs are not converted by a compiler into binary code before they are run. Instead of the compiler, a program called an interpreter is used. Conceptually, you can imagine that the interpreter reads the source text from top to bottom and generates and runs the binary code piece by piece.

But if you’re still a little unsure about the terms “source text”, “binary code”, and “interpreter”, take a look at the following analog example: consider the source text as a musical score for an orchestra. In this example, the binary code would be the finished production of the overall piece of music, saved on a CD. The music on the CD can be played back on any CD player, but it can no longer be changed in retrospect. The interpreter is the orchestra that plays the music piece live.

Interactive programming with scripting languages using REPL

In many scripting languages, it’s possible to run the interpreter interactively. This is called REPL mode – short for “read-eval-print-loop”. The programmer hands over the source text to the interpreter, which reads and evaluates the text. The interpreter then feeds back the result (print) and waits for the next entry (loop).

If an error is printed in REPL mode, the programmer can view the content of variables to locate the error. Moreover, it’s possible to overwrite the value of a variable and test the source text with the new value. This allows a program to be created out of smaller, individually tested pieces. Development and bug fixing are rolled into one. This makes it easy to quickly write a functioning program.

Defining complex data structures as literals in scripting languages

Scripting languages aim to reduce the workload for the programmer. To do so, these languages give the programmer a range of tools. They include complex data structures like strings, lists, fields, and objects. They can be written as “literals” in scripting languages. This allows complex data structures to be created directly, instead of having to assemble them with multiple commands. The programmer can express the data structures required more easily, simplifying the process.

// Example of an object lateral in JavaScript
customer = {
    'first name': "Bob",
    'surname': "Jones",
    'age': 40,
    'active': true,
    'addresses': {
        'personal': {},
        'company': {},
# Example of HTML generation using template lateral in JavaScript
page_title = 'What Are Scripting Languages?'
h1 = '<h1>${page_title}</h1>'
# returns "<h1>What Are Scripting Languages?</h1>"

Dynamic typing in scripting languages

In the code examples above, you may have noticed that there were no types like “String”, “int” or “bool” at all. However, the program needs the type of information to run. So where does this information come from?

Scripting languages generally utilize “dynamic typing”. The interpreter determines the type of a variable based on the context. In scripting languages, the type of a variable is also not fixed; it can change depending on the context. An example:

# Example of dynamic typing in Python
# A name displayed as a list of first name, surname
name = ['Alice', 'Smith']
# The type of the variable “name” is “list”
# We only need the first name in the following
name = name[0]
# The type of the variable “name” is now “str”

Use of scripting languages

Scripting languages are categorized according to use and area of application. Some scripting languages are used in the command line to condense sequences of commands. They help automate the process in this way. These languages include Bash and PowerShell.

VBA and AppleScript perform a similar function. Processes can be automated at the application level with these languages.

PHP, Perl, Ruby, Python, and JavaScript are used on web servers to implement dynamic websites and web applications. JavaScript is also the only scripting language to run in the web browser. Although it was originally only intended for programming interactive elements, nowadays, entire web applications are written in JavaScript.

Scripting languages are also prevalent in statistics and research. Here, the languages R and Python are primarily used.

We use cookies on our website to provide you with the best possible user experience. By continuing to use our website or services, you agree to their use. More Information.
Page top