Design a network script and select an appropriate script language Contents:
Design a network script and select an appropriate script language 1
Contents: 1
What is scripting? 2
Types of scripting activity 4
Programming languages for scripting 5
Script language features 7
Choosing a scripting language 8
Installing a script language 10
Using an IDE 10
Summary 11
What is scripting?
We can divide programming into three broad types
-
systems programming
-
applications programming
-
scripting
Systems programming is concerned with writing programs that form the core of an operating system (for example Microsoft Windows or Linux).
Applications programming is concerned with writing specific applications to run on the computer, including for example word processors, spreadsheets, databases, financial programs and so on.
Scripting programs control or coordinate the resources of the operating system and applications programs to carry out some particular task. Some of the things that are done with scripting include
-
repetitive housekeeping tasks such as backups or installations
-
configuration of user environments with login scripts
-
gathering information and reporting.
The comparisons below help define the nature of scripting. Note however that programming is more like a continuum, and the distinctions between scripting, application programming and systems programming are fuzzy. Today you can find whole applications built using typical ‘scripting’ languages like PERL or Python.
|
Systems programming
|
Applications programming
|
Scripting
|
Logical level
|
low level—you need to know the details of computer hardware in order to do systems programming
|
higher level, because it is protected from the details of specific hardware by the operating system. To write portable applications, you need to have a good understanding of the services provided by the operating system.
|
the highest level, and usually employs the operating system and/or other applications to get the job done.
|
Complexity
|
the most difficult type of programming, involving complex hardware, complex algorithms, and complex processes like concurrency.
|
may use complex algorithms, but are protected from many complex issues by the operating system.
|
the simplest type of programming
|
Time
|
takes a long time to develop because operating systems are very large, and great care must be taken to ensure that there are no errors.
|
take less time because they are smaller and less critical.
|
Scripts take the least time to develop. Many scripts are quite small, and some scripts may only contain a few lines of code. Even for large projects. scripting is often faster because of the high-level nature of the scripting language features. Scripting is often used where rapid or continuous development is required due to changing requirements, or when building a prototype or proof of concept.
|
Criticality
|
highly critical, because errors in operating systems code can affect the security and stability of the entire computer system.
|
The effects of errors are usually limited to the application itself, though the application may be quite important (eg a database management system)
|
more specific and less critical.
|
Users
|
developed by specialist software engineers for other users.
|
developed by specialist software engineers for other users.
|
typically developed by the users: people will often use scripts to help them with their own day-to-day work
| Scripts are often shared openly
Another interesting difference between scripting and other programming is that scripts are often shared openly. The open-source environment that has promoted the development of scripting languages also promotes the distribution and re-use of individual scripts, or of more extensive code packages. You can usually find a script to do what you want, or something close to what you want.
Types of scripting activity
There are a few different types of programming that are given the name ‘scripting’.
Web Scripting
Script code embedded in web pages is commonly used to add interactivity and enhance the user interface, such as forms, rollovers, menus, or navigation trees. These types of scripting languages are called client-side scripting languages, because they run within the browser. By contrast, server-side scripts run on a web server, and can provide access to information stored in databases or other files in a corporate computer system. Languages commonly used for client side web scripting include Javascript and PHP. Server-side scripting languages include Microsoft ASP programs, PERL, Python.
Application scripting
Many application programs these days come complete with scripting languages. This allows the advanced user to develop functions that are not provided by the base application. For example the Microsoft Office word processor, spreadsheet and database applications can be scripted using Microsoft Visual Basic for Applications (VBA).
System Administration Scripting
This was the earliest type of scripting, and is the focus of this module. This type of scripting is about easing the burden of systems and network administration by automating repetitive tasks with purpose-built scripts. Popular systems scripting languages include Python and PERL.
Rapid Application Development
It is becoming more common for complete applications to be developed in scripting languages, because the high logical level and advanced language features allows the programmer to get the job done more quickly. After an initial development phase, all or part of the program may be re-written in a compiled language to optimise performance. This step may not be required, given the high speed of modern computers.
Languages for different purposes
Systems programming languages need to be able to address the hardware directly; need to execute as fast as possible; and need low-level operations such as bit operations or specific machine language instructions. These languages are compiled high-level languages such as C and C++. Assembly language is still used very occasionally where direct, detailed control of the hardware is required.
Applications programming languages need to be expressive enough to solve many types of problems, but efficiency is usually still a major consideration. These languages are today compiled, object-oriented languages. Examples of common applications programming languages include C++, Microsoft C#, Borland Delphi, Microsoft Visual Basic, and Java.
Scripting languages tend to place more emphasis on maximum expressiveness and ‘power’, and are less concerned with efficiency. These languages are object-oriented and contain powerful features built-in, such as regular expressions, advanced data structures, dynamic memory management, and functional programming features. Scripting languages are usually interpreted. Examples are Python, Perl, Ruby, and Smalltalk.
Interpreted versus compiled languages Compilers produce machine-executable code
A compiler converts the high-level language source code (stored in a text file) into machine code or executable code. The machine code is stored in a binary file that can be executed directly by a specific CPU. Once an executable file has been generated, the operating system can load and execute the file. No additional software is required as the instructions are already in a format that the machine can interpret.
Compiled code is only executable on a particular type of hardware. For example, if the machine code is targeted for Intel 80x86 series CPUs, it will not run on a Power PC or any other type of CPU—it would need to be re-compiled using a compiler that outputs code for the other type of hardware.
Most executable code makes use of operating system services, so will only work on one type of operating system. You will have noticed this if you download programs: you usually have a choice of different versions of the program depending upon the operating system (Windows and Linux for example), or even operating system versions (Windows 98 versus Windows 2000).
A graphical representation of how programs are compiled can be found by typing compile into the search box for Webopaedia at www.webopaedia.com
Interpreters execute source code directly
As implied by its name, an interpreter reads the high-level instructions in the text file that humans can understand and interprets (in effect, executes) them on the target computer.
The interpreter reads the instructions contained in the source code file and carries out the operations that are specified. So the interpreter acts like a ‘virtual machine’ that executes the high-level language code. So there is a hierarchy of software—the interpreter sits between the hardware and the source code, carrying out instructions ‘on the fly’.
This means that any computer executing an interpreted program must have the interpreter installed.
Comparative advantages of compilation and interpretation
In theory, any compiled language can be interpreted and vice versa. However, some features are easier to handle in interpreted languages. Generally speaking, interpreted languages are more flexible because the interpreter can make decisions at run-time. This allows features like dynamic typing to be easily implemented.
Interpreted programs run more slowly than compiled programs, so most commercial off-the-shelf software is provided as an executable (a compiled program). However during development interpreters have an advantage, because running code directly on an interpreter is faster than the compiling, linking, and running.
Interpreted code is generally more portable than compiled code. This is largely because the interpreter deals with hardware-dependent and operating system-dependent code, rather than the developer having to produce different versions of code to suit various platforms. Of course, a separate version of the interpreter must be made for each platform.
Scripting languages are normally interpreted
With scripting, the speed of execution is less important than the ease and speed of development, enabled by advanced language features. Scripting languages enable sophisticated programs to be woven together with minimum effort. Thus languages used for scripting are usually interpreted.
Some languages try to achieve the best of both worlds by first compiling to an intermediate, compact form called ‘byte code’. Later this byte code is interpreted by a relatively simple, fast interpreter. These languages have good speed, are highly portable and are increasingly popular. Examples are Java, Python, and PERL.
Script language features
Advanced data types such as lists, dictionaries and sets are built in to the language.
-
High-level functionality for text and file manipulation. If you need to process text, regular expressions should either be built into the language or available as a standard library module.
-
Easy integration into Web pages and Web applications. Web browsers that process and display web pages are designed to deal with most scripting languages. The basic language used to construct pages for the World Wide Web, the HyperText Markup Language (HTML and later variants) also provide strong support for processing scripts.
-
Object-oriented programming. Most modern scripting languages have support for object oriented programming, although levels of support and ease of use vary. Ruby and Python have excellent support for Object Oriented programming.
-
Exceptions. Modern programming languages used for serious software construction have a structured error-handling scheme based upon exceptions.
-
Threads. Some scripting languages have support for threads, where a job is split into parts that can either take turns running on one processor, or can run simultaneously on multi-processor systems.
-
Some modern scripting languages have support for functional programming features, which may include things like closures, generators, and list comprehensions.
All script languages have their strengths and weaknesses. Some provide excellent support for text manipulation. Some provide strong support for complex mathematics which was traditionally the domain of very low-level compiled languages. Others integrate well with code written in other languages and provide the glue for integrating different applications into complex systems. Some provide strong support for network protocols and are especially useful for developing client-server applications and some are especially suited for Web development and can be embedded into HTML.
In general, you might use interpreted scripts for applications that:
-
are small, ‘one-off’ programs to do something specific (eg a personal login script);
-
automate tasks in an operating system or network such as installation, scheduling or information gathering;
-
glue together other programs such as operating system commands or other scripts;
-
are prototypes—where the application is subject to many changes, and rapid development is desired;
-
require sophisticated text processing or manipulate text files such as web pages and log files.
Applications that generate HTML code files, communicate with web servers, process log files such as proxy logs and event logs are suited to the scripting world.
Use compiled programs for applications where
-
maximum speed is required;
-
program correctness and predictable behaviour is paramount (eg an aircraft control system, or core operating system code would not be scripted).
Applications such as Operating Systems, Database systems, Word Processors, device drivers, modelling and complex graphic manipulation applications are typically complied.
Choosing a scripting language
Some factors to consider when choosing a particular scripting language from are:
-
Operating System and hardware dependence. Is there an interpreter for the script language that will run on your hardware and your operating system?
-
Ease of learning, use and available support. Consider the time it takes to learn the language and develop simple scripts with the language. Is the syntax and functions available in a language similar to what you already know? Are there documentation and tutorials available? Are there books, web sites, discussion forums, news groups and other support readily available if you choose this language?
-
Functionality and support for high-level data structures. Does the language support data structures such as lists and dictionaries (hashes)?
-
Pre-built code and libraries. How extensive are the available libraries for the language? Are there libraries for Graphical User Interface (GUI) support, mathematics, networking, text processing, XML parsing. How good is the support of your operating system?
-
Licensing. What does it cost? Are there restrictions on the use or distribution of scripts developed?
-
Portability. Will the scripts developed on my computer work on other computers without modification? Is this language strongly targeted to a particular system (such as the Windows Scripting Language) or is it largely system independent?
-
Acceptance. Who uses this language? Is it only available on certain systems? How widely is it used? Do I get many hits if I do a web search for the language?
-
System resource requirements. What minimal hardware and operating system is required?
PERL
Perl is a general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administration, web development, network programming, GUI development, and more.
The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). Its major features are that it’s easy to use, supports both procedural and object-oriented (OO) programming, has powerful built-in support for text processing, and has one of the world’s most impressive collections of third-party modules.’
Python
Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.
PHP
PHP is a general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.
Windows Script
Windows Script is a comprehensive scripting infrastructure for the Microsoft Windows platform. Windows Script provides two script engines, Visual Basic Scripting Edition and Microsoft JScript, which can be embedded into Windows Applications. It also provides an extensive array of supporting technologies that makes it easier for script users to script Windows applications.
Each scripting language has different features and the developers have their own view on how their product rates. A good web site for resources and information on some of the more popular scripting languages is Softpanorama: www.softpanorama.org/Scripting.
It contains link pages for PERL, Python, TLC and other languages. It also contains useful links to resources on the internet for the languages presented on this site.
Installing a scripting language is a very simple operation. You simply download an installation package and follow the directions. Usually a distribution is packaged as either a simple compressed file (zip or tar), or an installation file specific to the operating system (eg Microsoft Windows installer file, msi). Occasionally you may have to manually modify an environment variable such as PATH to point to the interpreter, but in general that should not be required.
The examples shown in this reading are shown using code constructed for the Python language. To execute the examples you will need to download and install Python on your computer.
The most recent version of Python is available from www.python.org, but we recommend the ActiveState distribution, because it comes packaged with additional help files, and the Windows Scripting extensions. Go to ActiveState: www.activestate.com and follow the link to the ‘ActivePython’.
Using an IDE
The standard distribution of Python comes with a simple Integrated Development Environment (IDE) called IDLE. Similarly, the ActiveState distribution comes with an IDE called PythonWin. We recommend that you use one of these GUIs, but first go through the more basic process of editing a source file, and invoking the Python interpreter from the command line as discussed above.
Integrated Development Environments make programming easier, and may have the following features:
-
Syntax highlighting, where the text of your code is coloured to make the syntax obvious. For example, keywords will be in one colour, strings in another and so on.
-
Code completion, where the editor will try to guess what you are typing, and present a list of possibilities. The editor may also look at the interface to library functions, and present information as you type, showing the types and meaning of the parameters.
-
Automatic indentation, where the editor detects when a new block of code has begun, and automatically indents the next line.
-
The usual editor functions such as find and replace, indent/dedent, an so on.
-
Code folding, which can collapse a whole function or code block to a single line, making it much easier to navigate through long programs.
-
The interpreter can be run directly from the interface, without launching a new shell.
-
An interactive window shows what your script has printed.
-
The interactive window also allows direct line-by-line interface to the interpreter, so that you can try small experiments while coding your script.
Summary
Instructions for computers to execute can be developed using compiled or interpreted languages. Scripts tend to be interpreted.
Script languages differ in the language feature and data structures available.
Criteria used in selecting scripting languages include platform and system dependence, ease of use, available support, availability of libraries and packages, portability, system resources and industry acceptance.
The Software Development Life Cycle (SDLC) is a process used in the development of computer programs and systems.
Script can be executed by invoking the interpreter and supplying the script name from a command line window or shell. However scripts are normally developed through an IDE, which has features to make programming easier.
1698_reading.doc
© State of new South Wales, Department of Education and Training 2006
Share with your friends: |