Scripting languages are a popular family of pro­gram­ming languages that allow frequent tasks to be performed quickly. Early scripting languages were generally used for niche ap­pli­ca­tions – 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 pro­cess­ing of text, they are ideally suited to the dynamic gen­er­a­tion of HTML pages.

Today, according to the TIOBE Index, scripting languages account for around a third of the world’s most fre­quent­ly used pro­gram­ming 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 pro­gram­ming and scripting languages differ?

To un­der­stand what makes a scripting language, it helps to become familiar with con­ven­tion­al pro­gram­ming languages like C, C++, and Java. In these languages, the pro­gram­mer 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 pro­gram­mer works in and a sub­se­quent binary file that can be run directly on the computer. A compiler is a special program that acts as a trans­la­tor between the two files.

The process of con­vert­ing source text to binary code is called “com­pi­la­tion”. During com­pi­la­tion, the source text is checked for its plau­si­bil­i­ty: Are all the variables actually defined? Do the types of func­tion­al pa­ra­me­ters match the func­tion­al de­f­i­n­i­tions? Did the pro­gram­mer forget a character somewhere? This check is performed across the whole source text and can take some time. The binary code generated from the com­pi­la­tion is strongly optimized so that it runs as fast and error-free as possible. Compiled languages are, therefore, par­tic­u­lar­ly suited to com­pu­ta­tion­al­ly intensive tasks and larger systems.

No com­pi­la­tion is required when executing a program written in a scripting language. So, no binary file is generated from the source text written by the pro­gram­mer. As a result, programs written in scripting languages are usually less efficient. However, this loss of ef­fi­cien­cy isn’t merely a dis­ad­van­tage. It’s a well-con­sid­ered trade-off: scripting languages relieve the pro­gram­mer by trans­fer­ring 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 pro­gram­mer can be seen as a running theme through­out the ar­chi­tec­ture of many scripting languages. For example, they dispense with the need for manual storage man­age­ment – a par­tic­u­lar­ly 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 in­ter­preter is used. Con­cep­tu­al­ly, you can imagine that the in­ter­preter 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 “in­ter­preter”, 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 pro­duc­tion 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 ret­ro­spect. The in­ter­preter is the orchestra that plays the music piece live.

In­ter­ac­tive pro­gram­ming with scripting languages using REPL

In many scripting languages, it’s possible to run the in­ter­preter in­ter­ac­tive­ly. This is called REPL mode – short for “read-eval-print-loop”. The pro­gram­mer hands over the source text to the in­ter­preter, which reads and evaluates the text. The in­ter­preter then feeds back the result (print) and waits for the next entry (loop).

If an error is printed in REPL mode, the pro­gram­mer 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, in­di­vid­u­al­ly tested pieces. De­vel­op­ment and bug fixing are rolled into one. This makes it easy to quickly write a func­tion­ing program.

Defining complex data struc­tures as literals in scripting languages

Scripting languages aim to reduce the workload for the pro­gram­mer. To do so, these languages give the pro­gram­mer a range of tools. They include complex data struc­tures like strings, lists, fields, and objects. They can be written as “literals” in scripting languages. This allows complex data struc­tures to be created directly, instead of having to assemble them with multiple commands. The pro­gram­mer can express the data struc­tures required more easily, sim­pli­fy­ing 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 in­for­ma­tion to run. So where does this in­for­ma­tion come from?

Scripting languages generally utilize “dynamic typing”. The in­ter­preter de­ter­mines 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”
type(name)
# We only need the first name in the following
name = name[0]
# The type of the variable “name” is now “str”
type(name)

Use of scripting languages

Scripting languages are cat­e­go­rized according to use and area of ap­pli­ca­tion. 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 Pow­er­Shell.

VBA and Ap­ple­Script perform a similar function. Processes can be automated at the ap­pli­ca­tion level with these languages.

PHP, Perl, Ruby, Python, and JavaScript are used on web servers to implement dynamic websites and web ap­pli­ca­tions. JavaScript is also the only scripting language to run in the web browser. Although it was orig­i­nal­ly only intended for pro­gram­ming in­ter­ac­tive elements, nowadays, entire web ap­pli­ca­tions are written in JavaScript.

Scripting languages are also prevalent in sta­tis­tics and research. Here, the languages R and Python are primarily used.

Go to Main Menu