Introduction to Scripting Language
In the world today, there exist so many programming languages. In fact, the total number is not clear, but we have an estimate of over 1000 plus languages in existence. And no doubt more and more of these languages are being developed. Why so many languages? The reason is, needs arise — as a result of new challenges that the existing languages can not solve or can not solve better. And so, the scientists decide to implement a language with a well-defined purpose. However, other languages were designed for the fun of it or with the idea or goal of challenging a language’s design decisions already in existence.
As it turns out, depending on what the software programmer wants to achieve, there exist options of languages to choose from. For instance, if automation is the problem, a script would be suitable, using a scripting language that is interpreted by a special runtime environment to execute the task(s); and just in case a system needed to be developed, then one would opt for a system based programming language like C or C++ for instance, that comes with a whole lot of advantages, one being faster runtime execution.
Are scripting languages, programming languages?
A common statement amongst computer scientists states that all scripting languages are nothing more or less. Still, programming languages, but not all programming languages, should be considered as scripting languages. Well, that statement holds because not all programming languages are interpreted. But why should we say that they are all programming languages? The main answer to this question boils down to the definition of what a programming language is.
An intuitive definition would be: A programming language is a well-defined set of instructions fed to a computer, commanding it to do something. What really separates the programming languages is the nature of their execution. To elaborate on this, scripts or scripting languages often will require a special runtime environment to execute. In contrast, the rest of the programming languages will require an assembly or a compiler to execute.
I don’t like the direction I want to take because I believe it will confuse confusion. But worry not, because the more you keep on consuming the rest of the article, you will only get to understand in detail all there is to explain. The point is, system-based programming languages can also be considered scripting languages. For instance, Java, C++, or Perl. All based on where they are being executed from and the purpose they serve. To put this into a clear perspective, if any of those languages are used to develop scripts, a prevalent thing on the server-side, they will definitely be considered scripting language. A good example is the use of C++ to develop CGI (Common Gateway Interface) scripts that automate tasks on the server-side.
Interpreted versus compiled languages
Based on the mode of execution, programming languages can be classified as either interpreted or compiled. Scripting languages fall under the category of interpreted languages, while most of the system languages are compiled. The difference between interpreted and compiled languages is that interpreted languages run through an interpreter program or tool that interprets line by line of instructions into machine code while doing the execution right away. On the other hand, compiled languages are manually converted to machine code in their entirety before the execution takes place.
Does that sound confusing? Bless me! Because I have an analogy that intuitively delivers the explanation that can be understood by a one-year-old baby! This is the analogy; let’s assume you have visited a strange country, yes strange, and you are definitely a stranger, and all you meet are too. You need communication, for reasons of wanting to get work done. So you pick an individual who understands both your language and that of the natives. This person definitely becomes an interpreter. The dude’s main task is to translate line by line of every sentence said by you to the natives, hence facilitating communication. To refer back to our discussion topic, consider the dude to be the computer interpreter, your strange language as the scripting language, and the native language as the machine code. Sounds cool, yah?
Enough of the interpreted languages. Suppose you got an interesting novel you needed badly to read during the holiday on the beach. Unfortunately, it was written in a language from Mars. And so you had to ask the alien(s) who understood your tongue to compile a copy in your tongue. Since it beats logic to compile it line by line, the alien does a compilation of the whole book and sends a copy to you. Making life easy on your side. This is what computer compilers do; they convert the whole source code to be precise into machine code.
With a keen look at the mode of execution of interpreted versus compiled languages, it is pretty clear that error(s) caught in a compiled language are summed up and presented at the end of the compilation. On the contrary, with interpreted languages, since execution takes place line by line, in tandem with the interpretation, error(s) are flagged while the interpretation is ongoing. In fact, an occurrence of an error stops the interpretation right there. So it has to be corrected — a process commonly referred to as debugging in the savvy world, and the whole process instantiated once more.
Still, on the code, scripting languages do not have a definite entry point. On the contrary, the majority of compiled languages, if not all, have a definite entry point, without which they will not compile, live alone to execute. These major differences in terms of execution mode make compiled languages faster in terms of execution speed. Lacking an entry point on the side of the interpreted languages serves to make them flexible because even a single line can successfully execute. This dynamic nature makes scripting languages suitable for executing simple tasks.
Interpreter vs compiler
One might wonder what an interpreter or compiler is. These are the tools or programs that convert human-readable code into machine code that the metal can execute (the processor). Computers can not read human languages — commonly referred to as high-level languages; so need to convert them to machine code by using the interpreter or the compiler. Machine code is nothing short of binary code—a computer language of zeros and ones. Everything in a high-level language has to be converted to zeros and ones to make the dump computer brain (the processor) understand all it is being asked to do.
Examples of scripting languages:
There exist several scripting languages. Examples include python, perl, lua, bash, javascript, to mention but a few. When do you choose one over the other? Before making considerations, one has to really understand the nature of the problem at hand. If the task requires advanced programming structures and probably the flexibility of dynamic typing, not to forget an object-oriented programming language, then python programming language would be the choice. Another option that could be used is PHP; it has features that almost correlate to python.
If the task required short scripts with well-defined end-goals, then a scripting language like Bash would be a perfect choice. Bash does not come with advanced programming structures. The programs, too, are not that complex but very brief and straight to the point. We can use bash to automate administrative tasks that require one to issue command after the other on the shell.
Another task that would need a scripting language is automating embedded systems. In that case, a light-weight scripting option would be cool. A good choice here would be Lua scripting language. It is not only light-weight but is object-oriented and very dynamic.
I will not forget to mention one of the core functionalities of scripting languages. That is parsing text documents or streams of data. You might be wondering what’s the best option for this. Yes, most of the scripting languages already mentioned have the capability of handling this task. But the option that beats the rest hands-down is the Perl programming language. Perl is used to writing straightforward scripts. It also supports an object-oriented programming paradigm, just in case you needed it for your program design.
Moreover, it is vital to note that some of the scripting languages are operating system dependent; for instance, Powershell scripting is only applicable to windows operating systems. Bash scripts will run on Unix or Linux based environments, although there have been massive advancements recently, to ensure that bash scripts run seamlessly on the Windows platform. The majority of the scripting languages are system independent.
To note is that most of the shell-based languages, and the command-line interface (CLI) based languages, are scripting languages. All of them need a specialized runtime interpreter environment to execute. Additionally, we have existing programming languages that can fall on either side of the divide. Python, for instance, can be considered as both a compiled and interpreted language. It all depends on how you are putting it to use. Taking you back to the introductory section, we mentioned that system-based languages could also serve as scripting languages.
Server-side versus client-side scripting languages
We can comfortably group scripting languages into two, as either server-side scripting languages or client-side scripting languages. What is the distinguishing feature between the two categories? Server-side scripting languages are known to run scripts on the server(can mean many things, the bare metal hosting the server application(s). Conversely, it can mean the server application, for instance, Apache or Nginx). These are scripts that connect the server to the database and the client. The server-side scripting idea ensures that the source code on the server-side is totally obscured or abstracted from the client side—that way, securing the content and operations on the server-side. Clearly, then, the client-side never gets to know what is taking place on the server-side.
As the name aptly suggests, the server-side serves content in code or data to the client-side. Most of the data is generated from the database. Alternatively, data can be generated from the API endpoints. Ability to generate code from the server-side ensured for a dynamic client-side. All these are made possible by the use of server-side scripting languages. Examples of the scripting languages tailored towards fulfilling these functionalities include but are not limited to PHP, javascript, python, Ruby, C#, node.js, and et cetera.
Conversely, client-side scripting language renders served content from the server-side to the client or end-user. Unlike server-side scripting, the client-side runs exclusively in the browser. The user can view the source code on the client side. Apart from content rendering, the client-side has been improved massively; for instance, it can handle user input validation – especially from inputs. A feature that was handled by the server-side only back then. The client-side too comes with one major advantage; it reduces the load on the server-side. Meaning, we no longer have a scenario where most if not all code is generated from the server. This improvement makes the client-side load faster than never before and optimizes the server side’s performance. In general, the end-user experiences improved performance, which most of them take for granted.
Client-side has several scripting languages that power it. They include javascript, HTML, and CSS. JavaScript is considered to be the glue language. It provides interactivity too. HTML is a markup language. It does enforce the structural aspect of the client-side content delivery by organizing content onto headers, body, all the way to the footer. It does provide for pagination and so on. CSS, on the other hand, is a styling language. Without it, we will miss the attractive look and feel of the client-side. That is not all; the client-side, through scripting, can communicate to the server by sending client requests. The communication is made possible by the use of HTTP methods.
Application of scripting languages
Scripts or rather scripting languages are used mostly in task automation. An awesome example of task automation is scraping and cleaning data from different websites. A scripting language like python or javascript can be used for this task.
In case of administrative tasks, like checking for updates, running updates and upgrades, managing networking devices, and so on, bash scripts or even Powershell scripts can be used. Other administrative tasks might include cleaning trash, creating users, and starting and stopping programs.
The use of the scripting languages can also glue applications running separately. That is, the output of one application can be channeled as input for the next application. For instance, a database can be connected to the client-side via a scripting language; embedded systems can also be linked using the scripts.
Advantages of scripting languages
Scripting languages tend to be easy to learn and use compared to system based languages. Shell script languages, for instance, are not complex with lots of programming structures. They are very straightforward to understand and use.
Additionally, scripting languages come with flexibility since most of them are dynamically typed and do not have an entry point file. A terminal can easily be fired up and the script executed line by line with short and easy to use commands.
Demerits of scripting languages
One disadvantage of scripting languages is they take a lot of time to execute compared to compiled languages. This is because of the interpreter’s overhead time while running through line by line of instructions, during code conversion from user-friendly source code to machine code.
Looking at its counterpart, compiled code takes a shorter time during compilation since there is no overhead time taken. The only downside is that most, if not all, need an entry point to compile and execute.
Conclusion
I want to believe that you have had an overview and understanding of what a scripting language is and how it differs from the rest of the system-based programming languages. Above all, after taking your time, I hope, too, you will be able to make the right choices when faced with problems that require you to develop scripts now and into the future. Much has been covered besides differentiation. For instance, a discussion that clearly but briefly explains what client-side and server-side scripting is.
We have had scenarios that could sound so confusing; for instance, on the server-side, most of the system-based languages have turned out to be scripting languages — all boiling down to the purpose they serve on the server-side. Without fear of contradiction, we could see comfortable say that any language used to write scripts is a scripting language. On the other hand, as discussed before, we can note that there are specially designed languages for scripting; whose examples and usage are briefly detailed below. Till the next article, I hope this leaves you a happy and hungry reader!
Also read What Is A Scripting Language?